PageRenderTime 38ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/core/modules/update/src/Tests/UpdateCoreTest.php

https://gitlab.com/geeta7/drupal
PHP | 366 lines | 249 code | 35 blank | 82 comment | 7 complexity | 55a651454cbf1a01b9e9b0b0ac1b420c MD5 | raw file
  1. <?php
  2. /**
  3. * @file
  4. * Contains \Drupal\update\Tests\UpdateCoreTest.
  5. */
  6. namespace Drupal\update\Tests;
  7. use Drupal\Core\Url;
  8. /**
  9. * Tests the Update Manager module through a series of functional tests using
  10. * mock XML data.
  11. *
  12. * @group update
  13. */
  14. class UpdateCoreTest extends UpdateTestBase {
  15. /**
  16. * Modules to enable.
  17. *
  18. * @var array
  19. */
  20. public static $modules = ['update_test', 'update', 'language', 'block'];
  21. protected function setUp() {
  22. parent::setUp();
  23. $admin_user = $this->drupalCreateUser(array('administer site configuration', 'administer modules', 'administer themes'));
  24. $this->drupalLogin($admin_user);
  25. $this->drupalPlaceBlock('local_actions_block');
  26. }
  27. /**
  28. * Sets the version to x.x.x when no project-specific mapping is defined.
  29. *
  30. * @param string $version
  31. * The version.
  32. */
  33. protected function setSystemInfo($version) {
  34. $setting = array(
  35. '#all' => array(
  36. 'version' => $version,
  37. ),
  38. );
  39. $this->config('update_test.settings')->set('system_info', $setting)->save();
  40. }
  41. /**
  42. * Tests the Update Manager module when no updates are available.
  43. */
  44. function testNoUpdatesAvailable() {
  45. foreach (array(0, 1) as $minor_version) {
  46. foreach (array(0, 1) as $patch_version) {
  47. foreach (array('-alpha1', '-beta1', '') as $extra_version) {
  48. $this->setSystemInfo("8.$minor_version.$patch_version" . $extra_version);
  49. $this->refreshUpdateStatus(array('drupal' => "$minor_version.$patch_version" . $extra_version));
  50. $this->standardTests();
  51. $this->assertText(t('Up to date'));
  52. $this->assertNoText(t('Update available'));
  53. $this->assertNoText(t('Security update required!'));
  54. $this->assertRaw('check.svg', 'Check icon was found.');
  55. }
  56. }
  57. }
  58. }
  59. /**
  60. * Tests the Update Manager module when one normal update is available.
  61. */
  62. function testNormalUpdateAvailable() {
  63. $this->setSystemInfo('8.0.0');
  64. foreach (array(0, 1) as $minor_version) {
  65. foreach (array('-alpha1', '-beta1', '') as $extra_version) {
  66. $this->refreshUpdateStatus(array('drupal' => "$minor_version.1" . $extra_version));
  67. $this->standardTests();
  68. $this->drupalGet('admin/reports/updates/check');
  69. $this->assertNoText(t('Security update required!'));
  70. $this->assertRaw(\Drupal::l("8.$minor_version.1" . $extra_version, Url::fromUri("http://example.com/drupal-8-$minor_version-1$extra_version-release")), 'Link to release appears.');
  71. $this->assertRaw(\Drupal::l(t('Download'), Url::fromUri("http://example.com/drupal-8-$minor_version-1$extra_version.tar.gz")), 'Link to download appears.');
  72. $this->assertRaw(\Drupal::l(t('Release notes'), Url::fromUri("http://example.com/drupal-8-$minor_version-1$extra_version-release")), 'Link to release notes appears.');
  73. switch ($minor_version) {
  74. case 0:
  75. // Both stable and unstable releases are available.
  76. // A stable release is the latest.
  77. if ($extra_version == '') {
  78. $this->assertNoText(t('Up to date'));
  79. $this->assertText(t('Update available'));
  80. $this->assertText(t('Recommended version:'));
  81. $this->assertNoText(t('Latest version:'));
  82. $this->assertRaw('warning.svg', 'Warning icon was found.');
  83. }
  84. // Only unstable releases are available.
  85. // An unstable release is the latest.
  86. else {
  87. $this->assertText(t('Up to date'));
  88. $this->assertNoText(t('Update available'));
  89. $this->assertNoText(t('Recommended version:'));
  90. $this->assertText(t('Latest version:'));
  91. $this->assertRaw('check.svg', 'Check icon was found.');
  92. }
  93. break;
  94. case 1:
  95. // Both stable and unstable releases are available.
  96. // A stable release is the latest.
  97. if ($extra_version == '') {
  98. $this->assertNoText(t('Up to date'));
  99. $this->assertText(t('Update available'));
  100. $this->assertText(t('Recommended version:'));
  101. $this->assertNoText(t('Latest version:'));
  102. $this->assertRaw('warning.svg', 'Warning icon was found.');
  103. }
  104. // Both stable and unstable releases are available.
  105. // An unstable release is the latest.
  106. else {
  107. $this->assertNoText(t('Up to date'));
  108. $this->assertText(t('Update available'));
  109. $this->assertText(t('Recommended version:'));
  110. $this->assertText(t('Latest version:'));
  111. $this->assertRaw('warning.svg', 'Warning icon was found.');
  112. }
  113. break;
  114. }
  115. }
  116. }
  117. }
  118. /**
  119. * Tests the Update Manager module when a major update is available.
  120. */
  121. function testMajorUpdateAvailable() {
  122. foreach (array(0, 1) as $minor_version) {
  123. foreach (array(0, 1) as $patch_version) {
  124. foreach (array('-alpha1', '-beta1', '') as $extra_version) {
  125. $this->setSystemInfo("8.$minor_version.$patch_version" . $extra_version);
  126. $this->refreshUpdateStatus(array('drupal' => '9'));
  127. $this->standardTests();
  128. $this->drupalGet('admin/reports/updates/check');
  129. $this->assertNoText(t('Security update required!'));
  130. $this->assertRaw(\Drupal::l('9.0.0', Url::fromUri("http://example.com/drupal-9-0-0-release")), 'Link to release appears.');
  131. $this->assertRaw(\Drupal::l(t('Download'), Url::fromUri("http://example.com/drupal-9-0-0.tar.gz")), 'Link to download appears.');
  132. $this->assertRaw(\Drupal::l(t('Release notes'), Url::fromUri("http://example.com/drupal-9-0-0-release")), 'Link to release notes appears.');
  133. $this->assertNoText(t('Up to date'));
  134. $this->assertText(t('Not supported!'));
  135. $this->assertText(t('Recommended version:'));
  136. $this->assertNoText(t('Latest version:'));
  137. $this->assertRaw('error.svg', 'Error icon was found.');
  138. }
  139. }
  140. }
  141. }
  142. /**
  143. * Tests the Update Manager module when a security update is available.
  144. */
  145. function testSecurityUpdateAvailable() {
  146. foreach (array(0, 1) as $minor_version) {
  147. $this->setSystemInfo("8.$minor_version.0");
  148. $this->refreshUpdateStatus(array('drupal' => "$minor_version.2-sec"));
  149. $this->standardTests();
  150. $this->assertNoText(t('Up to date'));
  151. $this->assertNoText(t('Update available'));
  152. $this->assertText(t('Security update required!'));
  153. $this->assertRaw(\Drupal::l("8.$minor_version.2", Url::fromUri("http://example.com/drupal-8-$minor_version-2-release")), 'Link to release appears.');
  154. $this->assertRaw(\Drupal::l(t('Download'), Url::fromUri("http://example.com/drupal-8-$minor_version-2.tar.gz")), 'Link to download appears.');
  155. $this->assertRaw(\Drupal::l(t('Release notes'), Url::fromUri("http://example.com/drupal-8-$minor_version-2-release")), 'Link to release notes appears.');
  156. $this->assertRaw('error.svg', 'Error icon was found.');
  157. }
  158. }
  159. /**
  160. * Ensures proper results where there are date mismatches among modules.
  161. */
  162. function testDatestampMismatch() {
  163. $system_info = array(
  164. '#all' => array(
  165. // We need to think we're running a -dev snapshot to see dates.
  166. 'version' => '8.0.0-dev',
  167. 'datestamp' => time(),
  168. ),
  169. 'block' => array(
  170. // This is 2001-09-09 01:46:40 GMT, so test for "2001-Sep-".
  171. 'datestamp' => '1000000000',
  172. ),
  173. );
  174. $this->config('update_test.settings')->set('system_info', $system_info)->save();
  175. $this->refreshUpdateStatus(array('drupal' => 'dev'));
  176. $this->assertNoText(t('2001-Sep-'));
  177. $this->assertText(t('Up to date'));
  178. $this->assertNoText(t('Update available'));
  179. $this->assertNoText(t('Security update required!'));
  180. }
  181. /**
  182. * Checks that running cron updates the list of available updates.
  183. */
  184. function testModulePageRunCron() {
  185. $this->setSystemInfo('8.0.0');
  186. $this->config('update.settings')
  187. ->set('fetch.url', Url::fromRoute('update_test.update_test')->setAbsolute()->toString())
  188. ->save();
  189. $this->config('update_test.settings')
  190. ->set('xml_map', array('drupal' => '0.0'))
  191. ->save();
  192. $this->cronRun();
  193. $this->drupalGet('admin/modules');
  194. $this->assertNoText(t('No update information available.'));
  195. }
  196. /**
  197. * Checks the messages at admin/modules when the site is up to date.
  198. */
  199. function testModulePageUpToDate() {
  200. $this->setSystemInfo('8.0.0');
  201. // Instead of using refreshUpdateStatus(), set these manually.
  202. $this->config('update.settings')
  203. ->set('fetch.url', Url::fromRoute('update_test.update_test')->setAbsolute()->toString())
  204. ->save();
  205. $this->config('update_test.settings')
  206. ->set('xml_map', array('drupal' => '0.0'))
  207. ->save();
  208. $this->drupalGet('admin/reports/updates');
  209. $this->clickLink(t('Check manually'));
  210. $this->assertText(t('Checked available update data for one project.'));
  211. $this->drupalGet('admin/modules');
  212. $this->assertNoText(t('There are updates available for your version of Drupal.'));
  213. $this->assertNoText(t('There is a security update available for your version of Drupal.'));
  214. }
  215. /**
  216. * Checks the messages at admin/modules when an update is missing.
  217. */
  218. function testModulePageRegularUpdate() {
  219. $this->setSystemInfo('8.0.0');
  220. // Instead of using refreshUpdateStatus(), set these manually.
  221. $this->config('update.settings')
  222. ->set('fetch.url', Url::fromRoute('update_test.update_test')->setAbsolute()->toString())
  223. ->save();
  224. $this->config('update_test.settings')
  225. ->set('xml_map', array('drupal' => '0.1'))
  226. ->save();
  227. $this->drupalGet('admin/reports/updates');
  228. $this->clickLink(t('Check manually'));
  229. $this->assertText(t('Checked available update data for one project.'));
  230. $this->drupalGet('admin/modules');
  231. $this->assertText(t('There are updates available for your version of Drupal.'));
  232. $this->assertNoText(t('There is a security update available for your version of Drupal.'));
  233. }
  234. /**
  235. * Checks the messages at admin/modules when a security update is missing.
  236. */
  237. function testModulePageSecurityUpdate() {
  238. $this->setSystemInfo('8.0.0');
  239. // Instead of using refreshUpdateStatus(), set these manually.
  240. $this->config('update.settings')
  241. ->set('fetch.url', Url::fromRoute('update_test.update_test')->setAbsolute()->toString())
  242. ->save();
  243. $this->config('update_test.settings')
  244. ->set('xml_map', array('drupal' => '0.2-sec'))
  245. ->save();
  246. $this->drupalGet('admin/reports/updates');
  247. $this->clickLink(t('Check manually'));
  248. $this->assertText(t('Checked available update data for one project.'));
  249. $this->drupalGet('admin/modules');
  250. $this->assertNoText(t('There are updates available for your version of Drupal.'));
  251. $this->assertText(t('There is a security update available for your version of Drupal.'));
  252. // Make sure admin/appearance warns you you're missing a security update.
  253. $this->drupalGet('admin/appearance');
  254. $this->assertNoText(t('There are updates available for your version of Drupal.'));
  255. $this->assertText(t('There is a security update available for your version of Drupal.'));
  256. // Make sure duplicate messages don't appear on Update status pages.
  257. $this->drupalGet('admin/reports/status');
  258. // We're expecting "There is a security update..." inside the status report
  259. // itself, but the drupal_set_message() appears as an li so we can prefix
  260. // with that and search for the raw HTML.
  261. $this->assertNoRaw('<li>' . t('There is a security update available for your version of Drupal.'));
  262. $this->drupalGet('admin/reports/updates');
  263. $this->assertNoText(t('There is a security update available for your version of Drupal.'));
  264. $this->drupalGet('admin/reports/updates/settings');
  265. $this->assertNoText(t('There is a security update available for your version of Drupal.'));
  266. }
  267. /**
  268. * Tests the Update Manager module when the update server returns 503 errors.
  269. */
  270. function testServiceUnavailable() {
  271. $this->refreshUpdateStatus(array(), '503-error');
  272. // Ensure that no "Warning: SimpleXMLElement..." parse errors are found.
  273. $this->assertNoText('SimpleXMLElement');
  274. $this->assertUniqueText(t('Failed to get available update data for one project.'));
  275. }
  276. /**
  277. * Tests that exactly one fetch task per project is created and not more.
  278. */
  279. function testFetchTasks() {
  280. $projecta = array(
  281. 'name' => 'aaa_update_test',
  282. );
  283. $projectb = array(
  284. 'name' => 'bbb_update_test',
  285. );
  286. $queue = \Drupal::queue('update_fetch_tasks');
  287. $this->assertEqual($queue->numberOfItems(), 0, 'Queue is empty');
  288. update_create_fetch_task($projecta);
  289. $this->assertEqual($queue->numberOfItems(), 1, 'Queue contains one item');
  290. update_create_fetch_task($projectb);
  291. $this->assertEqual($queue->numberOfItems(), 2, 'Queue contains two items');
  292. // Try to add project a again.
  293. update_create_fetch_task($projecta);
  294. $this->assertEqual($queue->numberOfItems(), 2, 'Queue still contains two items');
  295. // Clear storage and try again.
  296. update_storage_clear();
  297. update_create_fetch_task($projecta);
  298. $this->assertEqual($queue->numberOfItems(), 2, 'Queue contains two items');
  299. }
  300. /**
  301. * Checks language module in core package at admin/reports/updates.
  302. */
  303. function testLanguageModuleUpdate() {
  304. $this->setSystemInfo('8.0.0');
  305. // Instead of using refreshUpdateStatus(), set these manually.
  306. $this->config('update.settings')
  307. ->set('fetch.url', Url::fromRoute('update_test.update_test')->setAbsolute()->toString())
  308. ->save();
  309. $this->config('update_test.settings')
  310. ->set('xml_map', array('drupal' => '0.1'))
  311. ->save();
  312. $this->drupalGet('admin/reports/updates');
  313. $this->assertText(t('Language'));
  314. }
  315. /**
  316. * Ensures that the local actions appear.
  317. */
  318. public function testLocalActions() {
  319. $admin_user = $this->drupalCreateUser(array('administer site configuration', 'administer modules', 'administer software updates', 'administer themes'));
  320. $this->drupalLogin($admin_user);
  321. $this->drupalGet('admin/modules');
  322. $this->clickLink(t('Install new module'));
  323. $this->assertUrl('admin/modules/install');
  324. $this->drupalGet('admin/appearance');
  325. $this->clickLink(t('Install new theme'));
  326. $this->assertUrl('admin/theme/install');
  327. $this->drupalGet('admin/reports/updates');
  328. $this->clickLink(t('Install new module or theme'));
  329. $this->assertUrl('admin/reports/updates/install');
  330. }
  331. }