RebuildScriptTest.php in Drupal 9
File
core/modules/system/tests/src/Functional/UpdateSystem/RebuildScriptTest.php
View source
<?php
namespace Drupal\Tests\system\Functional\UpdateSystem;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
use Symfony\Component\Filesystem\Filesystem;
class RebuildScriptTest extends BrowserTestBase {
protected static $modules = [
'module_test',
'container_rebuild_test',
];
protected $defaultTheme = 'stark';
public function testRebuild() {
$cache = $this->container
->get('cache.default');
$cache
->set('rebuild_test', TRUE);
$this
->drupalGet(Url::fromUri('base:core/rebuild.php'));
$this
->assertSession()
->addressEquals(new Url('<front>'));
$this
->assertInstanceOf(\stdClass::class, $cache
->get('rebuild_test'));
$settings['settings']['rebuild_access'] = (object) [
'value' => TRUE,
'required' => TRUE,
];
$this
->writeSettings($settings);
$this
->rebuildAll();
$cache
->set('rebuild_test', TRUE);
\Drupal::state()
->set('container_rebuild_test.count', 0);
$this
->drupalGet(Url::fromUri('base:core/rebuild.php'));
$this
->assertSession()
->addressEquals(new Url('<front>'));
$this
->assertFalse($cache
->get('rebuild_test'));
$this
->refreshVariables();
$this
->assertSame(1, \Drupal::state()
->get('container_rebuild_test.count', 0));
$this
->drupalGet('/container_rebuild_test/module_test/module_test_system_info_alter');
$this
->assertSession()
->pageTextContains('module_test: core/modules/system/tests/modules/module_test');
$this
->assertSession()
->pageTextContains('module_test_system_info_alter: true');
$file_system = new Filesystem();
$file_system
->mirror('core/modules/system/tests/modules/module_test', $this->siteDirectory . '/modules/module_test');
\Drupal::state()
->set('container_rebuild_test.count', 0);
$this
->drupalGet(Url::fromUri('base:core/rebuild.php'));
$this
->assertSession()
->addressEquals(new Url('<front>'));
$this
->refreshVariables();
$this
->assertSame(1, \Drupal::state()
->get('container_rebuild_test.count', 0));
$this
->drupalGet('/container_rebuild_test/module_test/module_test_system_info_alter');
$this
->assertSession()
->pageTextContains('module_test: ' . $this->siteDirectory . '/modules/module_test');
$this
->assertSession()
->pageTextContains('module_test_system_info_alter: true');
$this
->config('core.extension')
->clear('module.module_test')
->save();
\Drupal::state()
->set('container_rebuild_test.count', 0);
$this
->drupalGet(Url::fromUri('base:core/rebuild.php'));
$this
->assertSession()
->addressEquals(new Url('<front>'));
$this
->refreshVariables();
$this
->assertSame(1, \Drupal::state()
->get('container_rebuild_test.count', 0));
$this
->drupalGet('/container_rebuild_test/module_test/module_test_system_info_alter');
$this
->assertSession()
->pageTextContains('module_test: not installed');
$this
->assertSession()
->pageTextContains('module_test_system_info_alter: false');
$modules = $this
->config('core.extension')
->get('module');
$modules['module_test'] = 0;
$this
->config('core.extension')
->set('module', module_config_sort($modules))
->save();
\Drupal::state()
->set('container_rebuild_test.count', 0);
$this
->drupalGet(Url::fromUri('base:core/rebuild.php'));
$this
->assertSession()
->addressEquals(new Url('<front>'));
$this
->refreshVariables();
$this
->assertSame(1, \Drupal::state()
->get('container_rebuild_test.count', 0));
$this
->drupalGet('/container_rebuild_test/module_test/module_test_system_info_alter');
$this
->assertSession()
->pageTextContains('module_test: ' . $this->siteDirectory . '/modules/module_test');
$this
->assertSession()
->pageTextContains('module_test_system_info_alter: true');
\Drupal::state()
->set('container_rebuild_test.count', 0);
\Drupal::service('kernel')
->invalidateContainer();
$this
->drupalGet(Url::fromUri('base:core/rebuild.php'));
$this
->assertSession()
->addressEquals(new Url('<front>'));
$this
->assertFalse($cache
->get('rebuild_test'));
$this
->refreshVariables();
$this
->assertSame(1, \Drupal::state()
->get('container_rebuild_test.count', 0));
}
}