pmUpdateStatusTest.php

  1. 8.0.x tests/pmUpdateStatusTest.php
  2. 7.x tests/pmUpdateStatusTest.php
  3. master tests/pmUpdateStatusTest.php

Prepare a codebase with modules in several update status and test pm-updatestatus.

Namespace

Unish

Classes

Namesort descending Description
pmUpdateStatus @group slow @group pm

File

tests/pmUpdateStatusTest.php
View source
  1. <?php
  2. /**
  3. * @file
  4. * Prepare a codebase with modules in several update status and test pm-updatestatus.
  5. */
  6. namespace Unish;
  7. /**
  8. * @group slow
  9. * @group pm
  10. */
  11. class pmUpdateStatus extends CommandUnishTestCase {
  12. /**
  13. * Setup the test environment.
  14. *
  15. * Here we assume that any Drupal core version parses data from Drupal's
  16. * update service the same way. We focus on testing drush functionality.
  17. *
  18. * Several drupal core versions are already tested by pmUpdateCode.
  19. *
  20. * We choose to setup a Drupal 7 environment for convenience:
  21. * - It has modules in each maintenance status
  22. * and they're not willing to change in short
  23. * - Drupal 6 will start to be unsupported at some point
  24. * - Drupal 8 still has not enough variety to cover the tests
  25. */
  26. function setUp() {
  27. $sites = $this->setUpDrupal(1, TRUE, "7.30");
  28. $options = array(
  29. 'root' => $this->webroot(),
  30. 'uri' => key($sites),
  31. 'yes' => NULL,
  32. 'cache' => NULL,
  33. 'skip' => NULL, // No FirePHP
  34. 'strict' => 0,
  35. );
  36. // Prepare a list of modules with several update statuses.
  37. $modules_dl = array();
  38. $modules_en = array();
  39. // Update available but not a security one. Cross fingers they never release a security update.
  40. $modules_dl[] = 'bad_judgement-1.0-rc38';
  41. $modules_en[] = 'bad_judgement';
  42. // Old devel release with a security update available.
  43. $modules_dl[] = 'devel-7.x-1.0-rc1';
  44. $modules_en[] = 'devel';
  45. // Installed version not supported.
  46. $modules_dl[] = 'cck-2.x-dev';
  47. $modules_en[] = 'cck';
  48. // Up to date.
  49. $modules_dl[] = 'ctools';
  50. $modules_en[] = 'ctools';
  51. // Download and enable the modules. Additionally download a module from git, so it has no version information.
  52. $this->drush('pm-download', $modules_dl, $options);
  53. $this->drush('pm-download', array('zen'), $options + array('package-handler' => 'git_drupalorg'));
  54. $modules_en[] = 'zen';
  55. // self::EXIT_ERROR because of bad_judgement.
  56. $this->drush('pm-enable', $modules_en, $options, NULL, NULL, self::EXIT_ERROR);
  57. }
  58. /**
  59. * Test several update statuses via drupal backend.
  60. */
  61. function testUpdateStatusDrupal() {
  62. $this->doTest('drupal');
  63. }
  64. /**
  65. * Test several update statuses via drush backend.
  66. */
  67. function testUpdateStatusDrush() {
  68. $this->doTest('drush');
  69. }
  70. function doTest($update_backend) {
  71. // Test several projects with a variety of statuses.
  72. $options = array(
  73. 'root' => $this->webroot(),
  74. 'uri' => key($this->getSites()),
  75. 'verbose' => NULL,
  76. 'backend' => NULL,
  77. 'update-backend' => $update_backend,
  78. );
  79. $this->drush('pm-updatestatus', array(), $options);
  80. $parsed = $this->parse_backend_output($this->getOutput());
  81. $data = $parsed['object'];
  82. $expected = array(
  83. 'drupal' => 'SECURITY UPDATE available',
  84. 'bad_judgement' => 'Update available',
  85. 'ctools' => 'Up to date',
  86. 'devel' => 'SECURITY UPDATE available',
  87. 'cck' => 'Installed version not supported',
  88. 'zen' => 'Project was not packaged by drupal.org but obtained from git. You need to enable git_deploy module',
  89. );
  90. foreach ($expected as $module => $status_msg) {
  91. $this->assertArrayHasKey($module, $data, "$module module present in pm-updatestatus output");
  92. $this->assertEquals($data[$module]['status_msg'], $status_msg, "$module status is '$status_msg'");
  93. }
  94. // Test statuses when asked for specific projects and versions.
  95. $args = array(
  96. 'bad_judgement-1.0-rc38',
  97. 'ctools-0.0',
  98. 'devel-1.5',
  99. 'foo',
  100. );
  101. $this->drush('pm-updatestatus', $args, $options);
  102. $parsed = $this->parse_backend_output($this->getOutput());
  103. $data = $parsed['object'];
  104. $expected = array(
  105. 'bad_judgement' => 'Specified version already installed',
  106. 'ctools' => 'Specified version not found',
  107. 'devel' => 'Specified version available',
  108. 'foo' => 'Specified project not found',
  109. );
  110. foreach ($expected as $module => $status_msg) {
  111. $this->assertArrayHasKey($module, $data, "$module module present in pm-updatestatus output");
  112. $this->assertEquals($data[$module]['status_msg'], $status_msg, "$module status is '$status_msg'");
  113. }
  114. // We don't expect any output for other projects than the provided ones.
  115. $not_expected = array(
  116. 'drupal',
  117. 'cck',
  118. 'zen',
  119. );
  120. foreach ($not_expected as $module) {
  121. $this->assertArrayNotHasKey($module, $data, "$module module not present in pm-updatestatus output");
  122. }
  123. // Test --security-only.
  124. $this->drush('pm-updatestatus', array(), $options + array('security-only' => NULL));
  125. $parsed = $this->parse_backend_output($this->getOutput());
  126. $data = $parsed['object'];
  127. $expected = array(
  128. 'drupal' => 'SECURITY UPDATE available',
  129. 'devel' => 'SECURITY UPDATE available',
  130. );
  131. foreach ($expected as $module => $status_msg) {
  132. $this->assertArrayHasKey($module, $data, "$module module present in pm-updatestatus output");
  133. $this->assertEquals($data[$module]['status_msg'], $status_msg, "$module status is '$status_msg'");
  134. }
  135. // We don't expect any output for projects without security updates.
  136. $not_expected = array(
  137. 'bad_judgement',
  138. 'ctools',
  139. 'cck',
  140. 'zen',
  141. );
  142. foreach ($not_expected as $module) {
  143. $this->assertArrayNotHasKey($module, $data, "$module module not present in pm-updatestatus output");
  144. }
  145. // Test --check-disabled.
  146. $dis_options = array(
  147. 'root' => $this->webroot(),
  148. 'uri' => key($this->getSites()),
  149. 'yes' => NULL,
  150. );
  151. $this->drush('pm-disable', array('devel'), $dis_options);
  152. $this->drush('pm-updatestatus', array(), $options + array('check-disabled' => 1));
  153. $parsed = $this->parse_backend_output($this->getOutput());
  154. $data = $parsed['object'];
  155. $this->assertArrayHasKey('devel', $data, "devel module present in pm-updatestatus output");
  156. $this->drush('pm-updatestatus', array(), $options + array('check-disabled' => 0));
  157. $parsed = $this->parse_backend_output($this->getOutput());
  158. $data = $parsed['object'];
  159. $this->assertArrayNotHasKey('devel', $data, "devel module not present in pm-updatestatus output");
  160. }
  161. }