update.test 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854
  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'), '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'), 'Link to release appears.');
  92. $this->assertRaw(l(t('Download'), 'http://example.com/drupal-7-1.tar.gz'), 'Link to download appears.');
  93. $this->assertRaw(l(t('Release notes'), 'http://example.com/drupal-7-1-release'), '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'), 'Link to release appears.');
  106. $this->assertRaw(l(t('Download'), 'http://example.com/drupal-7-2.tar.gz'), 'Link to download appears.');
  107. $this->assertRaw(l(t('Release notes'), 'http://example.com/drupal-7-2-release'), '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. $update_log = db_query_range('SELECT message FROM {watchdog} WHERE type = :type ORDER BY wid DESC', 0, 1, array(':type' => 'update'))->fetchField();
  210. $this->assertEqual('Error %errorcode (%message) occurred when trying to fetch available update data for the project %project.', $update_log, 'Failed update logged');
  211. }
  212. /**
  213. * Tests that exactly one fetch task per project is created and not more.
  214. */
  215. function testFetchTasks() {
  216. $projecta = array(
  217. 'name' => 'aaa_update_test',
  218. );
  219. $projectb = array(
  220. 'name' => 'bbb_update_test',
  221. );
  222. $queue = DrupalQueue::get('update_fetch_tasks');
  223. $this->assertEqual($queue->numberOfItems(), 0, 'Queue is empty');
  224. update_create_fetch_task($projecta);
  225. $this->assertEqual($queue->numberOfItems(), 1, 'Queue contains one item');
  226. update_create_fetch_task($projectb);
  227. $this->assertEqual($queue->numberOfItems(), 2, 'Queue contains two items');
  228. // Try to add project a again.
  229. update_create_fetch_task($projecta);
  230. $this->assertEqual($queue->numberOfItems(), 2, 'Queue still contains two items');
  231. // Clear cache and try again.
  232. _update_cache_clear();
  233. drupal_static_reset('_update_create_fetch_task');
  234. update_create_fetch_task($projecta);
  235. $this->assertEqual($queue->numberOfItems(), 2, 'Queue contains two items');
  236. }
  237. /**
  238. * Sets the version to 7.0 when no project-specific mapping is defined.
  239. */
  240. protected function setSystemInfo7_0() {
  241. $setting = array(
  242. '#all' => array(
  243. 'version' => '7.0',
  244. ),
  245. );
  246. variable_set('update_test_system_info', $setting);
  247. }
  248. }
  249. /**
  250. * Tests behavior related to handling updates to contributed modules and themes.
  251. */
  252. class UpdateTestContribCase extends UpdateTestHelper {
  253. public static function getInfo() {
  254. return array(
  255. 'name' => 'Update contrib functionality',
  256. 'description' => 'Tests how the Update Manager module handles contributed modules and themes in a series of functional tests using mock XML data.',
  257. 'group' => 'Update',
  258. );
  259. }
  260. function setUp() {
  261. parent::setUp('update_test', 'update', 'aaa_update_test', 'bbb_update_test', 'ccc_update_test');
  262. $admin_user = $this->drupalCreateUser(array('administer site configuration'));
  263. $this->drupalLogin($admin_user);
  264. }
  265. /**
  266. * Tests when there is no available release data for a contrib module.
  267. */
  268. function testNoReleasesAvailable() {
  269. $system_info = array(
  270. '#all' => array(
  271. 'version' => '7.0',
  272. ),
  273. 'aaa_update_test' => array(
  274. 'project' => 'aaa_update_test',
  275. 'version' => '7.x-1.0',
  276. 'hidden' => FALSE,
  277. ),
  278. );
  279. variable_set('update_test_system_info', $system_info);
  280. $this->refreshUpdateStatus(array('drupal' => '0', 'aaa_update_test' => 'no-releases'));
  281. $this->drupalGet('admin/reports/updates');
  282. // Cannot use $this->standardTests() because we need to check for the
  283. // 'No available releases found' string.
  284. $this->assertRaw('<h3>' . t('Drupal core') . '</h3>');
  285. $this->assertRaw(l(t('Drupal'), 'http://example.com/project/drupal'));
  286. $this->assertText(t('Up to date'));
  287. $this->assertRaw('<h3>' . t('Modules') . '</h3>');
  288. $this->assertNoText(t('Update available'));
  289. $this->assertText(t('No available releases found'));
  290. $this->assertNoRaw(l(t('AAA Update test'), 'http://example.com/project/aaa_update_test'));
  291. }
  292. /**
  293. * Tests the basic functionality of a contrib module on the status report.
  294. */
  295. function testUpdateContribBasic() {
  296. $system_info = array(
  297. '#all' => array(
  298. 'version' => '7.0',
  299. ),
  300. 'aaa_update_test' => array(
  301. 'project' => 'aaa_update_test',
  302. 'version' => '7.x-1.0',
  303. 'hidden' => FALSE,
  304. ),
  305. );
  306. variable_set('update_test_system_info', $system_info);
  307. $this->refreshUpdateStatus(
  308. array(
  309. 'drupal' => '0',
  310. 'aaa_update_test' => '1_0',
  311. )
  312. );
  313. $this->standardTests();
  314. $this->assertText(t('Up to date'));
  315. $this->assertRaw('<h3>' . t('Modules') . '</h3>');
  316. $this->assertNoText(t('Update available'));
  317. $this->assertRaw(l(t('AAA Update test'), 'http://example.com/project/aaa_update_test'), 'Link to aaa_update_test project appears.');
  318. }
  319. /**
  320. * Tests that contrib projects are ordered by project name.
  321. *
  322. * If a project contains multiple modules, we want to make sure that the
  323. * available updates report is sorted by the parent project names, not by the
  324. * names of the modules included in each project. In this test case, we have
  325. * two contrib projects, "BBB Update test" and "CCC Update test". However, we
  326. * have a module called "aaa_update_test" that's part of the "CCC Update test"
  327. * project. We need to make sure that we see the "BBB" project before the
  328. * "CCC" project, even though "CCC" includes a module that's processed first
  329. * if you sort alphabetically by module name (which is the order we see things
  330. * inside system_rebuild_module_data() for example).
  331. */
  332. function testUpdateContribOrder() {
  333. // We want core to be version 7.0.
  334. $system_info = array(
  335. '#all' => array(
  336. 'version' => '7.0',
  337. ),
  338. // All the rest should be visible as contrib modules at version 7.x-1.0.
  339. // aaa_update_test needs to be part of the "CCC Update test" project,
  340. // which would throw off the report if we weren't properly sorting by
  341. // the project names.
  342. 'aaa_update_test' => array(
  343. 'project' => 'ccc_update_test',
  344. 'version' => '7.x-1.0',
  345. 'hidden' => FALSE,
  346. ),
  347. // This should be its own project, and listed first on the report.
  348. 'bbb_update_test' => array(
  349. 'project' => 'bbb_update_test',
  350. 'version' => '7.x-1.0',
  351. 'hidden' => FALSE,
  352. ),
  353. // This will contain both aaa_update_test and ccc_update_test, and
  354. // should come after the bbb_update_test project.
  355. 'ccc_update_test' => array(
  356. 'project' => 'ccc_update_test',
  357. 'version' => '7.x-1.0',
  358. 'hidden' => FALSE,
  359. ),
  360. );
  361. variable_set('update_test_system_info', $system_info);
  362. $this->refreshUpdateStatus(array('drupal' => '0', '#all' => '1_0'));
  363. $this->standardTests();
  364. // We're expecting the report to say all projects are up to date.
  365. $this->assertText(t('Up to date'));
  366. $this->assertNoText(t('Update available'));
  367. // We want to see all 3 module names listed, since they'll show up either
  368. // as project names or as modules under the "Includes" listing.
  369. $this->assertText(t('AAA Update test'));
  370. $this->assertText(t('BBB Update test'));
  371. $this->assertText(t('CCC Update test'));
  372. // We want aaa_update_test included in the ccc_update_test project, not as
  373. // its own project on the report.
  374. $this->assertNoRaw(l(t('AAA Update test'), 'http://example.com/project/aaa_update_test'), 'Link to aaa_update_test project does not appear.');
  375. // The other two should be listed as projects.
  376. $this->assertRaw(l(t('BBB Update test'), 'http://example.com/project/bbb_update_test'), 'Link to bbb_update_test project appears.');
  377. $this->assertRaw(l(t('CCC Update test'), 'http://example.com/project/ccc_update_test'), 'Link to bbb_update_test project appears.');
  378. // We want to make sure we see the BBB project before the CCC project.
  379. // Instead of just searching for 'BBB Update test' or something, we want
  380. // to use the full markup that starts the project entry itself, so that
  381. // we're really testing that the project listings are in the right order.
  382. $bbb_project_link = '<div class="project"><a href="http://example.com/project/bbb_update_test">BBB Update test</a>';
  383. $ccc_project_link = '<div class="project"><a href="http://example.com/project/ccc_update_test">CCC Update test</a>';
  384. $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");
  385. }
  386. /**
  387. * Tests that subthemes are notified about security updates for base themes.
  388. */
  389. function testUpdateBaseThemeSecurityUpdate() {
  390. // Only enable the subtheme, not the base theme.
  391. db_update('system')
  392. ->fields(array('status' => 1))
  393. ->condition('type', 'theme')
  394. ->condition('name', 'update_test_subtheme')
  395. ->execute();
  396. // Define the initial state for core and the subtheme.
  397. $system_info = array(
  398. // We want core to be version 7.0.
  399. '#all' => array(
  400. 'version' => '7.0',
  401. ),
  402. // Show the update_test_basetheme
  403. 'update_test_basetheme' => array(
  404. 'project' => 'update_test_basetheme',
  405. 'version' => '7.x-1.0',
  406. 'hidden' => FALSE,
  407. ),
  408. // Show the update_test_subtheme
  409. 'update_test_subtheme' => array(
  410. 'project' => 'update_test_subtheme',
  411. 'version' => '7.x-1.0',
  412. 'hidden' => FALSE,
  413. ),
  414. );
  415. variable_set('update_test_system_info', $system_info);
  416. $xml_mapping = array(
  417. 'drupal' => '0',
  418. 'update_test_subtheme' => '1_0',
  419. 'update_test_basetheme' => '1_1-sec',
  420. );
  421. $this->refreshUpdateStatus($xml_mapping);
  422. $this->assertText(t('Security update required!'));
  423. $this->assertRaw(l(t('Update test base theme'), 'http://example.com/project/update_test_basetheme'), 'Link to the Update test base theme project appears.');
  424. }
  425. /**
  426. * Tests that the admin theme is always notified about security updates.
  427. */
  428. function testUpdateAdminThemeSecurityUpdate() {
  429. // Disable the admin theme.
  430. db_update('system')
  431. ->fields(array('status' => 0))
  432. ->condition('type', 'theme')
  433. ->condition('name', 'update_test_%', 'LIKE')
  434. ->execute();
  435. variable_set('admin_theme', 'update_test_admintheme');
  436. // Define the initial state for core and the themes.
  437. $system_info = array(
  438. '#all' => array(
  439. 'version' => '7.0',
  440. ),
  441. 'update_test_admintheme' => array(
  442. 'project' => 'update_test_admintheme',
  443. 'version' => '7.x-1.0',
  444. 'hidden' => FALSE,
  445. ),
  446. 'update_test_basetheme' => array(
  447. 'project' => 'update_test_basetheme',
  448. 'version' => '7.x-1.1',
  449. 'hidden' => FALSE,
  450. ),
  451. 'update_test_subtheme' => array(
  452. 'project' => 'update_test_subtheme',
  453. 'version' => '7.x-1.0',
  454. 'hidden' => FALSE,
  455. ),
  456. );
  457. variable_set('update_test_system_info', $system_info);
  458. variable_set('update_check_disabled', FALSE);
  459. $xml_mapping = array(
  460. // This is enough because we don't check the update status of the admin
  461. // theme. We want to check that the admin theme is included in the list.
  462. 'drupal' => '0',
  463. );
  464. $this->refreshUpdateStatus($xml_mapping);
  465. // The admin theme is displayed even if it's disabled.
  466. $this->assertText('update_test_admintheme', "The admin theme is checked for update even if it's disabled");
  467. // The other disabled themes are not displayed.
  468. $this->assertNoText('update_test_basetheme', 'Disabled theme is not checked for update in the list.');
  469. $this->assertNoText('update_test_subtheme', 'Disabled theme is not checked for update in the list.');
  470. }
  471. /**
  472. * Tests that disabled themes are only shown when desired.
  473. */
  474. function testUpdateShowDisabledThemes() {
  475. // Make sure all the update_test_* themes are disabled.
  476. db_update('system')
  477. ->fields(array('status' => 0))
  478. ->condition('type', 'theme')
  479. ->condition('name', 'update_test_%', 'LIKE')
  480. ->execute();
  481. // Define the initial state for core and the test contrib themes.
  482. $system_info = array(
  483. // We want core to be version 7.0.
  484. '#all' => array(
  485. 'version' => '7.0',
  486. ),
  487. // The update_test_basetheme should be visible and up to date.
  488. 'update_test_basetheme' => array(
  489. 'project' => 'update_test_basetheme',
  490. 'version' => '7.x-1.1',
  491. 'hidden' => FALSE,
  492. ),
  493. // The update_test_subtheme should be visible and up to date.
  494. 'update_test_subtheme' => array(
  495. 'project' => 'update_test_subtheme',
  496. 'version' => '7.x-1.0',
  497. 'hidden' => FALSE,
  498. ),
  499. );
  500. // When there are contributed modules in the site's file system, the
  501. // total number of attempts made in the test may exceed the default value
  502. // of update_max_fetch_attempts. Therefore this variable is set very high
  503. // to avoid test failures in those cases.
  504. variable_set('update_max_fetch_attempts', 99999);
  505. variable_set('update_test_system_info', $system_info);
  506. $xml_mapping = array(
  507. 'drupal' => '0',
  508. 'update_test_subtheme' => '1_0',
  509. 'update_test_basetheme' => '1_1-sec',
  510. );
  511. $base_theme_project_link = l(t('Update test base theme'), 'http://example.com/project/update_test_basetheme');
  512. $sub_theme_project_link = l(t('Update test subtheme'), 'http://example.com/project/update_test_subtheme');
  513. foreach (array(TRUE, FALSE) as $check_disabled) {
  514. variable_set('update_check_disabled', $check_disabled);
  515. $this->refreshUpdateStatus($xml_mapping);
  516. // In neither case should we see the "Themes" heading for enabled themes.
  517. $this->assertNoText(t('Themes'));
  518. if ($check_disabled) {
  519. $this->assertText(t('Disabled themes'));
  520. $this->assertRaw($base_theme_project_link, 'Link to the Update test base theme project appears.');
  521. $this->assertRaw($sub_theme_project_link, 'Link to the Update test subtheme project appears.');
  522. }
  523. else {
  524. $this->assertNoText(t('Disabled themes'));
  525. $this->assertNoRaw($base_theme_project_link, 'Link to the Update test base theme project does not appear.');
  526. $this->assertNoRaw($sub_theme_project_link, 'Link to the Update test subtheme project does not appear.');
  527. }
  528. }
  529. }
  530. /**
  531. * Makes sure that if we fetch from a broken URL, sane things happen.
  532. */
  533. function testUpdateBrokenFetchURL() {
  534. $system_info = array(
  535. '#all' => array(
  536. 'version' => '7.0',
  537. ),
  538. 'aaa_update_test' => array(
  539. 'project' => 'aaa_update_test',
  540. 'version' => '7.x-1.0',
  541. 'hidden' => FALSE,
  542. ),
  543. 'bbb_update_test' => array(
  544. 'project' => 'bbb_update_test',
  545. 'version' => '7.x-1.0',
  546. 'hidden' => FALSE,
  547. ),
  548. 'ccc_update_test' => array(
  549. 'project' => 'ccc_update_test',
  550. 'version' => '7.x-1.0',
  551. 'hidden' => FALSE,
  552. ),
  553. );
  554. variable_set('update_test_system_info', $system_info);
  555. $xml_mapping = array(
  556. 'drupal' => '0',
  557. 'aaa_update_test' => '1_0',
  558. 'bbb_update_test' => 'does-not-exist',
  559. 'ccc_update_test' => '1_0',
  560. );
  561. $this->refreshUpdateStatus($xml_mapping);
  562. $this->assertText(t('Up to date'));
  563. // We're expecting the report to say most projects are up to date, so we
  564. // hope that 'Up to date' is not unique.
  565. $this->assertNoUniqueText(t('Up to date'));
  566. // It should say we failed to get data, not that we're missing an update.
  567. $this->assertNoText(t('Update available'));
  568. // We need to check that this string is found as part of a project row,
  569. // not just in the "Failed to get available update data for ..." message
  570. // at the top of the page.
  571. $this->assertRaw('<div class="version-status">' . t('Failed to get available update data'));
  572. // We should see the output messages from fetching manually.
  573. $this->assertUniqueText(t('Checked available update data for 3 projects.'));
  574. $this->assertUniqueText(t('Failed to get available update data for one project.'));
  575. // The other two should be listed as projects.
  576. $this->assertRaw(l(t('AAA Update test'), 'http://example.com/project/aaa_update_test'), 'Link to aaa_update_test project appears.');
  577. $this->assertNoRaw(l(t('BBB Update test'), 'http://example.com/project/bbb_update_test'), 'Link to bbb_update_test project does not appear.');
  578. $this->assertRaw(l(t('CCC Update test'), 'http://example.com/project/ccc_update_test'), 'Link to bbb_update_test project appears.');
  579. }
  580. /**
  581. * Checks that hook_update_status_alter() works to change a status.
  582. *
  583. * We provide the same external data as if aaa_update_test 7.x-1.0 were
  584. * installed and that was the latest release. Then we use
  585. * hook_update_status_alter() to try to mark this as missing a security
  586. * update, then assert if we see the appropriate warnings on the right pages.
  587. */
  588. function testHookUpdateStatusAlter() {
  589. variable_set('allow_authorize_operations', TRUE);
  590. $update_admin_user = $this->drupalCreateUser(array('administer site configuration', 'administer software updates'));
  591. $this->drupalLogin($update_admin_user);
  592. $system_info = array(
  593. '#all' => array(
  594. 'version' => '7.0',
  595. ),
  596. 'aaa_update_test' => array(
  597. 'project' => 'aaa_update_test',
  598. 'version' => '7.x-1.0',
  599. 'hidden' => FALSE,
  600. ),
  601. );
  602. variable_set('update_test_system_info', $system_info);
  603. $update_status = array(
  604. 'aaa_update_test' => array(
  605. 'status' => UPDATE_NOT_SECURE,
  606. ),
  607. );
  608. variable_set('update_test_update_status', $update_status);
  609. $this->refreshUpdateStatus(
  610. array(
  611. 'drupal' => '0',
  612. 'aaa_update_test' => '1_0',
  613. )
  614. );
  615. $this->drupalGet('admin/reports/updates');
  616. $this->assertRaw('<h3>' . t('Modules') . '</h3>');
  617. $this->assertText(t('Security update required!'));
  618. $this->assertRaw(l(t('AAA Update test'), 'http://example.com/project/aaa_update_test'), 'Link to aaa_update_test project appears.');
  619. // Visit the reports page again without the altering and make sure the
  620. // status is back to normal.
  621. variable_set('update_test_update_status', array());
  622. $this->drupalGet('admin/reports/updates');
  623. $this->assertRaw('<h3>' . t('Modules') . '</h3>');
  624. $this->assertNoText(t('Security update required!'));
  625. $this->assertRaw(l(t('AAA Update test'), 'http://example.com/project/aaa_update_test'), 'Link to aaa_update_test project appears.');
  626. // Turn the altering back on and visit the Update manager UI.
  627. variable_set('update_test_update_status', $update_status);
  628. $this->drupalGet('admin/modules/update');
  629. $this->assertText(t('Security update'));
  630. // Turn the altering back off and visit the Update manager UI.
  631. variable_set('update_test_update_status', array());
  632. $this->drupalGet('admin/modules/update');
  633. $this->assertNoText(t('Security update'));
  634. }
  635. }
  636. /**
  637. * Tests project upload and extract functionality.
  638. */
  639. class UpdateTestUploadCase extends UpdateTestHelper {
  640. public static function getInfo() {
  641. return array(
  642. 'name' => 'Upload and extract module functionality',
  643. 'description' => 'Tests the Update Manager module\'s upload and extraction functionality.',
  644. 'group' => 'Update',
  645. );
  646. }
  647. public function setUp() {
  648. parent::setUp('update', 'update_test');
  649. variable_set('allow_authorize_operations', TRUE);
  650. $admin_user = $this->drupalCreateUser(array('administer software updates', 'administer site configuration'));
  651. $this->drupalLogin($admin_user);
  652. }
  653. /**
  654. * Tests upload and extraction of a module.
  655. */
  656. public function testUploadModule() {
  657. // Images are not valid archives, so get one and try to install it. We
  658. // need an extra variable to store the result of drupalGetTestFiles()
  659. // since reset() takes an argument by reference and passing in a constant
  660. // emits a notice in strict mode.
  661. $imageTestFiles = $this->drupalGetTestFiles('image');
  662. $invalidArchiveFile = reset($imageTestFiles);
  663. $edit = array(
  664. 'files[project_upload]' => $invalidArchiveFile->uri,
  665. );
  666. // This also checks that the correct archive extensions are allowed.
  667. $this->drupalPost('admin/modules/install', $edit, t('Install'));
  668. $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.');
  669. // Check to ensure an existing module can't be reinstalled. Also checks that
  670. // the archive was extracted since we can't know if the module is already
  671. // installed until after extraction.
  672. $validArchiveFile = drupal_get_path('module', 'update') . '/tests/aaa_update_test.tar.gz';
  673. $edit = array(
  674. 'files[project_upload]' => $validArchiveFile,
  675. );
  676. $this->drupalPost('admin/modules/install', $edit, t('Install'));
  677. $this->assertText(t('@module_name is already installed.', array('@module_name' => 'AAA Update test')), 'Existing module was extracted and not reinstalled.');
  678. }
  679. /**
  680. * Ensures that archiver extensions are properly merged in the UI.
  681. */
  682. function testFileNameExtensionMerging() {
  683. $this->drupalGet('admin/modules/install');
  684. // Make sure the bogus extension supported by update_test.module is there.
  685. $this->assertPattern('/file extensions are supported:.*update-test-extension/', "Found 'update-test-extension' extension");
  686. // Make sure it didn't clobber the first option from core.
  687. $this->assertPattern('/file extensions are supported:.*tar/', "Found 'tar' extension");
  688. }
  689. /**
  690. * Checks the messages on update manager pages when missing a security update.
  691. */
  692. function testUpdateManagerCoreSecurityUpdateMessages() {
  693. $setting = array(
  694. '#all' => array(
  695. 'version' => '7.0',
  696. ),
  697. );
  698. variable_set('update_test_system_info', $setting);
  699. variable_set('update_fetch_url', url('update-test', array('absolute' => TRUE)));
  700. variable_set('update_test_xml_map', array('drupal' => '2-sec'));
  701. // Initialize the update status.
  702. $this->drupalGet('admin/reports/updates');
  703. // Now, make sure none of the Update manager pages have duplicate messages
  704. // about core missing a security update.
  705. $this->drupalGet('admin/modules/install');
  706. $this->assertNoText(t('There is a security update available for your version of Drupal.'));
  707. $this->drupalGet('admin/modules/update');
  708. $this->assertNoText(t('There is a security update available for your version of Drupal.'));
  709. $this->drupalGet('admin/appearance/install');
  710. $this->assertNoText(t('There is a security update available for your version of Drupal.'));
  711. $this->drupalGet('admin/appearance/update');
  712. $this->assertNoText(t('There is a security update available for your version of Drupal.'));
  713. $this->drupalGet('admin/reports/updates/install');
  714. $this->assertNoText(t('There is a security update available for your version of Drupal.'));
  715. $this->drupalGet('admin/reports/updates/update');
  716. $this->assertNoText(t('There is a security update available for your version of Drupal.'));
  717. $this->drupalGet('admin/update/ready');
  718. $this->assertNoText(t('There is a security update available for your version of Drupal.'));
  719. }
  720. }
  721. /**
  722. * Tests update functionality unrelated to the database.
  723. */
  724. class UpdateCoreUnitTestCase extends DrupalUnitTestCase {
  725. public static function getInfo() {
  726. return array(
  727. 'name' => "Unit tests",
  728. 'description' => 'Test update funcionality unrelated to the database.',
  729. 'group' => 'Update',
  730. );
  731. }
  732. function setUp() {
  733. parent::setUp('update');
  734. module_load_include('inc', 'update', 'update.fetch');
  735. }
  736. /**
  737. * Tests that _update_build_fetch_url() builds the URL correctly.
  738. */
  739. function testUpdateBuildFetchUrl() {
  740. //first test that we didn't break the trivial case
  741. $project['name'] = 'update_test';
  742. $project['project_type'] = '';
  743. $project['info']['version'] = '';
  744. $project['info']['project status url'] = 'http://www.example.com';
  745. $project['includes'] = array('module1' => 'Module 1', 'module2' => 'Module 2');
  746. $site_key = '';
  747. $expected = 'http://www.example.com/' . $project['name'] . '/' . DRUPAL_CORE_COMPATIBILITY;
  748. $url = _update_build_fetch_url($project, $site_key);
  749. $this->assertEqual($url, $expected, "'$url' when no site_key provided should be '$expected'.");
  750. //For disabled projects it shouldn't add the site key either.
  751. $site_key = 'site_key';
  752. $project['project_type'] = 'disabled';
  753. $expected = 'http://www.example.com/' . $project['name'] . '/' . DRUPAL_CORE_COMPATIBILITY;
  754. $url = _update_build_fetch_url($project, $site_key);
  755. $this->assertEqual($url, $expected, "'$url' should be '$expected' for disabled projects.");
  756. //for enabled projects, adding the site key
  757. $project['project_type'] = '';
  758. $expected = 'http://www.example.com/' . $project['name'] . '/' . DRUPAL_CORE_COMPATIBILITY;
  759. $expected .= '?site_key=site_key';
  760. $expected .= '&list=' . rawurlencode('module1,module2');
  761. $url = _update_build_fetch_url($project, $site_key);
  762. $this->assertEqual($url, $expected, "When site_key provided, '$url' should be '$expected'.");
  763. // http://drupal.org/node/1481156 test incorrect logic when URL contains
  764. // a question mark.
  765. $project['info']['project status url'] = 'http://www.example.com/?project=';
  766. $expected = 'http://www.example.com/?project=/' . $project['name'] . '/' . DRUPAL_CORE_COMPATIBILITY;
  767. $expected .= '&site_key=site_key';
  768. $expected .= '&list=' . rawurlencode('module1,module2');
  769. $url = _update_build_fetch_url($project, $site_key);
  770. $this->assertEqual($url, $expected, "When ? is present, '$url' should be '$expected'.");
  771. }
  772. }