3 namespace Drupal\update\Tests;
5 use Drupal\Core\DrupalKernel;
7 use Drupal\simpletest\WebTestBase;
10 * Defines some shared functions used by all update tests.
12 * The overarching methodology of these tests is we need to compare a given
13 * state of installed modules and themes (e.g., version, project grouping,
14 * timestamps, etc) against a current state of what the release history XML
15 * files we fetch say is available. We have dummy XML files (in the
16 * core/modules/update/tests directory) that describe various scenarios of
17 * what's available for different test projects, and we have dummy .info file
18 * data (specified via hook_system_info_alter() in the update_test helper
19 * module) describing what's currently installed. Each test case defines a set
20 * of projects to install, their current state (via the
21 * 'update_test_system_info' variable) and the desired available update data
22 * (via the 'update_test_xml_map' variable), and then performs a series of
23 * assertions that the report matches our expectations given the specific
24 * initial state and availability scenario.
26 abstract class UpdateTestBase extends WebTestBase {
28 protected function setUp() {
31 // Change the root path which Update Manager uses to install and update
32 // projects to be inside the testing site directory. See
33 // \Drupal\update\UpdateRootFactory::get() for equivalent changes to the
35 $request = \Drupal::request();
36 $update_root = $this->container->get('update.root') . '/' . DrupalKernel::findSitePath($request);
37 $this->container->set('update.root', $update_root);
38 \Drupal::setContainer($this->container);
40 // Create the directories within the root path within which the Update
41 // Manager will install projects.
42 foreach (drupal_get_updaters() as $updater_info) {
43 $updater = $updater_info['class'];
44 $install_directory = $update_root . '/' . $updater::getRootDirectoryRelativePath();
45 if (!is_dir($install_directory)) {
46 mkdir($install_directory);
52 * Refreshes the update status based on the desired available update scenario.
55 * Array that maps project names to availability scenarios to fetch. The key
56 * '#all' is used if a project-specific mapping is not defined.
58 * (optional) A string containing the URL to fetch update data from.
59 * Defaults to 'update-test'.
61 * @see Drupal\update_test\Controller\UpdateTestController::updateTest()
63 protected function refreshUpdateStatus($xml_map, $url = 'update-test') {
64 // Tell the Update Manager module to fetch from the URL provided by
65 // update_test module.
66 $this->config('update.settings')->set('fetch.url', Url::fromUri('base:' . $url, ['absolute' => TRUE])->toString())->save();
67 // Save the map for UpdateTestController::updateTest() to use.
68 $this->config('update_test.settings')->set('xml_map', $xml_map)->save();
69 // Manually check the update status.
70 $this->drupalGet('admin/reports/updates');
71 $this->clickLink(t('Check manually'));
75 * Runs a series of assertions that are applicable to all update statuses.
77 protected function standardTests() {
78 $this->assertRaw('<h3>' . t('Drupal core') . '</h3>');
79 $this->assertRaw(\Drupal::l(t('Drupal'), Url::fromUri('http://example.com/project/drupal')), 'Link to the Drupal project appears.');
80 $this->assertNoText(t('No available releases found'));