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. /**
  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.0-beta2';
  23. $modules_str = 'unish-8.x-1.2,honeypot-8.x-1.18-beta3';
  24. $this->modules = array('block', 'unish', '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,
  45. );
  46. $this->drush('pm-download', array($modules_str), $options);
  47. $this->drush('pm-enable', $this->modules, $options);
  48. }
  49. function testUpdateCode() {
  50. if (UNISH_DRUPAL_MAJOR_VERSION < 7) {
  51. $this->markTestSkipped("pm-update does not work once Drupal core reaches EOL.");
  52. }
  53. $extension = UNISH_DRUPAL_MAJOR_VERSION == 8 ? '.info.yml' : '.info';
  54. $first = $this->modules[1];
  55. $second = $this->modules[2];
  56. $options = array(
  57. 'root' => $this->webroot(),
  58. 'uri' => key($this->getSites()),
  59. 'yes' => NULL,
  60. 'backup-dir' => UNISH_SANDBOX . '/backups',
  61. 'cache' => NULL,
  62. 'check-updatedb' => 0,
  63. // Needed in order to get 'Up to date' in the return value of updatestatus. See pm_project_filter().
  64. 'verbose' => NULL,
  65. 'strict' => 0,
  66. );
  67. // Upgrade a specific module.
  68. $this->drush('pm-updatecode', array($first), $options + array());
  69. // Assure that first was upgraded and second was not.
  70. $this->drush('pm-updatestatus', array(), $options + array('format' => 'json'));
  71. $all = $this->getOutputFromJSON();
  72. $this->assertEquals($all->$first->existing_version, $all->$first->candidate_version);
  73. $this->assertNotEquals($all->$second->existing_version, $all->$second->candidate_version);
  74. // Lock second, and update core.
  75. $this->drush('pm-updatecode', array(), $options + array('lock' => $second));
  76. $list = $this->getOutputAsList(); // For debugging.
  77. $this->drush('pm-updatestatus', array(), $options + array('format' => 'json'));
  78. $all = $this->getOutputFromJSON();
  79. $this->assertEquals($all->drupal->existing_version, $all->drupal->candidate_version);
  80. $this->assertNotEquals($all->$second->existing_version, $all->$second->candidate_version);
  81. // Unlock second, update, and check.
  82. $this->drush('pm-updatecode', array(), $options + array('unlock' => $second, 'no-backup' => NULL));
  83. $list = $this->getOutputAsList();
  84. $this->drush('pm-updatestatus', array(), $options + array('format' => 'json'));
  85. $all = $this->getOutputFromJSON();
  86. $this->assertEquals($all->$second->existing_version, $all->$second->candidate_version);
  87. // Verify that we keep backups as instructed.
  88. $backup_dir = UNISH_SANDBOX . '/backups';
  89. $Directory = new \RecursiveDirectoryIterator($backup_dir);
  90. $Iterator = new \RecursiveIteratorIterator($Directory);
  91. $found = FALSE;
  92. foreach ($Iterator as $item) {
  93. if (basename($item) == $first . $extension) {
  94. $found = TRUE;
  95. break;
  96. }
  97. }
  98. $this->assertTrue($found, 'Backup exists and contains the first module.');
  99. $Iterator = new \RecursiveIteratorIterator($Directory);
  100. $found = FALSE;
  101. foreach ($Iterator as $item) {
  102. if (basename($item) == $second . '.module') {
  103. $found = TRUE;
  104. break;
  105. }
  106. }
  107. $this->assertFalse($found, 'Backup exists and does not contain the second module.');
  108. }
  109. }