Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / system / tests / src / Functional / System / StatusTest.php
1 <?php
2
3 namespace Drupal\Tests\system\Functional\System;
4
5 use Drupal\Core\Url;
6 use Drupal\Tests\BrowserTestBase;
7 use Drupal\system\SystemRequirements;
8 use Symfony\Component\CssSelector\CssSelectorConverter;
9
10 /**
11  * Tests output on the status overview page.
12  *
13  * @group system
14  */
15 class StatusTest extends BrowserTestBase {
16
17   /**
18    * {@inheritdoc}
19    */
20   public static $modules = ['update_test_postupdate'];
21
22   /**
23    * {@inheritdoc}
24    */
25   protected function setUp() {
26     parent::setUp();
27
28     // Unset the sync directory in settings.php to trigger $config_directories
29     // error.
30     $settings['config_directories']  = [
31       CONFIG_SYNC_DIRECTORY => (object) [
32         'value' => '',
33         'required' => TRUE,
34       ],
35     ];
36     $this->writeSettings($settings);
37
38     $admin_user = $this->drupalCreateUser([
39       'administer site configuration',
40     ]);
41     $this->drupalLogin($admin_user);
42   }
43
44   /**
45    * Tests that the status page returns.
46    */
47   public function testStatusPage() {
48     // Go to Administration.
49     $this->drupalGet('admin/reports/status');
50     $this->assertResponse(200, 'The status page is reachable.');
51
52     $phpversion = phpversion();
53     $this->assertText($phpversion, 'Php version is shown on the page.');
54
55     // Checks if the suggestion to update to php 5.5.21 or 5.6.5 for disabling
56     // multiple statements is present when necessary.
57     if (\Drupal::database()->driver() === 'mysql' && !SystemRequirements::phpVersionWithPdoDisallowMultipleStatements($phpversion)) {
58       $this->assertText(t('PHP (multiple statement disabling)'));
59     }
60     else {
61       $this->assertNoText(t('PHP (multiple statement disabling)'));
62     }
63
64     if (function_exists('phpinfo')) {
65       $this->assertLinkByHref(Url::fromRoute('system.php')->toString());
66     }
67     else {
68       $this->assertNoLinkByHref(Url::fromRoute('system.php')->toString());
69     }
70
71     // If a module is fully installed no pending updates exists.
72     $this->assertNoText(t('Out of date'));
73
74     // The global $config_directories is not properly formed.
75     $this->assertRaw(t('Your %file file must define the $config_directories variable as an array containing the names of directories in which configuration files can be found. It must contain a %sync_key key.', ['%file' => $this->siteDirectory . '/settings.php', '%sync_key' => CONFIG_SYNC_DIRECTORY]));
76
77     // Set the schema version of update_test_postupdate to a lower version, so
78     // update_test_postupdate_update_8001() needs to be executed.
79     drupal_set_installed_schema_version('update_test_postupdate', 8000);
80     $this->drupalGet('admin/reports/status');
81     $this->assertText(t('Out of date'));
82
83     // Now cleanup the executed post update functions.
84     drupal_set_installed_schema_version('update_test_postupdate', 8001);
85     /** @var \Drupal\Core\Update\UpdateRegistry $post_update_registry */
86     $post_update_registry = \Drupal::service('update.post_update_registry');
87     $post_update_registry->filterOutInvokedUpdatesByModule('update_test_postupdate');
88     $this->drupalGet('admin/reports/status');
89     $this->assertText(t('Out of date'));
90
91     $this->drupalGet('admin/reports/status/php');
92     $this->assertResponse(200, 'The phpinfo page is reachable.');
93
94     // Check if cron error is displayed in errors section
95     $cron_last_run = \Drupal::state()->get('system.cron_last');
96     \Drupal::state()->set('system.cron_last', 0);
97     $this->drupalGet('admin/reports/status');
98     $css_selector_converter = new CssSelectorConverter();
99     $xpath = $css_selector_converter->toXPath('details.system-status-report__entry') . '//div[contains(text(), "Cron has not run recently")]';
100     $this->assertNotEmpty($this->xpath($xpath), 'Cron has not run recently error is being displayed.');
101     \Drupal::state()->set('system.cron_last', $cron_last_run);
102   }
103
104 }