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