pmUpdateCodeTest.php

  1. 8.0.x tests/pmUpdateCodeTest.php
  2. 6.x tests/pmUpdateCodeTest.php
  3. 7.x tests/pmUpdateCodeTest.php
  4. 4.x tests/pmUpdateCodeTest.php
  5. 5.x tests/pmUpdateCodeTest.php
  6. master tests/pmUpdateCodeTest.php

Prepare a codebase and upgrade it in several stages, exercising updatecode's filters. @todo test security-only once one of these modules or core gets a security release.

Classes

Namesort descending Description
pmUpdateCode @group slow @group pm

File

tests/pmUpdateCodeTest.php
View source
  1. <?php
  2. /**
  3. * @file
  4. * Prepare a codebase and upgrade it in several stages, exercising
  5. * updatecode's filters.
  6. * @todo test security-only once one of these modules or core gets a security release.
  7. */
  8. /**
  9. * @group slow
  10. * @group pm
  11. */
  12. class pmUpdateCode extends Drush_CommandTestCase {
  13. /*
  14. * An array of modules to be downloaded and enabled.
  15. */
  16. public $modules;
  17. /**
  18. * Download old core and older contrib releases which will always need updating.
  19. */
  20. public function setUp() {
  21. if (UNISH_DRUPAL_MAJOR_VERSION >= 8) {
  22. $core = '8.0-alpha6';
  23. $modules_str = 'instagram_block-8.x-1.0,honeypot-8.x-1.14-beta5';
  24. $this->modules = array('block', 'instagram_block', 'honeypot');
  25. }
  26. elseif (UNISH_DRUPAL_MAJOR_VERSION == 7) {
  27. $core = '7.0-rc3';
  28. $modules_str = 'devel-7.x-1.0-rc1,webform-7.x-3.4-beta1';
  29. $this->modules = array('menu', 'devel', 'webform');
  30. }
  31. else {
  32. $core = '6.28';
  33. $modules_str = 'devel-6.x-1.26,webform-6.x-3.18';
  34. $this->modules = array('menu', 'devel', 'webform');
  35. }
  36. $sites = $this->setUpDrupal(1, TRUE, $core);
  37. $options = array(
  38. 'root' => $this->webroot(),
  39. 'uri' => key($sites),
  40. 'yes' => NULL,
  41. 'quiet' => NULL,
  42. 'cache' => NULL,
  43. 'skip' => NULL, // No FirePHP
  44. 'strict' => 0, // invoke from script: do not verify options
  45. );
  46. $this->drush('pm-download', array($modules_str), $options);
  47. $this->drush('pm-enable', $this->modules, $options);
  48. }
  49. function testUpdateCode() {
  50. $first = $this->modules[1];
  51. $second = $this->modules[2];
  52. $options = array(
  53. 'root' => $this->webroot(),
  54. 'uri' => key($this->sites), // Have to access class property since $sites in in setUp().
  55. 'yes' => NULL,
  56. 'backup-dir' => UNISH_SANDBOX . '/backups',
  57. 'cache' => NULL,
  58. 'check-updatedb' => 0,
  59. 'strict' => 0,
  60. );
  61. // Try to upgrade a specific module.
  62. $this->drush('pm-updatecode', array($first), $options + array());
  63. // Assure that first was upgraded and second was not.
  64. $this->drush('pm-updatestatus', array(), $options + array());
  65. $all = $this->getOutput();
  66. $this->assertNotContains($first, $all);
  67. $this->assertContains($second, $all);
  68. // Lock second, and update core.
  69. $this->drush('pm-updatecode', array(), $options + array('lock' => $second));
  70. $list = $this->getOutputAsList(); // For debugging.
  71. $this->drush('pm-updatestatus', array(), $options + array());
  72. $all = $this->getOutput();
  73. $this->assertNotContains('drupal', $all, 'Core was updated');
  74. $this->assertContains($second, $all, 'Second was skipped.');
  75. // Unlock second, update, and check.
  76. $this->drush('pm-updatecode', array(), $options + array('unlock' => $second, 'no-backup' => NULL));
  77. $list = $this->getOutputAsList();
  78. $this->drush('pm-updatestatus', array(), $options + array());
  79. $all = $this->getOutput();
  80. $this->assertNotContains($second, $all, 'Second was updated');
  81. // Verify that we keep backups as instructed.
  82. $backup_dir = UNISH_SANDBOX . '/backups';
  83. $Directory = new RecursiveDirectoryIterator($backup_dir);
  84. $Iterator = new RecursiveIteratorIterator($Directory);
  85. $found = FALSE;
  86. foreach ($Iterator as $item) {
  87. if (basename($item) == $first . '.module') {
  88. $found = TRUE;
  89. break;
  90. }
  91. }
  92. $this->assertTrue($found, 'Backup exists and contains the first module.');
  93. $Iterator = new RecursiveIteratorIterator($Directory);
  94. $found = FALSE;
  95. foreach ($Iterator as $item) {
  96. if (basename($item) == $second . '.module') {
  97. $found = TRUE;
  98. break;
  99. }
  100. }
  101. $this->assertFalse($found, 'Backup exists and does not contain the second module.');
  102. }
  103. }