StatusTest.php in Drupal 9
File
core/modules/system/tests/src/Functional/System/StatusTest.php
View source
<?php
namespace Drupal\Tests\system\Functional\System;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
class StatusTest extends BrowserTestBase {
protected static $modules = [
'update_test_postupdate',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$settings['settings']['config_sync_directory'] = (object) [
'value' => '',
'required' => TRUE,
];
$this
->writeSettings($settings);
$admin_user = $this
->drupalCreateUser([
'administer site configuration',
]);
$this
->drupalLogin($admin_user);
}
public function testStatusPage() {
$this
->drupalGet('admin/reports/status');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains(phpversion());
if (function_exists('phpinfo')) {
$this
->assertSession()
->linkByHrefExists(Url::fromRoute('system.php')
->toString());
}
else {
$this
->assertSession()
->linkByHrefNotExists(Url::fromRoute('system.php')
->toString());
}
$this
->assertSession()
->pageTextNotContains('Out of date');
$this
->assertSession()
->pageTextContains("Your {$this->siteDirectory}/settings.php file must define the \$settings['config_sync_directory'] setting");
$update_registry = \Drupal::service('update.update_hook_registry');
$update_registry
->setInstalledVersion('update_test_postupdate', 8000);
$this
->drupalGet('admin/reports/status');
$this
->assertSession()
->pageTextContains('Out of date');
$update_registry
->setInstalledVersion('update_test_postupdate', 8001);
$post_update_registry = \Drupal::service('update.post_update_registry');
$post_update_registry
->filterOutInvokedUpdatesByModule('update_test_postupdate');
$this
->drupalGet('admin/reports/status');
$this
->assertSession()
->pageTextContains('Out of date');
$this
->drupalGet('admin/reports/status/php');
$this
->assertSession()
->statusCodeEquals(200);
$cron_last_run = \Drupal::state()
->get('system.cron_last');
\Drupal::state()
->set('system.cron_last', 0);
$this
->drupalGet('admin/reports/status');
$this
->assertSession()
->elementExists('xpath', '//details[contains(@class, "system-status-report__entry")]//div[contains(text(), "Cron has not run recently")]');
\Drupal::state()
->set('system.cron_last', $cron_last_run);
}
}