update.test 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  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. }
  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'), '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'), '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'), 'Link to bbb_update_test project appears.');
  375. $this->assertRaw(l(t('CCC Update test'), 'http://example.com/project/ccc_update_test'), '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'), 'Link to the Update test base theme project appears.');
  422. }
  423. /**
  424. * Tests that the admin theme is always notified about security updates.
  425. */
  426. function testUpdateAdminThemeSecurityUpdate() {
  427. // Disable the admin theme.
  428. db_update('system')
  429. ->fields(array('status' => 0))
  430. ->condition('type', 'theme')
  431. ->condition('name', 'update_test_%', 'LIKE')
  432. ->execute();
  433. variable_set('admin_theme', 'update_test_admintheme');
  434. // Define the initial state for core and the themes.
  435. $system_info = array(
  436. '#all' => array(
  437. 'version' => '7.0',
  438. ),
  439. 'update_test_admintheme' => array(
  440. 'project' => 'update_test_admintheme',
  441. 'version' => '7.x-1.0',
  442. 'hidden' => FALSE,
  443. ),
  444. 'update_test_basetheme' => array(
  445. 'project' => 'update_test_basetheme',
  446. 'version' => '7.x-1.1',
  447. 'hidden' => FALSE,
  448. ),
  449. 'update_test_subtheme' => array(
  450. 'project' => 'update_test_subtheme',
  451. 'version' => '7.x-1.0',
  452. 'hidden' => FALSE,
  453. ),
  454. );
  455. variable_set('update_test_system_info', $system_info);
  456. variable_set('update_check_disabled', FALSE);
  457. $xml_mapping = array(
  458. // This is enough because we don't check the update status of the admin
  459. // theme. We want to check that the admin theme is included in the list.
  460. 'drupal' => '0',
  461. );
  462. $this->refreshUpdateStatus($xml_mapping);
  463. // The admin theme is displayed even if it's disabled.
  464. $this->assertText('update_test_admintheme', "The admin theme is checked for update even if it's disabled");
  465. // The other disabled themes are not displayed.
  466. $this->assertNoText('update_test_basetheme', 'Disabled theme is not checked for update in the list.');
  467. $this->assertNoText('update_test_subtheme', 'Disabled theme is not checked for update in the list.');
  468. }
  469. /**
  470. * Tests that disabled themes are only shown when desired.
  471. */
  472. function testUpdateShowDisabledThemes() {
  473. // Make sure all the update_test_* themes are disabled.
  474. db_update('system')
  475. ->fields(array('status' => 0))
  476. ->condition('type', 'theme')
  477. ->condition('name', 'update_test_%', 'LIKE')
  478. ->execute();
  479. // Define the initial state for core and the test contrib themes.
  480. $system_info = array(
  481. // We want core to be version 7.0.
  482. '#all' => array(
  483. 'version' => '7.0',
  484. ),
  485. // The update_test_basetheme should be visible and up to date.
  486. 'update_test_basetheme' => array(
  487. 'project' => 'update_test_basetheme',
  488. 'version' => '7.x-1.1',
  489. 'hidden' => FALSE,
  490. ),
  491. // The update_test_subtheme should be visible and up to date.
  492. 'update_test_subtheme' => array(
  493. 'project' => 'update_test_subtheme',
  494. 'version' => '7.x-1.0',
  495. 'hidden' => FALSE,
  496. ),
  497. );
  498. // When there are contributed modules in the site's file system, the
  499. // total number of attempts made in the test may exceed the default value
  500. // of update_max_fetch_attempts. Therefore this variable is set very high
  501. // to avoid test failures in those cases.
  502. variable_set('update_max_fetch_attempts', 99999);
  503. variable_set('update_test_system_info', $system_info);
  504. $xml_mapping = array(
  505. 'drupal' => '0',
  506. 'update_test_subtheme' => '1_0',
  507. 'update_test_basetheme' => '1_1-sec',
  508. );
  509. $base_theme_project_link = l(t('Update test base theme'), 'http://example.com/project/update_test_basetheme');
  510. $sub_theme_project_link = l(t('Update test subtheme'), 'http://example.com/project/update_test_subtheme');
  511. foreach (array(TRUE, FALSE) as $check_disabled) {
  512. variable_set('update_check_disabled', $check_disabled);
  513. $this->refreshUpdateStatus($xml_mapping);
  514. // In neither case should we see the "Themes" heading for enabled themes.
  515. $this->assertNoText(t('Themes'));
  516. if ($check_disabled) {
  517. $this->assertText(t('Disabled themes'));
  518. $this->assertRaw($base_theme_project_link, 'Link to the Update test base theme project appears.');
  519. $this->assertRaw($sub_theme_project_link, 'Link to the Update test subtheme project appears.');
  520. }
  521. else {
  522. $this->assertNoText(t('Disabled themes'));
  523. $this->assertNoRaw($base_theme_project_link, 'Link to the Update test base theme project does not appear.');
  524. $this->assertNoRaw($sub_theme_project_link, 'Link to the Update test subtheme project does not appear.');
  525. }
  526. }
  527. }
  528. /**
  529. * Makes sure that if we fetch from a broken URL, sane things happen.
  530. */
  531. function testUpdateBrokenFetchURL() {
  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. 'bbb_update_test' => array(
  542. 'project' => 'bbb_update_test',
  543. 'version' => '7.x-1.0',
  544. 'hidden' => FALSE,
  545. ),
  546. 'ccc_update_test' => array(
  547. 'project' => 'ccc_update_test',
  548. 'version' => '7.x-1.0',
  549. 'hidden' => FALSE,
  550. ),
  551. );
  552. variable_set('update_test_system_info', $system_info);
  553. $xml_mapping = array(
  554. 'drupal' => '0',
  555. 'aaa_update_test' => '1_0',
  556. 'bbb_update_test' => 'does-not-exist',
  557. 'ccc_update_test' => '1_0',
  558. );
  559. $this->refreshUpdateStatus($xml_mapping);
  560. $this->assertText(t('Up to date'));
  561. // We're expecting the report to say most projects are up to date, so we
  562. // hope that 'Up to date' is not unique.
  563. $this->assertNoUniqueText(t('Up to date'));
  564. // It should say we failed to get data, not that we're missing an update.
  565. $this->assertNoText(t('Update available'));
  566. // We need to check that this string is found as part of a project row,
  567. // not just in the "Failed to get available update data for ..." message
  568. // at the top of the page.
  569. $this->assertRaw('<div class="version-status">' . t('Failed to get available update data'));
  570. // We should see the output messages from fetching manually.
  571. $this->assertUniqueText(t('Checked available update data for 3 projects.'));
  572. $this->assertUniqueText(t('Failed to get available update data for one project.'));
  573. // The other two should be listed as projects.
  574. $this->assertRaw(l(t('AAA Update test'), 'http://example.com/project/aaa_update_test'), 'Link to aaa_update_test project appears.');
  575. $this->assertNoRaw(l(t('BBB Update test'), 'http://example.com/project/bbb_update_test'), 'Link to bbb_update_test project does not appear.');
  576. $this->assertRaw(l(t('CCC Update test'), 'http://example.com/project/ccc_update_test'), 'Link to bbb_update_test project appears.');
  577. }
  578. /**
  579. * Checks that hook_update_status_alter() works to change a status.
  580. *
  581. * We provide the same external data as if aaa_update_test 7.x-1.0 were
  582. * installed and that was the latest release. Then we use
  583. * hook_update_status_alter() to try to mark this as missing a security
  584. * update, then assert if we see the appropriate warnings on the right pages.
  585. */
  586. function testHookUpdateStatusAlter() {
  587. variable_set('allow_authorize_operations', TRUE);
  588. $update_admin_user = $this->drupalCreateUser(array('administer site configuration', 'administer software updates'));
  589. $this->drupalLogin($update_admin_user);
  590. $system_info = array(
  591. '#all' => array(
  592. 'version' => '7.0',
  593. ),
  594. 'aaa_update_test' => array(
  595. 'project' => 'aaa_update_test',
  596. 'version' => '7.x-1.0',
  597. 'hidden' => FALSE,
  598. ),
  599. );
  600. variable_set('update_test_system_info', $system_info);
  601. $update_status = array(
  602. 'aaa_update_test' => array(
  603. 'status' => UPDATE_NOT_SECURE,
  604. ),
  605. );
  606. variable_set('update_test_update_status', $update_status);
  607. $this->refreshUpdateStatus(
  608. array(
  609. 'drupal' => '0',
  610. 'aaa_update_test' => '1_0',
  611. )
  612. );
  613. $this->drupalGet('admin/reports/updates');
  614. $this->assertRaw('<h3>' . t('Modules') . '</h3>');
  615. $this->assertText(t('Security update required!'));
  616. $this->assertRaw(l(t('AAA Update test'), 'http://example.com/project/aaa_update_test'), 'Link to aaa_update_test project appears.');
  617. // Visit the reports page again without the altering and make sure the
  618. // status is back to normal.
  619. variable_set('update_test_update_status', array());
  620. $this->drupalGet('admin/reports/updates');
  621. $this->assertRaw('<h3>' . t('Modules') . '</h3>');
  622. $this->assertNoText(t('Security update required!'));
  623. $this->assertRaw(l(t('AAA Update test'), 'http://example.com/project/aaa_update_test'), 'Link to aaa_update_test project appears.');
  624. // Turn the altering back on and visit the Update manager UI.
  625. variable_set('update_test_update_status', $update_status);
  626. $this->drupalGet('admin/modules/update');
  627. $this->assertText(t('Security update'));
  628. // Turn the altering back off and visit the Update manager UI.
  629. variable_set('update_test_update_status', array());
  630. $this->drupalGet('admin/modules/update');
  631. $this->assertNoText(t('Security update'));
  632. }
  633. }
  634. /**
  635. * Tests project upload and extract functionality.
  636. */
  637. class UpdateTestUploadCase extends UpdateTestHelper {
  638. public static function getInfo() {
  639. return array(
  640. 'name' => 'Upload and extract module functionality',
  641. 'description' => 'Tests the Update Manager module\'s upload and extraction functionality.',
  642. 'group' => 'Update',
  643. );
  644. }
  645. public function setUp() {
  646. parent::setUp('update', 'update_test');
  647. variable_set('allow_authorize_operations', TRUE);
  648. $admin_user = $this->drupalCreateUser(array('administer software updates', 'administer site configuration'));
  649. $this->drupalLogin($admin_user);
  650. }
  651. /**
  652. * Tests upload and extraction of a module.
  653. */
  654. public function testUploadModule() {
  655. // Images are not valid archives, so get one and try to install it. We
  656. // need an extra variable to store the result of drupalGetTestFiles()
  657. // since reset() takes an argument by reference and passing in a constant
  658. // emits a notice in strict mode.
  659. $imageTestFiles = $this->drupalGetTestFiles('image');
  660. $invalidArchiveFile = reset($imageTestFiles);
  661. $edit = array(
  662. 'files[project_upload]' => $invalidArchiveFile->uri,
  663. );
  664. // This also checks that the correct archive extensions are allowed.
  665. $this->drupalPost('admin/modules/install', $edit, t('Install'));
  666. $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.');
  667. // Check to ensure an existing module can't be reinstalled. Also checks that
  668. // the archive was extracted since we can't know if the module is already
  669. // installed until after extraction.
  670. $validArchiveFile = drupal_get_path('module', 'update') . '/tests/aaa_update_test.tar.gz';
  671. $edit = array(
  672. 'files[project_upload]' => $validArchiveFile,
  673. );
  674. $this->drupalPost('admin/modules/install', $edit, t('Install'));
  675. $this->assertText(t('@module_name is already installed.', array('@module_name' => 'AAA Update test')), 'Existing module was extracted and not reinstalled.');
  676. }
  677. /**
  678. * Ensures that archiver extensions are properly merged in the UI.
  679. */
  680. function testFileNameExtensionMerging() {
  681. $this->drupalGet('admin/modules/install');
  682. // Make sure the bogus extension supported by update_test.module is there.
  683. $this->assertPattern('/file extensions are supported:.*update-test-extension/', "Found 'update-test-extension' extension");
  684. // Make sure it didn't clobber the first option from core.
  685. $this->assertPattern('/file extensions are supported:.*tar/', "Found 'tar' extension");
  686. }
  687. /**
  688. * Checks the messages on update manager pages when missing a security update.
  689. */
  690. function testUpdateManagerCoreSecurityUpdateMessages() {
  691. $setting = array(
  692. '#all' => array(
  693. 'version' => '7.0',
  694. ),
  695. );
  696. variable_set('update_test_system_info', $setting);
  697. variable_set('update_fetch_url', url('update-test', array('absolute' => TRUE)));
  698. variable_set('update_test_xml_map', array('drupal' => '2-sec'));
  699. // Initialize the update status.
  700. $this->drupalGet('admin/reports/updates');
  701. // Now, make sure none of the Update manager pages have duplicate messages
  702. // about core missing a security update.
  703. $this->drupalGet('admin/modules/install');
  704. $this->assertNoText(t('There is a security update available for your version of Drupal.'));
  705. $this->drupalGet('admin/modules/update');
  706. $this->assertNoText(t('There is a security update available for your version of Drupal.'));
  707. $this->drupalGet('admin/appearance/install');
  708. $this->assertNoText(t('There is a security update available for your version of Drupal.'));
  709. $this->drupalGet('admin/appearance/update');
  710. $this->assertNoText(t('There is a security update available for your version of Drupal.'));
  711. $this->drupalGet('admin/reports/updates/install');
  712. $this->assertNoText(t('There is a security update available for your version of Drupal.'));
  713. $this->drupalGet('admin/reports/updates/update');
  714. $this->assertNoText(t('There is a security update available for your version of Drupal.'));
  715. $this->drupalGet('admin/update/ready');
  716. $this->assertNoText(t('There is a security update available for your version of Drupal.'));
  717. }
  718. }
  719. /**
  720. * Tests update functionality unrelated to the database.
  721. */
  722. class UpdateCoreUnitTestCase extends DrupalUnitTestCase {
  723. public static function getInfo() {
  724. return array(
  725. 'name' => "Unit tests",
  726. 'description' => 'Test update funcionality unrelated to the database.',
  727. 'group' => 'Update',
  728. );
  729. }
  730. function setUp() {
  731. parent::setUp('update');
  732. module_load_include('inc', 'update', 'update.fetch');
  733. }
  734. /**
  735. * Tests that _update_build_fetch_url() builds the URL correctly.
  736. */
  737. function testUpdateBuildFetchUrl() {
  738. //first test that we didn't break the trivial case
  739. $project['name'] = 'update_test';
  740. $project['project_type'] = '';
  741. $project['info']['version'] = '';
  742. $project['info']['project status url'] = 'http://www.example.com';
  743. $project['includes'] = array('module1' => 'Module 1', 'module2' => 'Module 2');
  744. $site_key = '';
  745. $expected = 'http://www.example.com/' . $project['name'] . '/' . DRUPAL_CORE_COMPATIBILITY;
  746. $url = _update_build_fetch_url($project, $site_key);
  747. $this->assertEqual($url, $expected, "'$url' when no site_key provided should be '$expected'.");
  748. //For disabled projects it shouldn't add the site key either.
  749. $site_key = 'site_key';
  750. $project['project_type'] = 'disabled';
  751. $expected = 'http://www.example.com/' . $project['name'] . '/' . DRUPAL_CORE_COMPATIBILITY;
  752. $url = _update_build_fetch_url($project, $site_key);
  753. $this->assertEqual($url, $expected, "'$url' should be '$expected' for disabled projects.");
  754. //for enabled projects, adding the site key
  755. $project['project_type'] = '';
  756. $expected = 'http://www.example.com/' . $project['name'] . '/' . DRUPAL_CORE_COMPATIBILITY;
  757. $expected .= '?site_key=site_key';
  758. $expected .= '&list=' . rawurlencode('module1,module2');
  759. $url = _update_build_fetch_url($project, $site_key);
  760. $this->assertEqual($url, $expected, "When site_key provided, '$url' should be '$expected'.");
  761. // http://drupal.org/node/1481156 test incorrect logic when URL contains
  762. // a question mark.
  763. $project['info']['project status url'] = 'http://www.example.com/?project=';
  764. $expected = 'http://www.example.com/?project=/' . $project['name'] . '/' . DRUPAL_CORE_COMPATIBILITY;
  765. $expected .= '&site_key=site_key';
  766. $expected .= '&list=' . rawurlencode('module1,module2');
  767. $url = _update_build_fetch_url($project, $site_key);
  768. $this->assertEqual($url, $expected, "When ? is present, '$url' should be '$expected'.");
  769. }
  770. }