Skip to content

Commit

Permalink
Add test coverage to prove that the installer actually applies the St…
Browse files Browse the repository at this point in the history
…arshot recipe (#163)
  • Loading branch information
phenaproxima authored and Neslee committed Aug 6, 2024
1 parent 36e5b94 commit a6ab778
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions tests/src/ExistingSite/BasicExpectationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

namespace Drupal\Tests\dxpr_cms\ExistingSite;

use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Extension\ExtensionList;
use Drupal\Core\Extension\ModuleExtensionList;
use Drupal\Core\Extension\ThemeExtensionList;
use weitzman\DrupalTestTraits\ExistingSiteBase;

/**
Expand All @@ -22,9 +24,31 @@ public function testBasicExpectations(): void {
$assert_session->statusCodeEquals(200);
$assert_session->elementAttributeContains('css', 'meta[name="Generator"]', 'content', 'Drupal');

/** @var \Drupal\Core\Config\ConfigFactoryInterface $config_factory */
$config_factory = $this->container->get(ConfigFactoryInterface::class);
$this->assertEmpty($config_factory->get('core.extension')->get('profile'));
// The installer should have uninstalled itself.
$this->assertFalse($this->container->getParameter('install_profile'));

// Ensure that there are non-core extensions installed, which proves that
// recipes were applied during site installation.
$this->assertContribInstalled($this->container->get(ModuleExtensionList::class));
$this->assertContribInstalled($this->container->get(ThemeExtensionList::class));
}

/**
* Asserts that any number of contributed extensions are installed.
*
* @param \Drupal\Core\Extension\ExtensionList $list
* An extension list.
*/
private function assertContribInstalled(ExtensionList $list): void {
$core_dir = $this->container->getParameter('app.root') . '/core';

foreach (array_keys($list->getAllInstalledInfo()) as $name) {
// If the extension isn't part of core, great! We're done.
if (!str_starts_with($list->getPath($name), $core_dir)) {
return;
}
}
$this->fail('No contributed extensions are installed.');
}

}

0 comments on commit a6ab778

Please sign in to comment.