CCC Update test';
Chris@17: $this->assertTrue(strpos($this->getSession()->getPage()->getContent(), $bbb_project_link) < strpos($this->getSession()->getPage()->getContent(), $ccc_project_link), "'BBB Update test' project is listed before the 'CCC Update test' project");
Chris@0: }
Chris@0:
Chris@0: /**
Chris@0: * Tests that subthemes are notified about security updates for base themes.
Chris@0: */
Chris@0: public function testUpdateBaseThemeSecurityUpdate() {
Chris@0: // @todo https://www.drupal.org/node/2338175 base themes have to be
Chris@0: // installed.
Chris@0: // Only install the subtheme, not the base theme.
Chris@0: \Drupal::service('theme_handler')->install(['update_test_subtheme']);
Chris@0:
Chris@0: // Define the initial state for core and the subtheme.
Chris@0: $system_info = [
Chris@0: // We want core to be version 8.0.0.
Chris@0: '#all' => [
Chris@0: 'version' => '8.0.0',
Chris@0: ],
Chris@0: // Show the update_test_basetheme
Chris@0: 'update_test_basetheme' => [
Chris@0: 'project' => 'update_test_basetheme',
Chris@0: 'version' => '8.x-1.0',
Chris@0: 'hidden' => FALSE,
Chris@0: ],
Chris@0: // Show the update_test_subtheme
Chris@0: 'update_test_subtheme' => [
Chris@0: 'project' => 'update_test_subtheme',
Chris@0: 'version' => '8.x-1.0',
Chris@0: 'hidden' => FALSE,
Chris@0: ],
Chris@0: ];
Chris@0: $this->config('update_test.settings')->set('system_info', $system_info)->save();
Chris@0: $xml_mapping = [
Chris@0: 'drupal' => '0.0',
Chris@0: 'update_test_subtheme' => '1_0',
Chris@0: 'update_test_basetheme' => '1_1-sec',
Chris@0: ];
Chris@0: $this->refreshUpdateStatus($xml_mapping);
Chris@0: $this->assertText(t('Security update required!'));
Chris@0: $this->assertRaw(\Drupal::l(t('Update test base theme'), Url::fromUri('http://example.com/project/update_test_basetheme')), 'Link to the Update test base theme project appears.');
Chris@0: }
Chris@0:
Chris@0: /**
Chris@0: * Tests that disabled themes are only shown when desired.
Chris@0: *
Chris@0: * @todo https://www.drupal.org/node/2338175 extensions can not be hidden and
Chris@0: * base themes have to be installed.
Chris@0: */
Chris@0: public function testUpdateShowDisabledThemes() {
Chris@0: $update_settings = $this->config('update.settings');
Chris@0: // Make sure all the update_test_* themes are disabled.
Chris@0: $extension_config = $this->config('core.extension');
Chris@0: foreach ($extension_config->get('theme') as $theme => $weight) {
Chris@0: if (preg_match('/^update_test_/', $theme)) {
Chris@0: $extension_config->clear("theme.$theme");
Chris@0: }
Chris@0: }
Chris@0: $extension_config->save();
Chris@0:
Chris@0: // Define the initial state for core and the test contrib themes.
Chris@0: $system_info = [
Chris@0: // We want core to be version 8.0.0.
Chris@0: '#all' => [
Chris@0: 'version' => '8.0.0',
Chris@0: ],
Chris@0: // The update_test_basetheme should be visible and up to date.
Chris@0: 'update_test_basetheme' => [
Chris@0: 'project' => 'update_test_basetheme',
Chris@0: 'version' => '8.x-1.1',
Chris@0: 'hidden' => FALSE,
Chris@0: ],
Chris@0: // The update_test_subtheme should be visible and up to date.
Chris@0: 'update_test_subtheme' => [
Chris@0: 'project' => 'update_test_subtheme',
Chris@0: 'version' => '8.x-1.0',
Chris@0: 'hidden' => FALSE,
Chris@0: ],
Chris@0: ];
Chris@0: // When there are contributed modules in the site's file system, the
Chris@0: // total number of attempts made in the test may exceed the default value
Chris@0: // of update_max_fetch_attempts. Therefore this variable is set very high
Chris@0: // to avoid test failures in those cases.
Chris@0: $update_settings->set('fetch.max_attempts', 99999)->save();
Chris@0: $this->config('update_test.settings')->set('system_info', $system_info)->save();
Chris@0: $xml_mapping = [
Chris@0: 'drupal' => '0.0',
Chris@0: 'update_test_subtheme' => '1_0',
Chris@0: 'update_test_basetheme' => '1_1-sec',
Chris@0: ];
Chris@0: $base_theme_project_link = \Drupal::l(t('Update test base theme'), Url::fromUri('http://example.com/project/update_test_basetheme'));
Chris@0: $sub_theme_project_link = \Drupal::l(t('Update test subtheme'), Url::fromUri('http://example.com/project/update_test_subtheme'));
Chris@0: foreach ([TRUE, FALSE] as $check_disabled) {
Chris@0: $update_settings->set('check.disabled_extensions', $check_disabled)->save();
Chris@0: $this->refreshUpdateStatus($xml_mapping);
Chris@0: // In neither case should we see the "Themes" heading for installed
Chris@0: // themes.
Chris@0: $this->assertNoText(t('Themes'));
Chris@0: if ($check_disabled) {
Chris@0: $this->assertText(t('Uninstalled themes'));
Chris@0: $this->assertRaw($base_theme_project_link, 'Link to the Update test base theme project appears.');
Chris@0: $this->assertRaw($sub_theme_project_link, 'Link to the Update test subtheme project appears.');
Chris@0: }
Chris@0: else {
Chris@0: $this->assertNoText(t('Uninstalled themes'));
Chris@0: $this->assertNoRaw($base_theme_project_link, 'Link to the Update test base theme project does not appear.');
Chris@0: $this->assertNoRaw($sub_theme_project_link, 'Link to the Update test subtheme project does not appear.');
Chris@0: }
Chris@0: }
Chris@0: }
Chris@0:
Chris@0: /**
Chris@0: * Tests updates with a hidden base theme.
Chris@0: */
Chris@0: public function testUpdateHiddenBaseTheme() {
Chris@0: module_load_include('compare.inc', 'update');
Chris@0:
Chris@0: // Install the subtheme.
Chris@0: \Drupal::service('theme_handler')->install(['update_test_subtheme']);
Chris@0:
Chris@0: // Add a project and initial state for base theme and subtheme.
Chris@0: $system_info = [
Chris@0: // Hide the update_test_basetheme.
Chris@0: 'update_test_basetheme' => [
Chris@0: 'project' => 'update_test_basetheme',
Chris@0: 'hidden' => TRUE,
Chris@0: ],
Chris@0: // Show the update_test_subtheme.
Chris@0: 'update_test_subtheme' => [
Chris@0: 'project' => 'update_test_subtheme',
Chris@0: 'hidden' => FALSE,
Chris@0: ],
Chris@0: ];
Chris@0: $this->config('update_test.settings')->set('system_info', $system_info)->save();
Chris@0: $projects = \Drupal::service('update.manager')->getProjects();
Chris@0: $theme_data = \Drupal::service('theme_handler')->rebuildThemeData();
Chris@0: $project_info = new ProjectInfo();
Chris@0: $project_info->processInfoList($projects, $theme_data, 'theme', TRUE);
Chris@0:
Chris@0: $this->assertTrue(!empty($projects['update_test_basetheme']), 'Valid base theme (update_test_basetheme) was found.');
Chris@0: }
Chris@0:
Chris@0: /**
Chris@0: * Makes sure that if we fetch from a broken URL, sane things happen.
Chris@0: */
Chris@0: public function testUpdateBrokenFetchURL() {
Chris@0: $system_info = [
Chris@0: '#all' => [
Chris@0: 'version' => '8.0.0',
Chris@0: ],
Chris@0: 'aaa_update_test' => [
Chris@0: 'project' => 'aaa_update_test',
Chris@0: 'version' => '8.x-1.0',
Chris@0: 'hidden' => FALSE,
Chris@0: ],
Chris@0: 'bbb_update_test' => [
Chris@0: 'project' => 'bbb_update_test',
Chris@0: 'version' => '8.x-1.0',
Chris@0: 'hidden' => FALSE,
Chris@0: ],
Chris@0: 'ccc_update_test' => [
Chris@0: 'project' => 'ccc_update_test',
Chris@0: 'version' => '8.x-1.0',
Chris@0: 'hidden' => FALSE,
Chris@0: ],
Chris@0: ];
Chris@0: $this->config('update_test.settings')->set('system_info', $system_info)->save();
Chris@0:
Chris@0: // Ensure that the update information is correct before testing.
Chris@0: $this->drupalGet('admin/reports/updates');
Chris@0:
Chris@0: $xml_mapping = [
Chris@0: 'drupal' => '0.0',
Chris@0: 'aaa_update_test' => '1_0',
Chris@0: 'bbb_update_test' => 'does-not-exist',
Chris@0: 'ccc_update_test' => '1_0',
Chris@0: ];
Chris@0: $this->refreshUpdateStatus($xml_mapping);
Chris@0:
Chris@0: $this->assertText(t('Up to date'));
Chris@0: // We're expecting the report to say most projects are up to date, so we
Chris@0: // hope that 'Up to date' is not unique.
Chris@0: $this->assertNoUniqueText(t('Up to date'));
Chris@0: // It should say we failed to get data, not that we're missing an update.
Chris@0: $this->assertNoText(t('Update available'));
Chris@0:
Chris@0: // We need to check that this string is found as part of a project row, not
Chris@0: // just in the "Failed to get available update data" message at the top of
Chris@0: // the page.
Chris@0: $this->assertRaw('
' . t('Failed to get available update data'));
Chris@0:
Chris@0: // We should see the output messages from fetching manually.
Chris@0: $this->assertUniqueText(t('Checked available update data for 3 projects.'));
Chris@0: $this->assertUniqueText(t('Failed to get available update data for one project.'));
Chris@0:
Chris@0: // The other two should be listed as projects.
Chris@0: $this->assertRaw(\Drupal::l(t('AAA Update test'), Url::fromUri('http://example.com/project/aaa_update_test')), 'Link to aaa_update_test project appears.');
Chris@0: $this->assertNoRaw(\Drupal::l(t('BBB Update test'), Url::fromUri('http://example.com/project/bbb_update_test')), 'Link to bbb_update_test project does not appear.');
Chris@0: $this->assertRaw(\Drupal::l(t('CCC Update test'), Url::fromUri('http://example.com/project/ccc_update_test')), 'Link to bbb_update_test project appears.');
Chris@0: }
Chris@0:
Chris@0: /**
Chris@0: * Checks that hook_update_status_alter() works to change a status.
Chris@0: *
Chris@0: * We provide the same external data as if aaa_update_test 8.x-1.0 were
Chris@0: * installed and that was the latest release. Then we use
Chris@0: * hook_update_status_alter() to try to mark this as missing a security
Chris@0: * update, then assert if we see the appropriate warnings on the right pages.
Chris@0: */
Chris@0: public function testHookUpdateStatusAlter() {
Chris@0: $update_test_config = $this->config('update_test.settings');
Chris@0: $update_admin_user = $this->drupalCreateUser(['administer site configuration', 'administer software updates']);
Chris@0: $this->drupalLogin($update_admin_user);
Chris@0:
Chris@0: $system_info = [
Chris@0: '#all' => [
Chris@0: 'version' => '8.0.0',
Chris@0: ],
Chris@0: 'aaa_update_test' => [
Chris@0: 'project' => 'aaa_update_test',
Chris@0: 'version' => '8.x-1.0',
Chris@0: 'hidden' => FALSE,
Chris@0: ],
Chris@0: ];
Chris@0: $update_test_config->set('system_info', $system_info)->save();
Chris@0: $update_status = [
Chris@0: 'aaa_update_test' => [
Chris@0: 'status' => UPDATE_NOT_SECURE,
Chris@0: ],
Chris@0: ];
Chris@0: $update_test_config->set('update_status', $update_status)->save();
Chris@0: $this->refreshUpdateStatus(
Chris@0: [
Chris@0: 'drupal' => '0.0',
Chris@0: 'aaa_update_test' => '1_0',
Chris@0: ]
Chris@0: );
Chris@0: $this->drupalGet('admin/reports/updates');
Chris@0: $this->assertRaw('
' . t('Modules') . '
');
Chris@0: $this->assertText(t('Security update required!'));
Chris@0: $this->assertRaw(\Drupal::l(t('AAA Update test'), Url::fromUri('http://example.com/project/aaa_update_test')), 'Link to aaa_update_test project appears.');
Chris@0:
Chris@0: // Visit the reports page again without the altering and make sure the
Chris@0: // status is back to normal.
Chris@0: $update_test_config->set('update_status', [])->save();
Chris@0: $this->drupalGet('admin/reports/updates');
Chris@0: $this->assertRaw('' . t('Modules') . '
');
Chris@0: $this->assertNoText(t('Security update required!'));
Chris@0: $this->assertRaw(\Drupal::l(t('AAA Update test'), Url::fromUri('http://example.com/project/aaa_update_test')), 'Link to aaa_update_test project appears.');
Chris@0:
Chris@0: // Turn the altering back on and visit the Update manager UI.
Chris@0: $update_test_config->set('update_status', $update_status)->save();
Chris@0: $this->drupalGet('admin/modules/update');
Chris@0: $this->assertText(t('Security update'));
Chris@0:
Chris@0: // Turn the altering back off and visit the Update manager UI.
Chris@0: $update_test_config->set('update_status', [])->save();
Chris@0: $this->drupalGet('admin/modules/update');
Chris@0: $this->assertNoText(t('Security update'));
Chris@0: }
Chris@0:
Chris@17: /**
Chris@17: * Tests update status of security releases.
Chris@17: *
Chris@17: * @param string $module_version
Chris@17: * The module version the site is using.
Chris@17: * @param string[] $expected_security_releases
Chris@17: * The security releases, if any, that the status report should recommend.
Chris@17: * @param string $expected_update_message_type
Chris@17: * The type of update message expected.
Chris@17: * @param string $fixture
Chris@17: * The fixture file to use.
Chris@17: *
Chris@17: * @dataProvider securityUpdateAvailabilityProvider
Chris@17: */
Chris@17: public function testSecurityUpdateAvailability($module_version, array $expected_security_releases, $expected_update_message_type, $fixture) {
Chris@17: $system_info = [
Chris@17: '#all' => [
Chris@17: 'version' => '8.0.0',
Chris@17: ],
Chris@17: 'aaa_update_test' => [
Chris@17: 'project' => 'aaa_update_test',
Chris@17: 'version' => $module_version,
Chris@17: 'hidden' => FALSE,
Chris@17: ],
Chris@17: ];
Chris@17: $this->config('update_test.settings')->set('system_info', $system_info)->save();
Chris@17: $this->refreshUpdateStatus(['drupal' => '0.0', 'aaa_update_test' => $fixture]);
Chris@17: $this->assertSecurityUpdates('aaa_update_test', $expected_security_releases, $expected_update_message_type, 'table.update:nth-of-type(2)');
Chris@17: }
Chris@17:
Chris@17: /**
Chris@17: * Data provider method for testSecurityUpdateAvailability().
Chris@17: *
Chris@17: * These test cases rely on the following fixtures containing the following
Chris@17: * releases:
Chris@17: * - aaa_update_test.sec.8.x-1.2.xml
Chris@17: * - 8.x-1.2 Security update
Chris@17: * - 8.x-1.1 Insecure
Chris@17: * - 8.x-1.0 Insecure
Chris@17: * - aaa_update_test.sec.8.x-1.1_8.x-1.2.xml
Chris@17: * - 8.x-1.2 Security update
Chris@17: * - 8.x-1.1 Security update, Insecure
Chris@17: * - 8.x-1.0 Insecure
Chris@17: * - aaa_update_test.sec.8.x-1.2_8.x-2.2.xml
Chris@17: * - 8.x-3.0-beta2
Chris@17: * - 8.x-3.0-beta1 Insecure
Chris@17: * - 8.x-2.2 Security update
Chris@17: * - 8.x-2.1 Security update, Insecure
Chris@17: * - 8.x-2.0 Insecure
Chris@17: * - 8.x-1.2 Security update
Chris@17: * - 8.x-1.1 Insecure
Chris@17: * - 8.x-1.0 Insecure
Chris@17: * - aaa_update_test.sec.8.x-2.2_1.x_secure.xml
Chris@17: * - 8.x-2.2 Security update
Chris@17: * - 8.x-2.1 Security update, Insecure
Chris@17: * - 8.x-2.0 Insecure
Chris@17: * - 8.x-1.2
Chris@17: * - 8.x-1.1
Chris@17: * - 8.x-1.0
Chris@17: */
Chris@17: public function securityUpdateAvailabilityProvider() {
Chris@17: return [
Chris@17: // Security releases available for module major release 1.
Chris@17: // No releases for next major.
Chris@17: '8.x-1.0, 8.x-1.2' => [
Chris@17: 'module_patch_version' => '8.x-1.0',
Chris@17: 'expected_security_releases' => ['8.x-1.2'],
Chris@17: 'expected_update_message_type' => static::SECURITY_UPDATE_REQUIRED,
Chris@17: 'fixture' => 'sec.8.x-1.2',
Chris@17: ],
Chris@17: // Two security releases available for module major release 1.
Chris@17: // 8.x-1.1 security release marked as insecure.
Chris@17: // No releases for next major.
Chris@17: '8.x-1.0, 8.x-1.1 8.x-1.2' => [
Chris@17: 'module_patch_version' => '8.x-1.0',
Chris@17: 'expected_security_releases' => ['8.x-1.2'],
Chris@17: 'expected_update_message_type' => static::SECURITY_UPDATE_REQUIRED,
Chris@17: 'fixture' => 'sec.8.x-1.1_8.x-1.2',
Chris@17: ],
Chris@17: // Security release available for module major release 2.
Chris@17: // No releases for next major.
Chris@17: '8.x-2.0, 8.x-2.2' => [
Chris@17: 'module_patch_version' => '8.x-2.0',
Chris@17: 'expected_security_releases' => ['8.x-2.2'],
Chris@17: 'expected_update_message_type' => static::SECURITY_UPDATE_REQUIRED,
Chris@17: 'fixture' => 'sec.8.x-2.2_1.x_secure',
Chris@17: ],
Chris@17: '8.x-2.2, 8.x-1.2 8.x-2.2' => [
Chris@17: 'module_patch_version' => '8.x-2.2',
Chris@17: 'expected_security_releases' => [],
Chris@17: 'expected_update_message_type' => static::UPDATE_NONE,
Chris@17: 'fixture' => 'sec.8.x-1.2_8.x-2.2',
Chris@17: ],
Chris@17: // Security release available for module major release 1.
Chris@17: // Security release also available for next major.
Chris@17: '8.x-1.0, 8.x-1.2 8.x-2.2' => [
Chris@17: 'module_patch_version' => '8.x-1.0',
Chris@17: 'expected_security_releases' => ['8.x-1.2'],
Chris@17: 'expected_update_message_type' => static::SECURITY_UPDATE_REQUIRED,
Chris@17: 'fixture' => 'sec.8.x-1.2_8.x-2.2',
Chris@17: ],
Chris@17: // No security release available for module major release 1 but 1.x
Chris@17: // releases are not marked as insecure.
Chris@17: // Security release available for next major.
Chris@17: '8.x-1.0, 8.x-2.2, not insecure' => [
Chris@17: 'module_patch_version' => '8.x-1.0',
Chris@17: 'expected_security_releases' => [],
Chris@17: 'expected_update_message_type' => static::UPDATE_AVAILABLE,
Chris@17: 'fixture' => 'sec.8.x-2.2_1.x_secure',
Chris@17: ],
Chris@17: // On latest security release for module major release 1.
Chris@17: // Security release also available for next major.
Chris@17: '8.x-1.2, 8.x-1.2 8.x-2.2' => [
Chris@17: 'module_patch_version' => '8.x-1.2',
Chris@17: 'expected_security_release' => [],
Chris@17: 'expected_update_message_type' => static::UPDATE_NONE,
Chris@17: 'fixture' => 'sec.8.x-1.2_8.x-2.2',
Chris@17: ],
Chris@17: // @todo In https://www.drupal.org/node/2865920 add test cases:
Chris@17: // - 8.x-2.0 using fixture 'sec.8.x-1.2_8.x-2.2' to ensure that 8.x-2.2
Chris@17: // is the only security update.
Chris@17: // - 8.x-3.0-beta1 using fixture 'sec.8.x-1.2_8.x-2.2' to ensure that
Chris@17: // 8.x-2.2 is the only security update.
Chris@17: ];
Chris@17: }
Chris@17:
Chris@0: }