update.test 32 KB

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