Chris@0: container->get('update.root') . '/' . DrupalKernel::findSitePath($request); Chris@0: $this->container->set('update.root', $update_root); Chris@0: \Drupal::setContainer($this->container); Chris@0: Chris@0: // Create the directories within the root path within which the Update Chris@0: // Manager will install projects. Chris@0: foreach (drupal_get_updaters() as $updater_info) { Chris@0: $updater = $updater_info['class']; Chris@0: $install_directory = $update_root . '/' . $updater::getRootDirectoryRelativePath(); Chris@0: if (!is_dir($install_directory)) { Chris@0: mkdir($install_directory); Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Refreshes the update status based on the desired available update scenario. Chris@0: * Chris@0: * @param $xml_map Chris@0: * Array that maps project names to availability scenarios to fetch. The key Chris@0: * '#all' is used if a project-specific mapping is not defined. Chris@0: * @param $url Chris@0: * (optional) A string containing the URL to fetch update data from. Chris@0: * Defaults to 'update-test'. Chris@0: * Chris@0: * @see \Drupal\update_test\Controller\UpdateTestController::updateTest() Chris@0: */ Chris@0: protected function refreshUpdateStatus($xml_map, $url = 'update-test') { Chris@0: // Tell the Update Manager module to fetch from the URL provided by Chris@0: // update_test module. Chris@0: $this->config('update.settings')->set('fetch.url', Url::fromUri('base:' . $url, ['absolute' => TRUE])->toString())->save(); Chris@0: // Save the map for UpdateTestController::updateTest() to use. Chris@0: $this->config('update_test.settings')->set('xml_map', $xml_map)->save(); Chris@0: // Manually check the update status. Chris@0: $this->drupalGet('admin/reports/updates'); Chris@0: $this->clickLink(t('Check manually')); Chris@0: $this->checkForMetaRefresh(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Runs a series of assertions that are applicable to all update statuses. Chris@0: */ Chris@0: protected function standardTests() { Chris@0: $this->assertRaw('

' . t('Drupal core') . '

'); Chris@0: $this->assertRaw(\Drupal::l(t('Drupal'), Url::fromUri('http://example.com/project/drupal')), 'Link to the Drupal project appears.'); Chris@0: $this->assertNoText(t('No available releases found')); Chris@0: } Chris@0: Chris@17: /** Chris@17: * Asserts the expected security updates are displayed correctly on the page. Chris@17: * Chris@17: * @param string $project_path_part Chris@17: * The project path part needed for the download and release links. 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 $update_element_css_locator Chris@17: * The CSS locator for the page element that contains the security updates. Chris@17: */ Chris@17: protected function assertSecurityUpdates($project_path_part, array $expected_security_releases, $expected_update_message_type, $update_element_css_locator) { Chris@17: $assert_session = $this->assertSession(); Chris@17: $page = $this->getSession()->getPage(); Chris@17: $this->standardTests(); Chris@17: $assert_session->elementTextNotContains('css', $update_element_css_locator, 'Not supported'); Chris@17: $all_security_release_urls = array_map(function ($link) { Chris@17: return $link->getAttribute('href'); Chris@17: }, $page->findAll('css', "$update_element_css_locator .version-security a[href$='-release']")); Chris@17: $all_security_download_urls = array_map(function ($link) { Chris@17: return $link->getAttribute('href'); Chris@17: }, $page->findAll('css', "$update_element_css_locator .version-security a[href$='.tar.gz']")); Chris@17: if ($expected_security_releases) { Chris@17: $expected_download_urls = []; Chris@17: $expected_release_urls = []; Chris@17: if ($expected_update_message_type === static::SECURITY_UPDATE_REQUIRED) { Chris@17: $assert_session->elementTextNotContains('css', $update_element_css_locator, 'Update available'); Chris@17: $assert_session->elementTextContains('css', $update_element_css_locator, 'Security update required!'); Chris@17: $assert_session->responseContains('error.svg', 'Error icon was found.'); Chris@17: } Chris@17: else { Chris@17: $assert_session->elementTextContains('css', $update_element_css_locator, 'Update available'); Chris@17: $assert_session->elementTextNotContains('css', $update_element_css_locator, 'Security update required!'); Chris@17: } Chris@17: $assert_session->elementTextNotContains('css', $update_element_css_locator, 'Up to date'); Chris@17: foreach ($expected_security_releases as $expected_security_release) { Chris@17: $expected_url_version = str_replace('.', '-', $expected_security_release); Chris@17: $release_url = "http://example.com/$project_path_part-$expected_url_version-release"; Chris@17: $download_url = "http://example.com/$project_path_part-$expected_url_version.tar.gz"; Chris@17: $expected_release_urls[] = $release_url; Chris@17: $expected_download_urls[] = $download_url; Chris@17: // Ensure the expected links are security links. Chris@17: $this->assertTrue(in_array($release_url, $all_security_release_urls), "Release $release_url is a security release link."); Chris@17: $this->assertTrue(in_array($download_url, $all_security_download_urls), "Release $download_url is a security download link."); Chris@17: $assert_session->linkByHrefExists($release_url); Chris@17: $assert_session->linkByHrefExists($download_url); Chris@17: } Chris@17: // Ensure no other links are shown as security releases. Chris@17: $this->assertEquals([], array_diff($all_security_release_urls, $expected_release_urls)); Chris@17: $this->assertEquals([], array_diff($all_security_download_urls, $expected_download_urls)); Chris@17: } Chris@17: else { Chris@17: // Ensure there were no security links. Chris@17: $this->assertEquals([], $all_security_release_urls); Chris@17: $this->assertEquals([], $all_security_download_urls); Chris@17: $assert_session->pageTextNotContains('Security update required!'); Chris@17: if ($expected_update_message_type === static::UPDATE_AVAILABLE) { Chris@17: $assert_session->elementTextContains('css', $update_element_css_locator, 'Update available'); Chris@17: $assert_session->elementTextNotContains('css', $update_element_css_locator, 'Up to date'); Chris@17: } Chris@17: elseif ($expected_update_message_type === static::UPDATE_NONE) { Chris@17: $assert_session->elementTextNotContains('css', $update_element_css_locator, 'Update available'); Chris@17: $assert_session->elementTextContains('css', $update_element_css_locator, 'Up to date'); Chris@17: } Chris@17: else { Chris@17: $this->fail('Unexpected value for $expected_update_message_type: ' . $expected_update_message_type); Chris@17: } Chris@17: } Chris@17: } Chris@17: Chris@0: }