update.test

  1. drupal
    1. 7 modules/update/update.test
    2. 7 modules/simpletest/tests/update.test
    3. 8 core/modules/system/tests/update.test
    4. 8 core/modules/update/update.test

Tests for update.module.

This file contains tests for the update module. The overarching methodology of these tests is we need to compare a given state of installed modules and themes (e.g. version, project grouping, timestamps, etc) vs. a current state of what the release history XML files we fetch say is available. We have dummy XML files (in the 'tests' subdirectory) that describe various scenarios of what's available for different test projects, and we have dummy .info file data (specified via hook_system_info_alter() in the update_test helper module) describing what's currently installed. Each test case defines a set of projects to install, their current state (via the 'update_test_system_info' variable) and the desired available update data (via the 'update_test_xml_map' variable), and then performs a series of assertions that the report matches our expectations given the specific initial state and availability scenario.

Classes

NameDescription
UpdateCoreTestCase
UpdateCoreUnitTestCase
UpdateTestContribCase
UpdateTestHelperBase class to define some shared functions used by all update tests.
UpdateTestUploadCase

File

modules/update/update.test
View source
  1. <?php
  2. /**
  3. * @file
  4. * Tests for update.module.
  5. *
  6. * This file contains tests for the update module. The overarching methodology
  7. * of these tests is we need to compare a given state of installed modules and
  8. * themes (e.g. version, project grouping, timestamps, etc) vs. a current
  9. * state of what the release history XML files we fetch say is available. We
  10. * have dummy XML files (in the 'tests' subdirectory) that describe various
  11. * scenarios of what's available for different test projects, and we have
  12. * dummy .info file data (specified via hook_system_info_alter() in the
  13. * update_test helper module) describing what's currently installed. Each
  14. * test case defines a set of projects to install, their current state (via
  15. * the 'update_test_system_info' variable) and the desired available update
  16. * data (via the 'update_test_xml_map' variable), and then performs a series
  17. * of assertions that the report matches our expectations given the specific
  18. * initial state and availability scenario.
  19. */
  20. /**
  21. * Base class to define some shared functions used by all update tests.
  22. */
  23. class UpdateTestHelper extends DrupalWebTestCase {
  24. /**
  25. * Refresh the update status based on the desired available update scenario.
  26. *
  27. * @param $xml_map
  28. * Array that maps project names to availability scenarios to fetch.
  29. * The key '#all' is used if a project-specific mapping is not defined.
  30. *
  31. * @see update_test_mock_page()
  32. */
  33. protected function refreshUpdateStatus($xml_map, $url = 'update-test') {
  34. // Tell update module to fetch from the URL provided by update_test module.
  35. variable_set('update_fetch_url', url($url, array('absolute' => TRUE)));
  36. // Save the map for update_test_mock_page() to use.
  37. variable_set('update_test_xml_map', $xml_map);
  38. // Manually check the update status.
  39. $this->drupalGet('admin/reports/updates/check');
  40. }
  41. /**
  42. * Run a series of assertions that are applicable for all update statuses.
  43. */
  44. protected function standardTests() {
  45. $this->assertRaw('<h3>' . t('Drupal core') . '</h3>');
  46. $this->assertRaw(l(t('Drupal'), 'http://example.com/project/drupal'), t('Link to the Drupal project appears.'));
  47. $this->assertNoText(t('No available releases found'));
  48. }
  49. }
  50. class UpdateCoreTestCase extends UpdateTestHelper {
  51. public static function getInfo() {
  52. return array(
  53. 'name' => 'Update core functionality',
  54. 'description' => 'Tests the update module through a series of functional tests using mock XML data.',
  55. 'group' => 'Update',
  56. );
  57. }
  58. function setUp() {
  59. parent::setUp('update_test', 'update');
  60. $admin_user = $this->drupalCreateUser(array('administer site configuration', 'administer modules'));
  61. $this->drupalLogin($admin_user);
  62. }
  63. /**
  64. * Tests the update module when no updates are available.
  65. */
  66. function testNoUpdatesAvailable() {
  67. $this->setSystemInfo7_0();
  68. $this->refreshUpdateStatus(array('drupal' => '0'));
  69. $this->standardTests();
  70. $this->assertText(t('Up to date'));
  71. $this->assertNoText(t('Update available'));
  72. $this->assertNoText(t('Security update required!'));
  73. }
  74. /**
  75. * Tests the update module when one normal update ("7.1") is available.
  76. */
  77. function testNormalUpdateAvailable() {
  78. $this->setSystemInfo7_0();
  79. $this->refreshUpdateStatus(array('drupal' => '1'));
  80. $this->standardTests();
  81. $this->assertNoText(t('Up to date'));
  82. $this->assertText(t('Update available'));
  83. $this->assertNoText(t('Security update required!'));
  84. $this->assertRaw(l('7.1', 'http://example.com/drupal-7-1-release'), t('Link to release appears.'));
  85. $this->assertRaw(l(t('Download'), 'http://example.com/drupal-7-1.tar.gz'), t('Link to download appears.'));
  86. $this->assertRaw(l(t('Release notes'), 'http://example.com/drupal-7-1-release'), t('Link to release notes appears.'));
  87. }
  88. /**
  89. * Tests the update module when a security update ("7.2") is available.
  90. */
  91. function testSecurityUpdateAvailable() {
  92. $this->setSystemInfo7_0();
  93. $this->refreshUpdateStatus(array('drupal' => '2-sec'));
  94. $this->standardTests();
  95. $this->assertNoText(t('Up to date'));
  96. $this->assertNoText(t('Update available'));
  97. $this->assertText(t('Security update required!'));
  98. $this->assertRaw(l('7.2', 'http://example.com/drupal-7-2-release'), t('Link to release appears.'));
  99. $this->assertRaw(l(t('Download'), 'http://example.com/drupal-7-2.tar.gz'), t('Link to download appears.'));
  100. $this->assertRaw(l(t('Release notes'), 'http://example.com/drupal-7-2-release'), t('Link to release notes appears.'));
  101. }
  102. /**
  103. * Ensure proper results where there are date mismatches among modules.
  104. */
  105. function testDatestampMismatch() {
  106. $system_info = array(
  107. '#all' => array(
  108. // We need to think we're running a -dev snapshot to see dates.
  109. 'version' => '7.0-dev',
  110. 'datestamp' => time(),
  111. ),
  112. 'block' => array(
  113. // This is 2001-09-09 01:46:40 GMT, so test for "2001-Sep-".
  114. 'datestamp' => '1000000000',
  115. ),
  116. );
  117. variable_set('update_test_system_info', $system_info);
  118. $this->refreshUpdateStatus(array('drupal' => 'dev'));
  119. $this->assertNoText(t('2001-Sep-'));
  120. $this->assertText(t('Up to date'));
  121. $this->assertNoText(t('Update available'));
  122. $this->assertNoText(t('Security update required!'));
  123. }
  124. /**
  125. * Check that running cron updates the list of available updates.
  126. */
  127. function testModulePageRunCron() {
  128. $this->setSystemInfo7_0();
  129. variable_set('update_fetch_url', url('update-test', array('absolute' => TRUE)));
  130. variable_set('update_test_xml_map', array('drupal' => '0'));
  131. $this->cronRun();
  132. $this->drupalGet('admin/modules');
  133. $this->assertNoText(t('No update information available.'));
  134. }
  135. /**
  136. * Check the messages at admin/modules when the site is up to date.
  137. */
  138. function testModulePageUpToDate() {
  139. $this->setSystemInfo7_0();
  140. // Instead of using refreshUpdateStatus(), set these manually.
  141. variable_set('update_fetch_url', url('update-test', array('absolute' => TRUE)));
  142. variable_set('update_test_xml_map', array('drupal' => '0'));
  143. $this->drupalGet('admin/reports/updates');
  144. $this->clickLink(t('Check manually'));
  145. $this->assertText(t('Checked available update data for one project.'));
  146. $this->drupalGet('admin/modules');
  147. $this->assertNoText(t('There are updates available for your version of Drupal.'));
  148. $this->assertNoText(t('There is a security update available for your version of Drupal.'));
  149. }
  150. /**
  151. * Check the messages at admin/modules when missing an update.
  152. */
  153. function testModulePageRegularUpdate() {
  154. $this->setSystemInfo7_0();
  155. // Instead of using refreshUpdateStatus(), set these manually.
  156. variable_set('update_fetch_url', url('update-test', array('absolute' => TRUE)));
  157. variable_set('update_test_xml_map', array('drupal' => '1'));
  158. $this->drupalGet('admin/reports/updates');
  159. $this->clickLink(t('Check manually'));
  160. $this->assertText(t('Checked available update data for one project.'));
  161. $this->drupalGet('admin/modules');
  162. $this->assertText(t('There are updates available for your version of Drupal.'));
  163. $this->assertNoText(t('There is a security update available for your version of Drupal.'));
  164. }
  165. /**
  166. * Check the messages at admin/modules when missing a security update.
  167. */
  168. function testModulePageSecurityUpdate() {
  169. $this->setSystemInfo7_0();
  170. // Instead of using refreshUpdateStatus(), set these manually.
  171. variable_set('update_fetch_url', url('update-test', array('absolute' => TRUE)));
  172. variable_set('update_test_xml_map', array('drupal' => '2-sec'));
  173. $this->drupalGet('admin/reports/updates');
  174. $this->clickLink(t('Check manually'));
  175. $this->assertText(t('Checked available update data for one project.'));
  176. $this->drupalGet('admin/modules');
  177. $this->assertNoText(t('There are updates available for your version of Drupal.'));
  178. $this->assertText(t('There is a security update available for your version of Drupal.'));
  179. // Make sure admin/appearance warns you you're missing a security update.
  180. $this->drupalGet('admin/appearance');
  181. $this->assertNoText(t('There are updates available for your version of Drupal.'));
  182. $this->assertText(t('There is a security update available for your version of Drupal.'));
  183. // Make sure duplicate messages don't appear on Update status pages.
  184. $this->drupalGet('admin/reports/status');
  185. // We're expecting "There is a security update..." inside the status report
  186. // itself, but the drupal_set_message() appears as an li so we can prefix
  187. // with that and search for the raw HTML.
  188. $this->assertNoRaw('<li>' . t('There is a security update available for your version of Drupal.'));
  189. $this->drupalGet('admin/reports/updates');
  190. $this->assertNoText(t('There is a security update available for your version of Drupal.'));
  191. $this->drupalGet('admin/reports/updates/settings');
  192. $this->assertNoText(t('There is a security update available for your version of Drupal.'));
  193. }
  194. /**
  195. * Tests the update module when the update server returns 503 (Service unavailable) errors.
  196. */
  197. function testServiceUnavailable() {
  198. $this->refreshUpdateStatus(array(), '503-error');
  199. // Ensure that no "Warning: SimpleXMLElement..." parse errors are found.
  200. $this->assertNoText('SimpleXMLElement');
  201. $this->assertUniqueText(t('Failed to get available update data for one project.'));
  202. }
  203. /**
  204. * Tests that exactly one fetch task per project is created and not more.
  205. */
  206. function testFetchTasks() {
  207. $projecta = array(
  208. 'name' => 'aaa_update_test',
  209. );
  210. $projectb = array(
  211. 'name' => 'bbb_update_test',
  212. );
  213. $queue = DrupalQueue::get('update_fetch_tasks');
  214. $this->assertEqual($queue->numberOfItems(), 0, 'Queue is empty');
  215. update_create_fetch_task($projecta);
  216. $this->assertEqual($queue->numberOfItems(), 1, 'Queue contains one item');
  217. update_create_fetch_task($projectb);
  218. $this->assertEqual($queue->numberOfItems(), 2, 'Queue contains two items');
  219. // Try to add project a again.
  220. update_create_fetch_task($projecta);
  221. $this->assertEqual($queue->numberOfItems(), 2, 'Queue still contains two items');
  222. // Clear cache and try again.
  223. _update_cache_clear();
  224. drupal_static_reset('_update_create_fetch_task');
  225. update_create_fetch_task($projecta);
  226. $this->assertEqual($queue->numberOfItems(), 2, 'Queue contains two items');
  227. }
  228. protected function setSystemInfo7_0() {
  229. $setting = array(
  230. '#all' => array(
  231. 'version' => '7.0',
  232. ),
  233. );
  234. variable_set('update_test_system_info', $setting);
  235. }
  236. }
  237. class UpdateTestContribCase extends UpdateTestHelper {
  238. public static function getInfo() {
  239. return array(
  240. 'name' => 'Update contrib functionality',
  241. 'description' => 'Tests how the update module handles contributed modules and themes in a series of functional tests using mock XML data.',
  242. 'group' => 'Update',
  243. );
  244. }
  245. function setUp() {
  246. parent::setUp('update_test', 'update', 'aaa_update_test', 'bbb_update_test', 'ccc_update_test');
  247. $admin_user = $this->drupalCreateUser(array('administer site configuration'));
  248. $this->drupalLogin($admin_user);
  249. }
  250. /**
  251. * Tests when there is no available release data for a contrib module.
  252. */
  253. function testNoReleasesAvailable() {
  254. $system_info = array(
  255. '#all' => array(
  256. 'version' => '7.0',
  257. ),
  258. 'aaa_update_test' => array(
  259. 'project' => 'aaa_update_test',
  260. 'version' => '7.x-1.0',
  261. 'hidden' => FALSE,
  262. ),
  263. );
  264. variable_set('update_test_system_info', $system_info);
  265. $this->refreshUpdateStatus(array('drupal' => '0', 'aaa_update_test' => 'no-releases'));
  266. $this->drupalGet('admin/reports/updates');
  267. // Cannot use $this->standardTests() because we need to check for the
  268. // 'No available releases found' string.
  269. $this->assertRaw('<h3>' . t('Drupal core') . '</h3>');
  270. $this->assertRaw(l(t('Drupal'), 'http://example.com/project/drupal'));
  271. $this->assertText(t('Up to date'));
  272. $this->assertRaw('<h3>' . t('Modules') . '</h3>');
  273. $this->assertNoText(t('Update available'));
  274. $this->assertText(t('No available releases found'));
  275. $this->assertNoRaw(l(t('AAA Update test'), 'http://example.com/project/aaa_update_test'));
  276. }
  277. /**
  278. * Test the basic functionality of a contrib module on the status report.
  279. */
  280. function testUpdateContribBasic() {
  281. $system_info = array(
  282. '#all' => array(
  283. 'version' => '7.0',
  284. ),
  285. 'aaa_update_test' => array(
  286. 'project' => 'aaa_update_test',
  287. 'version' => '7.x-1.0',
  288. 'hidden' => FALSE,
  289. ),
  290. );
  291. variable_set('update_test_system_info', $system_info);
  292. $this->refreshUpdateStatus(
  293. array(
  294. 'drupal' => '0',
  295. 'aaa_update_test' => '1_0',
  296. )
  297. );
  298. $this->standardTests();
  299. $this->assertText(t('Up to date'));
  300. $this->assertRaw('<h3>' . t('Modules') . '</h3>');
  301. $this->assertNoText(t('Update available'));
  302. $this->assertRaw(l(t('AAA Update test'), 'http://example.com/project/aaa_update_test'), t('Link to aaa_update_test project appears.'));
  303. }
  304. /**
  305. * Test that contrib projects are ordered by project name.
  306. *
  307. * If a project contains multiple modules, we want to make sure that the
  308. * available updates report is sorted by the parent project names, not by
  309. * the names of the modules included in each project. In this test case, we
  310. * have 2 contrib projects, "BBB Update test" and "CCC Update test".
  311. * However, we have a module called "aaa_update_test" that's part of the
  312. * "CCC Update test" project. We need to make sure that we see the "BBB"
  313. * project before the "CCC" project, even though "CCC" includes a module
  314. * that's processed first if you sort alphabetically by module name (which
  315. * is the order we see things inside system_rebuild_module_data() for example).
  316. */
  317. function testUpdateContribOrder() {
  318. // We want core to be version 7.0.
  319. $system_info = array(
  320. '#all' => array(
  321. 'version' => '7.0',
  322. ),
  323. // All the rest should be visible as contrib modules at version 7.x-1.0.
  324. // aaa_update_test needs to be part of the "CCC Update test" project,
  325. // which would throw off the report if we weren't properly sorting by
  326. // the project names.
  327. 'aaa_update_test' => array(
  328. 'project' => 'ccc_update_test',
  329. 'version' => '7.x-1.0',
  330. 'hidden' => FALSE,
  331. ),
  332. // This should be its own project, and listed first on the report.
  333. 'bbb_update_test' => array(
  334. 'project' => 'bbb_update_test',
  335. 'version' => '7.x-1.0',
  336. 'hidden' => FALSE,
  337. ),
  338. // This will contain both aaa_update_test and ccc_update_test, and
  339. // should come after the bbb_update_test project.
  340. 'ccc_update_test' => array(
  341. 'project' => 'ccc_update_test',
  342. 'version' => '7.x-1.0',
  343. 'hidden' => FALSE,
  344. ),
  345. );
  346. variable_set('update_test_system_info', $system_info);
  347. $this->refreshUpdateStatus(array('drupal' => '0', '#all' => '1_0'));
  348. $this->standardTests();
  349. // We're expecting the report to say all projects are up to date.
  350. $this->assertText(t('Up to date'));
  351. $this->assertNoText(t('Update available'));
  352. // We want to see all 3 module names listed, since they'll show up either
  353. // as project names or as modules under the "Includes" listing.
  354. $this->assertText(t('AAA Update test'));
  355. $this->assertText(t('BBB Update test'));
  356. $this->assertText(t('CCC Update test'));
  357. // We want aaa_update_test included in the ccc_update_test project, not as
  358. // its own project on the report.
  359. $this->assertNoRaw(l(t('AAA Update test'), 'http://example.com/project/aaa_update_test'), t('Link to aaa_update_test project does not appear.'));
  360. // The other two should be listed as projects.
  361. $this->assertRaw(l(t('BBB Update test'), 'http://example.com/project/bbb_update_test'), t('Link to bbb_update_test project appears.'));
  362. $this->assertRaw(l(t('CCC Update test'), 'http://example.com/project/ccc_update_test'), t('Link to bbb_update_test project appears.'));
  363. // We want to make sure we see the BBB project before the CCC project.
  364. // Instead of just searching for 'BBB Update test' or something, we want
  365. // to use the full markup that starts the project entry itself, so that
  366. // we're really testing that the project listings are in the right order.
  367. $bbb_project_link = '<div class="project"><a href="http://example.com/project/bbb_update_test">BBB Update test</a>';
  368. $ccc_project_link = '<div class="project"><a href="http://example.com/project/ccc_update_test">CCC Update test</a>';
  369. $this->assertTrue(strpos($this->drupalGetContent(), $bbb_project_link) < strpos($this->drupalGetContent(), $ccc_project_link), "'BBB Update test' project is listed before the 'CCC Update test' project");
  370. }
  371. /**
  372. * Test that subthemes are notified about security updates for base themes.
  373. */
  374. function testUpdateBaseThemeSecurityUpdate() {
  375. // Only enable the subtheme, not the base theme.
  376. db_update('system')
  377. ->fields(array('status' => 1))
  378. ->condition('type', 'theme')
  379. ->condition('name', 'update_test_subtheme')
  380. ->execute();
  381. // Define the initial state for core and the subtheme.
  382. $system_info = array(
  383. // We want core to be version 7.0.
  384. '#all' => array(
  385. 'version' => '7.0',
  386. ),
  387. // Show the update_test_basetheme
  388. 'update_test_basetheme' => array(
  389. 'project' => 'update_test_basetheme',
  390. 'version' => '7.x-1.0',
  391. 'hidden' => FALSE,
  392. ),
  393. // Show the update_test_subtheme
  394. 'update_test_subtheme' => array(
  395. 'project' => 'update_test_subtheme',
  396. 'version' => '7.x-1.0',
  397. 'hidden' => FALSE,
  398. ),
  399. );
  400. variable_set('update_test_system_info', $system_info);
  401. $xml_mapping = array(
  402. 'drupal' => '0',
  403. 'update_test_subtheme' => '1_0',
  404. 'update_test_basetheme' => '1_1-sec',
  405. );
  406. $this->refreshUpdateStatus($xml_mapping);
  407. $this->assertText(t('Security update required!'));
  408. $this->assertRaw(l(t('Update test base theme'), 'http://example.com/project/update_test_basetheme'), t('Link to the Update test base theme project appears.'));
  409. }
  410. /**
  411. * Test that disabled themes are only shown when desired.
  412. */
  413. function testUpdateShowDisabledThemes() {
  414. // Make sure all the update_test_* themes are disabled.
  415. db_update('system')
  416. ->fields(array('status' => 0))
  417. ->condition('type', 'theme')
  418. ->condition('name', 'update_test_%', 'LIKE')
  419. ->execute();
  420. // Define the initial state for core and the test contrib themes.
  421. $system_info = array(
  422. // We want core to be version 7.0.
  423. '#all' => array(
  424. 'version' => '7.0',
  425. ),
  426. // The update_test_basetheme should be visible and up to date.
  427. 'update_test_basetheme' => array(
  428. 'project' => 'update_test_basetheme',
  429. 'version' => '7.x-1.1',
  430. 'hidden' => FALSE,
  431. ),
  432. // The update_test_subtheme should be visible and up to date.
  433. 'update_test_subtheme' => array(
  434. 'project' => 'update_test_subtheme',
  435. 'version' => '7.x-1.0',
  436. 'hidden' => FALSE,
  437. ),
  438. );
  439. // When there are contributed modules in the site's file system, the
  440. // total number of attempts made in the test may exceed the default value
  441. // of update_max_fetch_attempts. Therefore this variable is set very high
  442. // to avoid test failures in those cases.
  443. variable_set('update_max_fetch_attempts', 99999);
  444. variable_set('update_test_system_info', $system_info);
  445. $xml_mapping = array(
  446. 'drupal' => '0',
  447. 'update_test_subtheme' => '1_0',
  448. 'update_test_basetheme' => '1_1-sec',
  449. );
  450. $base_theme_project_link = l(t('Update test base theme'), 'http://example.com/project/update_test_basetheme');
  451. $sub_theme_project_link = l(t('Update test subtheme'), 'http://example.com/project/update_test_subtheme');
  452. foreach (array(TRUE, FALSE) as $check_disabled) {
  453. variable_set('update_check_disabled', $check_disabled);
  454. $this->refreshUpdateStatus($xml_mapping);
  455. // In neither case should we see the "Themes" heading for enabled themes.
  456. $this->assertNoText(t('Themes'));
  457. if ($check_disabled) {
  458. $this->assertText(t('Disabled themes'));
  459. $this->assertRaw($base_theme_project_link, t('Link to the Update test base theme project appears.'));
  460. $this->assertRaw($sub_theme_project_link, t('Link to the Update test subtheme project appears.'));
  461. }
  462. else {
  463. $this->assertNoText(t('Disabled themes'));
  464. $this->assertNoRaw($base_theme_project_link, t('Link to the Update test base theme project does not appear.'));
  465. $this->assertNoRaw($sub_theme_project_link, t('Link to the Update test subtheme project does not appear.'));
  466. }
  467. }
  468. }
  469. /**
  470. * Make sure that if we fetch from a broken URL, sane things happen.
  471. */
  472. function testUpdateBrokenFetchURL() {
  473. $system_info = array(
  474. '#all' => array(
  475. 'version' => '7.0',
  476. ),
  477. 'aaa_update_test' => array(
  478. 'project' => 'aaa_update_test',
  479. 'version' => '7.x-1.0',
  480. 'hidden' => FALSE,
  481. ),
  482. 'bbb_update_test' => array(
  483. 'project' => 'bbb_update_test',
  484. 'version' => '7.x-1.0',
  485. 'hidden' => FALSE,
  486. ),
  487. 'ccc_update_test' => array(
  488. 'project' => 'ccc_update_test',
  489. 'version' => '7.x-1.0',
  490. 'hidden' => FALSE,
  491. ),
  492. );
  493. variable_set('update_test_system_info', $system_info);
  494. $xml_mapping = array(
  495. 'drupal' => '0',
  496. 'aaa_update_test' => '1_0',
  497. 'bbb_update_test' => 'does-not-exist',
  498. 'ccc_update_test' => '1_0',
  499. );
  500. $this->refreshUpdateStatus($xml_mapping);
  501. $this->assertText(t('Up to date'));
  502. // We're expecting the report to say most projects are up to date, so we
  503. // hope that 'Up to date' is not unique.
  504. $this->assertNoUniqueText(t('Up to date'));
  505. // It should say we failed to get data, not that we're missing an update.
  506. $this->assertNoText(t('Update available'));
  507. // We need to check that this string is found as part of a project row,
  508. // not just in the "Failed to get available update data for ..." message
  509. // at the top of the page.
  510. $this->assertRaw('<div class="version-status">' . t('Failed to get available update data'));
  511. // We should see the output messages from fetching manually.
  512. $this->assertUniqueText(t('Checked available update data for 3 projects.'));
  513. $this->assertUniqueText(t('Failed to get available update data for one project.'));
  514. // The other two should be listed as projects.
  515. $this->assertRaw(l(t('AAA Update test'), 'http://example.com/project/aaa_update_test'), t('Link to aaa_update_test project appears.'));
  516. $this->assertNoRaw(l(t('BBB Update test'), 'http://example.com/project/bbb_update_test'), t('Link to bbb_update_test project does not appear.'));
  517. $this->assertRaw(l(t('CCC Update test'), 'http://example.com/project/ccc_update_test'), t('Link to bbb_update_test project appears.'));
  518. }
  519. /**
  520. * Check that hook_update_status_alter() works to change a status.
  521. *
  522. * We provide the same external data as if aaa_update_test 7.x-1.0 were
  523. * installed and that was the latest release. Then we use
  524. * hook_update_status_alter() to try to mark this as missing a security
  525. * update, then assert if we see the appropriate warnings on the right
  526. * pages.
  527. */
  528. function testHookUpdateStatusAlter() {
  529. variable_set('allow_authorize_operations', TRUE);
  530. $update_admin_user = $this->drupalCreateUser(array('administer site configuration', 'administer software updates'));
  531. $this->drupalLogin($update_admin_user);
  532. $system_info = array(
  533. '#all' => array(
  534. 'version' => '7.0',
  535. ),
  536. 'aaa_update_test' => array(
  537. 'project' => 'aaa_update_test',
  538. 'version' => '7.x-1.0',
  539. 'hidden' => FALSE,
  540. ),
  541. );
  542. variable_set('update_test_system_info', $system_info);
  543. $update_status = array(
  544. 'aaa_update_test' => array(
  545. 'status' => UPDATE_NOT_SECURE,
  546. ),
  547. );
  548. variable_set('update_test_update_status', $update_status);
  549. $this->refreshUpdateStatus(
  550. array(
  551. 'drupal' => '0',
  552. 'aaa_update_test' => '1_0',
  553. )
  554. );
  555. $this->drupalGet('admin/reports/updates');
  556. $this->assertRaw('<h3>' . t('Modules') . '</h3>');
  557. $this->assertText(t('Security update required!'));
  558. $this->assertRaw(l(t('AAA Update test'), 'http://example.com/project/aaa_update_test'), t('Link to aaa_update_test project appears.'));
  559. // Visit the reports page again without the altering and make sure the
  560. // status is back to normal.
  561. variable_set('update_test_update_status', array());
  562. $this->drupalGet('admin/reports/updates');
  563. $this->assertRaw('<h3>' . t('Modules') . '</h3>');
  564. $this->assertNoText(t('Security update required!'));
  565. $this->assertRaw(l(t('AAA Update test'), 'http://example.com/project/aaa_update_test'), t('Link to aaa_update_test project appears.'));
  566. // Turn the altering back on and visit the Update manager UI.
  567. variable_set('update_test_update_status', $update_status);
  568. $this->drupalGet('admin/modules/update');
  569. $this->assertText(t('Security update'));
  570. // Turn the altering back off and visit the Update manager UI.
  571. variable_set('update_test_update_status', array());
  572. $this->drupalGet('admin/modules/update');
  573. $this->assertNoText(t('Security update'));
  574. }
  575. }
  576. class UpdateTestUploadCase extends UpdateTestHelper {
  577. public static function getInfo() {
  578. return array(
  579. 'name' => 'Upload and extract module functionality',
  580. 'description' => 'Tests the update module\'s upload and extraction functionality.',
  581. 'group' => 'Update',
  582. );
  583. }
  584. public function setUp() {
  585. parent::setUp('update', 'update_test');
  586. variable_set('allow_authorize_operations', TRUE);
  587. $admin_user = $this->drupalCreateUser(array('administer software updates', 'administer site configuration'));
  588. $this->drupalLogin($admin_user);
  589. }
  590. /**
  591. * Tests upload and extraction of a module.
  592. */
  593. public function testUploadModule() {
  594. // Images are not valid archives, so get one and try to install it. We
  595. // need an extra variable to store the result of drupalGetTestFiles()
  596. // since reset() takes an argument by reference and passing in a constant
  597. // emits a notice in strict mode.
  598. $imageTestFiles = $this->drupalGetTestFiles('image');
  599. $invalidArchiveFile = reset($imageTestFiles);
  600. $edit = array(
  601. 'files[project_upload]' => $invalidArchiveFile->uri,
  602. );
  603. // This also checks that the correct archive extensions are allowed.
  604. $this->drupalPost('admin/modules/install', $edit, t('Install'));
  605. $this->assertText(t('Only files with the following extensions are allowed: @archive_extensions.', array('@archive_extensions' => archiver_get_extensions())),'Only valid archives can be uploaded.');
  606. // Check to ensure an existing module can't be reinstalled. Also checks that
  607. // the archive was extracted since we can't know if the module is already
  608. // installed until after extraction.
  609. $validArchiveFile = drupal_get_path('module', 'update') . '/tests/aaa_update_test.tar.gz';
  610. $edit = array(
  611. 'files[project_upload]' => $validArchiveFile,
  612. );
  613. $this->drupalPost('admin/modules/install', $edit, t('Install'));
  614. $this->assertText(t('@module_name is already installed.', array('@module_name' => 'AAA Update test')), 'Existing module was extracted and not reinstalled.');
  615. }
  616. /**
  617. * Ensure that archiver extensions are properly merged in the UI.
  618. */
  619. function testFileNameExtensionMerging() {
  620. $this->drupalGet('admin/modules/install');
  621. // Make sure the bogus extension supported by update_test.module is there.
  622. $this->assertPattern('/file extensions are supported:.*update-test-extension/', t("Found 'update-test-extension' extension"));
  623. // Make sure it didn't clobber the first option from core.
  624. $this->assertPattern('/file extensions are supported:.*tar/', t("Found 'tar' extension"));
  625. }
  626. /**
  627. * Check the messages on Update manager pages when missing a security update.
  628. */
  629. function testUpdateManagerCoreSecurityUpdateMessages() {
  630. $setting = array(
  631. '#all' => array(
  632. 'version' => '7.0',
  633. ),
  634. );
  635. variable_set('update_test_system_info', $setting);
  636. variable_set('update_fetch_url', url('update-test', array('absolute' => TRUE)));
  637. variable_set('update_test_xml_map', array('drupal' => '2-sec'));
  638. // Initialize the update status.
  639. $this->drupalGet('admin/reports/updates');
  640. // Now, make sure none of the Update manager pages have duplicate messages
  641. // about core missing a security update.
  642. $this->drupalGet('admin/modules/install');
  643. $this->assertNoText(t('There is a security update available for your version of Drupal.'));
  644. $this->drupalGet('admin/modules/update');
  645. $this->assertNoText(t('There is a security update available for your version of Drupal.'));
  646. $this->drupalGet('admin/appearance/install');
  647. $this->assertNoText(t('There is a security update available for your version of Drupal.'));
  648. $this->drupalGet('admin/appearance/update');
  649. $this->assertNoText(t('There is a security update available for your version of Drupal.'));
  650. $this->drupalGet('admin/reports/updates/install');
  651. $this->assertNoText(t('There is a security update available for your version of Drupal.'));
  652. $this->drupalGet('admin/reports/updates/update');
  653. $this->assertNoText(t('There is a security update available for your version of Drupal.'));
  654. $this->drupalGet('admin/update/ready');
  655. $this->assertNoText(t('There is a security update available for your version of Drupal.'));
  656. }
  657. }
  658. class UpdateCoreUnitTestCase extends DrupalUnitTestCase {
  659. public static function getInfo() {
  660. return array(
  661. 'name' => "Unit tests",
  662. 'description' => 'Test update funcionality unrelated to the database.',
  663. 'group' => 'Update',
  664. );
  665. }
  666. function setUp() {
  667. parent::setUp('update');
  668. module_load_include('inc', 'update', 'update.fetch');
  669. }
  670. /**
  671. * Tests _update_build_fetch_url according to issue 1481156
  672. */
  673. function testUpdateBuildFetchUrl() {
  674. //first test that we didn't break the trivial case
  675. $project['name'] = 'update_test';
  676. $project['project_type'] = '';
  677. $project['info']['version'] = '';
  678. $project['info']['project status url'] = 'http://www.example.com';
  679. $site_key = '';
  680. $expected = 'http://www.example.com/' . $project['name'] . '/' . DRUPAL_CORE_COMPATIBILITY;
  681. $url = _update_build_fetch_url($project, $site_key);
  682. $this->assertEqual($url, $expected, "'$url' when no site_key provided should be '$expected'.");
  683. //For disabled projects it shouldn't add the site key either.
  684. $site_key = 'site_key';
  685. $project['project_type'] = 'disabled';
  686. $expected = 'http://www.example.com/' . $project['name'] . '/' . DRUPAL_CORE_COMPATIBILITY;
  687. $url = _update_build_fetch_url($project, $site_key);
  688. $this->assertEqual($url, $expected, "'$url' should be '$expected' for disabled projects.");
  689. //for enabled projects, adding the site key
  690. $project['project_type'] = '';
  691. $expected = 'http://www.example.com/' . $project['name'] . '/' . DRUPAL_CORE_COMPATIBILITY;
  692. $expected .= '?site_key=site_key';
  693. $url = _update_build_fetch_url($project, $site_key);
  694. $this->assertEqual($url, $expected, "When site_key provided, '$url' should be '$expected'.");
  695. // http://drupal.org/node/1481156 test incorrect logic when url contains
  696. // a question mark.
  697. $project['info']['project status url'] = 'http://www.example.com/?project=';
  698. $expected = 'http://www.example.com/?project=/' . $project['name'] . '/' . DRUPAL_CORE_COMPATIBILITY;
  699. $expected .= '&site_key=site_key';
  700. $url = _update_build_fetch_url($project, $site_key);
  701. $this->assertEqual($url, $expected, "When ? is present, '$url' should be '$expected'.");
  702. }
  703. }
Login or register to post comments