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.

Namespace

Unish

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. */
  7. namespace Unish;
  8. /**
  9. * @group slow
  10. * @group pm
  11. */
  12. class pmUpdateCode extends CommandUnishTestCase {
  13. /*
  14. * An array of modules to be downloaded and enabled.
  15. */
  16. public $modules;
  17. private function getPreviousStable($project) {
  18. // Call drush pm-releases and get the output
  19. $this->drush('pm-releases', array($project), array('all' => NULL, 'fields' => 'Release'));
  20. $list = $this->getOutputAsList();
  21. // Line 0 is "Release"
  22. // Line 1 is "...-dev"
  23. // Line 2 is current best release
  24. // Line 3 is the previous release
  25. return trim($list[3]);
  26. }
  27. /**
  28. * Download old core and older contrib releases which will always need updating.
  29. */
  30. public function setUp() {
  31. if (UNISH_DRUPAL_MAJOR_VERSION >= 8) {
  32. // Make sure that we can still update from the previous release
  33. // to the current release.
  34. $core = $this->getPreviousStable("drupal-8");
  35. $modules_str = 'unish-8.x-1.2,honeypot-8.x-1.19-beta14';
  36. $this->modules = array('block', 'unish', 'honeypot');
  37. }
  38. elseif (UNISH_DRUPAL_MAJOR_VERSION == 7) {
  39. $core = '7.0-rc3';
  40. $modules_str = 'devel-7.x-1.0-rc1,webform-7.x-3.4-beta1';
  41. $this->modules = array('menu', 'devel', 'webform');
  42. }
  43. else {
  44. $core = '6.28';
  45. $modules_str = 'devel-6.x-1.26,webform-6.x-3.18';
  46. $this->modules = array('menu', 'devel', 'webform');
  47. }
  48. $sites = $this->setUpDrupal(1, TRUE, $core);
  49. $options = array(
  50. 'root' => $this->webroot(),
  51. 'uri' => key($sites),
  52. 'yes' => NULL,
  53. 'quiet' => NULL,
  54. 'cache' => NULL,
  55. 'skip' => NULL, // No FirePHP
  56. 'strict' => 0,
  57. );
  58. $this->drush('pm-download', array($modules_str), $options);
  59. $this->drush('pm-enable', $this->modules, $options);
  60. }
  61. function testUpdateCode() {
  62. $extension = UNISH_DRUPAL_MAJOR_VERSION == 8 ? '.info.yml' : '.info';
  63. $first = $this->modules[1];
  64. $second = $this->modules[2];
  65. $options = array(
  66. 'root' => $this->webroot(),
  67. 'uri' => key($this->getSites()),
  68. 'yes' => NULL,
  69. 'backup-dir' => UNISH_SANDBOX . '/backups',
  70. 'cache' => NULL,
  71. 'check-updatedb' => 0,
  72. // Needed in order to get 'Up to date' in the return value of updatestatus. See pm_project_filter().
  73. 'verbose' => NULL,
  74. 'strict' => 0,
  75. );
  76. // Upgrade a specific module.
  77. $this->drush('pm-updatecode', array($first), $options + array());
  78. // Assure that first was upgraded and second was not.
  79. $this->drush('pm-updatestatus', array(), $options + array('format' => 'json'));
  80. $all = $this->getOutputFromJSON();
  81. $this->assertEquals($all->$first->existing_version, $all->$first->candidate_version);
  82. $this->assertNotEquals($all->$second->existing_version, $all->$second->candidate_version);
  83. // Lock second, and update core.
  84. $this->drush('pm-updatecode', array(), $options + array('lock' => $second));
  85. $list = $this->getOutputAsList(); // For debugging.
  86. $this->drush('pm-updatestatus', array(), $options + array('format' => 'json'));
  87. $all = $this->getOutputFromJSON();
  88. $this->assertEquals($all->drupal->existing_version, $all->drupal->candidate_version);
  89. $this->assertNotEquals($all->$second->existing_version, $all->$second->candidate_version);
  90. // Unlock second, update, and check.
  91. $this->drush('pm-updatecode', array(), $options + array('unlock' => $second, 'no-backup' => NULL));
  92. $list = $this->getOutputAsList();
  93. $this->drush('pm-updatestatus', array(), $options + array('format' => 'json'));
  94. $all = $this->getOutputFromJSON();
  95. $this->assertEquals($all->$second->existing_version, $all->$second->candidate_version);
  96. // Verify that we keep backups as instructed.
  97. $backup_dir = UNISH_SANDBOX . '/backups';
  98. $Directory = new \RecursiveDirectoryIterator($backup_dir);
  99. $Iterator = new \RecursiveIteratorIterator($Directory);
  100. $found = FALSE;
  101. foreach ($Iterator as $item) {
  102. if (basename($item) == $first . $extension) {
  103. $found = TRUE;
  104. break;
  105. }
  106. }
  107. $this->assertTrue($found, 'Backup exists and contains the first module.');
  108. $Iterator = new \RecursiveIteratorIterator($Directory);
  109. $found = FALSE;
  110. foreach ($Iterator as $item) {
  111. if (basename($item) == $second . '.module') {
  112. $found = TRUE;
  113. break;
  114. }
  115. }
  116. $this->assertFalse($found, 'Backup exists and does not contain the second module.');
  117. }
  118. }