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',
'update',
];
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',
'access site reports',
]);
$this
->drupalLogin($admin_user);
}
public function testStatusPage() {
$this
->drupalGet('admin/reports');
$this
->assertEquals('Status report', $this
->cssSelect('.list-group :first-child')[0]
->getText());
$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
->filterOutInvokedUpdatesByExtension('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);
$this
->assertSession()
->pageTextContains('Database support for JSON');
$elements = $this
->xpath('//details[@class="system-status-report__entry"]//div[contains(text(), :text)]', [
':text' => 'Is required in Drupal 10.0.',
]);
$this
->assertCount(1, $elements);
$this
->assertStringStartsWith('Available', $elements[0]
->getParent()
->getText());
$module_installer = \Drupal::service('module_installer');
$session = $this
->assertSession();
$module_installer
->install([
'deprecated_module',
]);
$this
->drupalGet('admin/reports/status');
$session
->pageTextContains('Deprecated modules enabled');
$session
->pageTextContains('Deprecated modules found: Deprecated module.');
$this
->assertSession()
->elementExists('xpath', "//a[contains(@href, 'http://example.com/deprecated')]");
$module_installer
->uninstall([
'deprecated_module',
]);
$this
->drupalGet('admin/reports/status');
$session
->pageTextNotContains('Deprecated modules enabled');
$session
->pageTextNotContains('Deprecated modules found: Deprecated module.');
$this
->assertSession()
->elementNotExists('xpath', "//a[contains(@href, 'http://example.com/deprecated')]");
$session
->pageTextNotContains('Obsolete extensions enabled');
$session
->pageTextNotContains('Obsolete extensions found: System obsolete status test.');
$this
->config('core.extension')
->set('module.system_status_obsolete_test', 0)
->save();
$this
->rebuildAll();
$this
->drupalGet('admin/reports/status');
$session
->pageTextContains('Obsolete extensions enabled');
$session
->pageTextContains('Obsolete extensions found: System obsolete status test.');
$module_installer
->uninstall([
'system_status_obsolete_test',
]);
$this
->drupalGet('admin/reports/status');
$session
->pageTextNotContains('Obsolete extensions enabled');
$session
->pageTextNotContains('Obsolete extensions found: System obsolete status test.');
$theme_installer = \Drupal::service('theme_installer');
$theme_installer
->install([
'test_deprecated_theme',
]);
$this
->drupalGet('admin/reports/status');
$session
->pageTextContains('Deprecated themes enabled');
$session
->pageTextContains('Deprecated themes found: Test deprecated theme.');
$this
->assertSession()
->elementExists('xpath', "//a[contains(@href, 'http://example.com/deprecated_theme')]");
$theme_installer
->uninstall([
'test_deprecated_theme',
]);
$this
->drupalGet('admin/reports/status');
$session
->pageTextNotContains('Deprecated themes enabled');
$session
->pageTextNotContains('Deprecated themes found: Test deprecated theme.');
$this
->assertSession()
->elementNotExists('xpath', "//a[contains(@href, 'http://example.com/deprecated_theme')]");
if ($this
->getDatabaseConnection()
->databaseType() == 'pgsql') {
$this
->assertSession()
->pageTextContains('PostgreSQL pg_trgm extension');
$elements = $this
->xpath('//details[@class="system-status-report__entry"]//div[contains(text(), :text)]', [
':text' => 'The pg_trgm PostgreSQL extension is present.',
]);
$this
->assertCount(1, $elements);
$this
->assertStringStartsWith('Available', $elements[0]
->getParent()
->getText());
}
}
}