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