Mercurial > hg > isophonics-drupal-site
comparison core/modules/update/tests/src/Functional/UpdateTestBase.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 4c8ae668cc8c |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
22 * (via the 'update_test_xml_map' variable), and then performs a series of | 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 | 23 * assertions that the report matches our expectations given the specific |
24 * initial state and availability scenario. | 24 * initial state and availability scenario. |
25 */ | 25 */ |
26 abstract class UpdateTestBase extends BrowserTestBase { | 26 abstract class UpdateTestBase extends BrowserTestBase { |
27 | |
28 /** | |
29 * Denotes a security update will be required in the test case. | |
30 */ | |
31 const SECURITY_UPDATE_REQUIRED = 'SECURITY_UPDATE_REQUIRED'; | |
32 | |
33 /** | |
34 * Denotes an update will be available in the test case. | |
35 */ | |
36 const UPDATE_AVAILABLE = 'UPDATE_AVAILABLE'; | |
37 | |
38 /** | |
39 * Denotes no update will be available in the test case. | |
40 */ | |
41 const UPDATE_NONE = 'UPDATE_NONE'; | |
27 | 42 |
28 protected function setUp() { | 43 protected function setUp() { |
29 parent::setUp(); | 44 parent::setUp(); |
30 | 45 |
31 // Change the root path which Update Manager uses to install and update | 46 // Change the root path which Update Manager uses to install and update |
79 $this->assertRaw('<h3>' . t('Drupal core') . '</h3>'); | 94 $this->assertRaw('<h3>' . t('Drupal core') . '</h3>'); |
80 $this->assertRaw(\Drupal::l(t('Drupal'), Url::fromUri('http://example.com/project/drupal')), 'Link to the Drupal project appears.'); | 95 $this->assertRaw(\Drupal::l(t('Drupal'), Url::fromUri('http://example.com/project/drupal')), 'Link to the Drupal project appears.'); |
81 $this->assertNoText(t('No available releases found')); | 96 $this->assertNoText(t('No available releases found')); |
82 } | 97 } |
83 | 98 |
99 /** | |
100 * Asserts the expected security updates are displayed correctly on the page. | |
101 * | |
102 * @param string $project_path_part | |
103 * The project path part needed for the download and release links. | |
104 * @param string[] $expected_security_releases | |
105 * The security releases, if any, that the status report should recommend. | |
106 * @param string $expected_update_message_type | |
107 * The type of update message expected. | |
108 * @param string $update_element_css_locator | |
109 * The CSS locator for the page element that contains the security updates. | |
110 */ | |
111 protected function assertSecurityUpdates($project_path_part, array $expected_security_releases, $expected_update_message_type, $update_element_css_locator) { | |
112 $assert_session = $this->assertSession(); | |
113 $page = $this->getSession()->getPage(); | |
114 $this->standardTests(); | |
115 $assert_session->elementTextNotContains('css', $update_element_css_locator, 'Not supported'); | |
116 $all_security_release_urls = array_map(function ($link) { | |
117 return $link->getAttribute('href'); | |
118 }, $page->findAll('css', "$update_element_css_locator .version-security a[href$='-release']")); | |
119 $all_security_download_urls = array_map(function ($link) { | |
120 return $link->getAttribute('href'); | |
121 }, $page->findAll('css', "$update_element_css_locator .version-security a[href$='.tar.gz']")); | |
122 if ($expected_security_releases) { | |
123 $expected_download_urls = []; | |
124 $expected_release_urls = []; | |
125 if ($expected_update_message_type === static::SECURITY_UPDATE_REQUIRED) { | |
126 $assert_session->elementTextNotContains('css', $update_element_css_locator, 'Update available'); | |
127 $assert_session->elementTextContains('css', $update_element_css_locator, 'Security update required!'); | |
128 $assert_session->responseContains('error.svg', 'Error icon was found.'); | |
129 } | |
130 else { | |
131 $assert_session->elementTextContains('css', $update_element_css_locator, 'Update available'); | |
132 $assert_session->elementTextNotContains('css', $update_element_css_locator, 'Security update required!'); | |
133 } | |
134 $assert_session->elementTextNotContains('css', $update_element_css_locator, 'Up to date'); | |
135 foreach ($expected_security_releases as $expected_security_release) { | |
136 $expected_url_version = str_replace('.', '-', $expected_security_release); | |
137 $release_url = "http://example.com/$project_path_part-$expected_url_version-release"; | |
138 $download_url = "http://example.com/$project_path_part-$expected_url_version.tar.gz"; | |
139 $expected_release_urls[] = $release_url; | |
140 $expected_download_urls[] = $download_url; | |
141 // Ensure the expected links are security links. | |
142 $this->assertTrue(in_array($release_url, $all_security_release_urls), "Release $release_url is a security release link."); | |
143 $this->assertTrue(in_array($download_url, $all_security_download_urls), "Release $download_url is a security download link."); | |
144 $assert_session->linkByHrefExists($release_url); | |
145 $assert_session->linkByHrefExists($download_url); | |
146 } | |
147 // Ensure no other links are shown as security releases. | |
148 $this->assertEquals([], array_diff($all_security_release_urls, $expected_release_urls)); | |
149 $this->assertEquals([], array_diff($all_security_download_urls, $expected_download_urls)); | |
150 } | |
151 else { | |
152 // Ensure there were no security links. | |
153 $this->assertEquals([], $all_security_release_urls); | |
154 $this->assertEquals([], $all_security_download_urls); | |
155 $assert_session->pageTextNotContains('Security update required!'); | |
156 if ($expected_update_message_type === static::UPDATE_AVAILABLE) { | |
157 $assert_session->elementTextContains('css', $update_element_css_locator, 'Update available'); | |
158 $assert_session->elementTextNotContains('css', $update_element_css_locator, 'Up to date'); | |
159 } | |
160 elseif ($expected_update_message_type === static::UPDATE_NONE) { | |
161 $assert_session->elementTextNotContains('css', $update_element_css_locator, 'Update available'); | |
162 $assert_session->elementTextContains('css', $update_element_css_locator, 'Up to date'); | |
163 } | |
164 else { | |
165 $this->fail('Unexpected value for $expected_update_message_type: ' . $expected_update_message_type); | |
166 } | |
167 } | |
168 } | |
169 | |
84 } | 170 } |