pmRequestUnitTest.php

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

Tests for pm parsers.

Namespace

Unish

Classes

Namesort descending Description
pmRequestUnitCase pm testing

File

tests/pmRequestUnitTest.php
View source
  1. <?php
  2. /**
  3. * @file
  4. * Tests for pm parsers.
  5. */
  6. namespace Unish;
  7. /**
  8. * pm testing
  9. *
  10. * @group pm
  11. */
  12. class pmRequestUnitCase extends UnitUnishTestCase {
  13. /**
  14. * Tests for pm_parse_version() with semantic versioning.
  15. */
  16. public function testVersionParserCoreSemVer() {
  17. _drush_add_commandfiles(array(DRUSH_BASE_PATH . '/commands/pm'));
  18. drush_set_option('default-major', UNISH_DRUPAL_MAJOR_VERSION);
  19. $version = '8.0.0-beta2';
  20. $version_parts = pm_parse_version($version, TRUE);
  21. $this->assertEquals('8.0.0-beta2', $version_parts['version']);
  22. $this->assertEquals('8.x', $version_parts['drupal_version']);
  23. $this->assertEquals('8', $version_parts['version_major']);
  24. $this->assertEquals('0', $version_parts['version_minor']);
  25. $this->assertEquals('0', $version_parts['version_patch']);
  26. $this->assertEquals('beta2', $version_parts['version_extra']);
  27. $this->assertEquals('8.0.0-beta2', $version_parts['project_version']);
  28. $version = '8.0.x-dev';
  29. $version_parts = pm_parse_version($version, TRUE);
  30. $this->assertEquals('8.0.x-dev', $version_parts['version']);
  31. $this->assertEquals('8.x', $version_parts['drupal_version']);
  32. $this->assertEquals('8', $version_parts['version_major']);
  33. $this->assertEquals('0', $version_parts['version_minor']);
  34. $this->assertEquals('', $version_parts['version_patch']);
  35. $this->assertEquals('dev', $version_parts['version_extra']);
  36. $this->assertEquals('8.0.x-dev', $version_parts['project_version']);
  37. $version = '8.0.0-beta3+252-dev';
  38. $version_parts = pm_parse_version($version, TRUE);
  39. $this->assertEquals('8.0.0-beta3+252-dev', $version_parts['version']);
  40. $this->assertEquals('8.x', $version_parts['drupal_version']);
  41. $this->assertEquals('8', $version_parts['version_major']);
  42. $this->assertEquals('0', $version_parts['version_minor']);
  43. $this->assertEquals('0', $version_parts['version_patch']);
  44. $this->assertEquals('beta3', $version_parts['version_extra']);
  45. $this->assertEquals('252', $version_parts['version_offset']);
  46. $this->assertEquals('8.0.0-beta3+252-dev', $version_parts['project_version']);
  47. $version = '8.1.x';
  48. $version_parts = pm_parse_version($version, TRUE);
  49. $this->assertEquals('8.1.x-dev', $version_parts['version']);
  50. $this->assertEquals('8.x', $version_parts['drupal_version']);
  51. $this->assertEquals('8', $version_parts['version_major']);
  52. $this->assertEquals('1', $version_parts['version_minor']);
  53. $this->assertEquals('', $version_parts['version_patch']);
  54. $this->assertEquals('dev', $version_parts['version_extra']);
  55. $this->assertEquals('8.1.x-dev', $version_parts['project_version']);
  56. $version = '8.0.1';
  57. $version_parts = pm_parse_version($version, TRUE);
  58. $this->assertEquals('8.0.1', $version_parts['version']);
  59. $this->assertEquals('8.x', $version_parts['drupal_version']);
  60. $this->assertEquals('8', $version_parts['version_major']);
  61. $this->assertEquals('0', $version_parts['version_minor']);
  62. $this->assertEquals('1', $version_parts['version_patch']);
  63. $this->assertEquals('', $version_parts['version_extra']);
  64. $this->assertEquals('8.0.1', $version_parts['project_version']);
  65. }
  66. /**
  67. * Tests for pm_parse_version() with drupal version scheme for core.
  68. */
  69. public function testVersionParserCore() {
  70. _drush_add_commandfiles(array(DRUSH_BASE_PATH . '/commands/pm'));
  71. drush_set_option('default-major', UNISH_DRUPAL_MAJOR_VERSION);
  72. $version = '';
  73. $version_parts = pm_parse_version($version, TRUE);
  74. $this->assertEquals('', $version_parts['version']);
  75. $this->assertEquals(UNISH_DRUPAL_MAJOR_VERSION . '.x', $version_parts['drupal_version']);
  76. $this->assertEquals(UNISH_DRUPAL_MAJOR_VERSION, $version_parts['version_major']);
  77. $this->assertEquals('', $version_parts['version_minor']);
  78. $this->assertEquals('', $version_parts['version_patch']);
  79. $this->assertEquals('', $version_parts['version_extra']);
  80. $this->assertEquals('', $version_parts['project_version']);
  81. // We use version 5 in these tests to avoid false positives from
  82. // pm_parse_version(), in case it was picking drush's default-major.
  83. $version = '5';
  84. $version_parts = pm_parse_version($version, TRUE);
  85. $this->assertEquals('', $version_parts['version']);
  86. $this->assertEquals('5.x', $version_parts['drupal_version']);
  87. $this->assertEquals('', $version_parts['project_version']);
  88. $this->assertEquals('5', $version_parts['version_major']);
  89. $this->assertEquals('', $version_parts['version_minor']);
  90. $this->assertEquals('', $version_parts['version_patch']);
  91. $this->assertEquals('', $version_parts['version_extra']);
  92. $version = '5.x';
  93. $version_parts = pm_parse_version($version, TRUE);
  94. $this->assertEquals('5.x-dev', $version_parts['version']);
  95. $this->assertEquals('5.x', $version_parts['drupal_version']);
  96. $this->assertEquals('5', $version_parts['version_major']);
  97. $this->assertEquals('', $version_parts['version_minor']);
  98. $this->assertEquals('', $version_parts['version_patch']);
  99. $this->assertEquals('dev', $version_parts['version_extra']);
  100. $this->assertEquals('5.x-dev', $version_parts['project_version']);
  101. $version = '5.x-dev';
  102. $version_parts = pm_parse_version($version, TRUE);
  103. $this->assertEquals('5.x-dev', $version_parts['version']);
  104. $this->assertEquals('5.x', $version_parts['drupal_version']);
  105. $this->assertEquals('5', $version_parts['version_major']);
  106. $this->assertEquals('', $version_parts['version_minor']);
  107. $this->assertEquals('', $version_parts['version_patch']);
  108. $this->assertEquals('dev', $version_parts['version_extra']);
  109. $this->assertEquals('5.x-dev', $version_parts['project_version']);
  110. $version = '5.0';
  111. $version_parts = pm_parse_version($version, TRUE);
  112. $this->assertEquals('5.0', $version_parts['version']);
  113. $this->assertEquals('5.x', $version_parts['drupal_version']);
  114. $this->assertEquals('5', $version_parts['version_major']);
  115. $this->assertEquals('', $version_parts['version_minor']);
  116. $this->assertEquals('0', $version_parts['version_patch']);
  117. $this->assertEquals('', $version_parts['version_extra']);
  118. $this->assertEquals('5.0', $version_parts['project_version']);
  119. $version = '5.0-beta1';
  120. $version_parts = pm_parse_version($version, TRUE);
  121. $this->assertEquals('5.0-beta1', $version_parts['version']);
  122. $this->assertEquals('5.x', $version_parts['drupal_version']);
  123. $this->assertEquals('5', $version_parts['version_major']);
  124. $this->assertEquals('', $version_parts['version_minor']);
  125. $this->assertEquals('0', $version_parts['version_patch']);
  126. $this->assertEquals('beta1', $version_parts['version_extra']);
  127. $this->assertEquals('5.0-beta1', $version_parts['project_version']);
  128. }
  129. /**
  130. * Tests for pm_parse_version() with project versions.
  131. */
  132. public function testVersionParserContrib() {
  133. _drush_add_commandfiles(array(DRUSH_BASE_PATH . '/commands/pm'));
  134. drush_set_option('default-major', UNISH_DRUPAL_MAJOR_VERSION);
  135. $version = '';
  136. $version_parts = pm_parse_version($version);
  137. $this->assertEquals('', $version_parts['version']);
  138. $this->assertEquals(UNISH_DRUPAL_MAJOR_VERSION . '.x', $version_parts['drupal_version']);
  139. $this->assertEquals('', $version_parts['version_major']);
  140. $this->assertEquals('', $version_parts['version_minor']);
  141. $this->assertEquals('', $version_parts['version_patch']);
  142. $this->assertEquals('', $version_parts['version_extra']);
  143. $this->assertEquals('', $version_parts['project_version']);
  144. $version = '7';
  145. $version_parts = pm_parse_version($version);
  146. $this->assertEquals('', $version_parts['version']);
  147. $this->assertEquals('7.x', $version_parts['drupal_version']);
  148. $this->assertEquals('', $version_parts['version_major']);
  149. $this->assertEquals('', $version_parts['version_minor']);
  150. $this->assertEquals('', $version_parts['version_patch']);
  151. $this->assertEquals('', $version_parts['version_extra']);
  152. $this->assertEquals('', $version_parts['project_version']);
  153. $version = '7.x';
  154. $version_parts = pm_parse_version($version);
  155. $this->assertEquals('', $version_parts['version']);
  156. $this->assertEquals('7.x', $version_parts['drupal_version']);
  157. $this->assertEquals('', $version_parts['version_major']);
  158. $this->assertEquals('', $version_parts['version_minor']);
  159. $this->assertEquals('', $version_parts['version_patch']);
  160. $this->assertEquals('', $version_parts['version_extra']);
  161. $this->assertEquals('', $version_parts['project_version']);
  162. $version = '7.x-1.0-beta1';
  163. $version_parts = pm_parse_version($version);
  164. $this->assertEquals('7.x', $version_parts['drupal_version']);
  165. $this->assertEquals('1', $version_parts['version_major']);
  166. $this->assertEquals('', $version_parts['version_minor']);
  167. $this->assertEquals('0', $version_parts['version_patch']);
  168. $this->assertEquals('beta1', $version_parts['version_extra']);
  169. $this->assertEquals('1.0-beta1', $version_parts['project_version']);
  170. $version = '7.x-1.0-beta1+30-dev';
  171. $version_parts = pm_parse_version($version);
  172. $this->assertEquals('7.x', $version_parts['drupal_version']);
  173. $this->assertEquals('1', $version_parts['version_major']);
  174. $this->assertEquals('', $version_parts['version_minor']);
  175. $this->assertEquals('0', $version_parts['version_patch']);
  176. $this->assertEquals('beta1', $version_parts['version_extra']);
  177. $this->assertEquals('30', $version_parts['version_offset']);
  178. $this->assertEquals('1.0-beta1+30-dev', $version_parts['project_version']);
  179. $version = '7.x-1.0';
  180. $version_parts = pm_parse_version($version);
  181. $this->assertEquals('7.x', $version_parts['drupal_version']);
  182. $this->assertEquals('1', $version_parts['version_major']);
  183. $this->assertEquals('', $version_parts['version_minor']);
  184. $this->assertEquals('0', $version_parts['version_patch']);
  185. $this->assertEquals('', $version_parts['version_extra']);
  186. $this->assertEquals('1.0', $version_parts['project_version']);
  187. $version = '7.x-1.0+30-dev';
  188. $version_parts = pm_parse_version($version);
  189. $this->assertEquals('7.x', $version_parts['drupal_version']);
  190. $this->assertEquals('1', $version_parts['version_major']);
  191. $this->assertEquals('', $version_parts['version_minor']);
  192. $this->assertEquals('0', $version_parts['version_patch']);
  193. $this->assertEquals('', $version_parts['version_extra']);
  194. $this->assertEquals('30', $version_parts['version_offset']);
  195. $this->assertEquals('1.0+30-dev', $version_parts['project_version']);
  196. // Since we're not on a bootstrapped site, the version string
  197. // for the following cases is interpreted as a core version.
  198. // Tests on a bootstrapped site are in \pmRequestCase::testVersionParser()
  199. $version = '6.x';
  200. $version_parts = pm_parse_version($version);
  201. $this->assertEquals('6.x', $version_parts['drupal_version']);
  202. $this->assertEquals('', $version_parts['version_major']);
  203. $this->assertEquals('', $version_parts['version_minor']);
  204. $this->assertEquals('', $version_parts['version_patch']);
  205. $this->assertEquals('', $version_parts['version_extra']);
  206. $this->assertEquals('', $version_parts['project_version']);
  207. $version = '6.22';
  208. $version_parts = pm_parse_version($version);
  209. $this->assertEquals('6.x', $version_parts['drupal_version']);
  210. $this->assertEquals('', $version_parts['version_major']);
  211. $this->assertEquals('', $version_parts['version_minor']);
  212. $this->assertEquals('', $version_parts['version_patch']);
  213. $this->assertEquals('', $version_parts['version_extra']);
  214. $this->assertEquals('', $version_parts['project_version']);
  215. }
  216. /**
  217. * Tests for pm_parse_request().
  218. */
  219. public function testRequestParser() {
  220. $request = 'devel-7.x-1.2';
  221. $request = pm_parse_request($request);
  222. $this->assertEquals('devel', $request['name']);
  223. $this->assertEquals('7.x-1.2', $request['version']);
  224. $request = 'field-conditional-state';
  225. $request = pm_parse_request($request);
  226. $this->assertEquals('field-conditional-state', $request['name']);
  227. $this->assertEquals('', $request['version']);
  228. $request = 'field-conditional-state-7.x-1.2';
  229. $request = pm_parse_request($request);
  230. $this->assertEquals('field-conditional-state', $request['name']);
  231. $this->assertEquals('7.x-1.2', $request['version']);
  232. }
  233. }