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