/framework/Release/test/Horde/Release/Unit/ReleaseTest.php

https://github.com/ewandor/horde · PHP · 257 lines · 202 code · 25 blank · 30 comment · 0 complexity · 3178b3eb077d85c806b773c315216fc9 MD5 · raw file

  1. <?php
  2. /**
  3. * Test the version processing.
  4. *
  5. * PHP version 5
  6. *
  7. * @category Horde
  8. * @package Release
  9. * @subpackage UnitTests
  10. * @author Gunnar Wrobel <wrobel@pardus.de>
  11. * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
  12. * @link http://pear.horde.org/index.php?package=Release
  13. */
  14. /**
  15. * Prepare the test setup.
  16. */
  17. require_once dirname(__FILE__) . '/../Autoload.php';
  18. /**
  19. * Test the version processing.
  20. *
  21. * Copyright 2011-2012 Horde LLC (http://www.horde.org/)
  22. *
  23. * See the enclosed file COPYING for license information (LGPL). If you
  24. * did not receive this file, see http://www.horde.org/licenses/lgpl21.
  25. *
  26. * @category Horde
  27. * @package Release
  28. * @subpackage UnitTests
  29. * @author Gunnar Wrobel <wrobel@pardus.de>
  30. * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
  31. * @link http://pear.horde.org/index.php?package=Release
  32. */
  33. class Horde_Release_Unit_ReleaseTest
  34. extends Horde_Release_TestCase
  35. {
  36. public function testUpdateSentinel()
  37. {
  38. $tmp_dir = $this->getTemporaryDirectory();
  39. $r = $this->_getReleaseHelper(
  40. $this->_getOptions(
  41. array('oldversion' => '0.9', 'version' => '1.0',)
  42. )
  43. );
  44. mkdir($tmp_dir . '/docs');
  45. file_put_contents($tmp_dir . '/docs/CHANGES', "\n=OLD=\n");
  46. $r->setVersionStrings();
  47. $r->setDirectoryName($tmp_dir);
  48. ob_start();
  49. $r->updateSentinel();
  50. ob_end_clean();
  51. $this->assertEquals(
  52. '----------
  53. v1.0.1-cvs
  54. ----------
  55. =OLD=
  56. ',
  57. file_get_contents($tmp_dir . '/docs/CHANGES')
  58. );
  59. }
  60. public function testSetMailingList()
  61. {
  62. $r = $this->_getAnnounceHelper();
  63. $r->notes['list'] = 'newlist@lists.horde.org';
  64. $this->assertContains(
  65. 'newlist@lists.horde.org',
  66. $this->_announce($r)
  67. );
  68. }
  69. public function testHordeMailingList()
  70. {
  71. $r = $this->_getAnnounceHelper(array('module' => 'horde-something'));
  72. $this->assertContains(
  73. 'horde@lists.horde.org',
  74. $this->_announce($r)
  75. );
  76. }
  77. public function testNoI18NForFinal()
  78. {
  79. $r = $this->_getAnnounceHelper();
  80. $this->assertNotContains(
  81. 'i18n@lists.horde.org',
  82. $this->_announce($r)
  83. );
  84. }
  85. public function testI18NForPreRelease()
  86. {
  87. $r = $this->_getAnnounceHelper(array('version' => '1.0-RC1'));
  88. $this->assertContains(
  89. 'i18n@lists.horde.org',
  90. $this->_announce($r)
  91. );
  92. }
  93. public function testSubject()
  94. {
  95. $r = $this->_getAnnounceHelper();
  96. $this->assertContains(
  97. 'Horde 1.0',
  98. $this->_announce($r)
  99. );
  100. }
  101. public function testSubjectForFinal()
  102. {
  103. $r = $this->_getAnnounceHelper();
  104. $this->assertContains(
  105. '(final)',
  106. $this->_announce($r)
  107. );
  108. }
  109. public function testSubjectForPreRelease()
  110. {
  111. $r = $this->_getAnnounceHelper(array('version' => '1.0-RC1'));
  112. $this->assertNotContains(
  113. '(final)',
  114. $this->_announce($r)
  115. );
  116. }
  117. public function testSubjectForBranch()
  118. {
  119. $r = $this->_getAnnounceHelper(array('version' => 'H4-1.0-RC1'));
  120. $this->assertContains(
  121. 'Horde H4 (1.0-RC1)',
  122. $this->_announce($r)
  123. );
  124. }
  125. public function testSubjectForFinalBranch()
  126. {
  127. $r = $this->_getAnnounceHelper(array('version' => 'H4-1.0'));
  128. $this->assertContains(
  129. 'Horde H4 (1.0) (final)',
  130. $this->_announce($r)
  131. );
  132. }
  133. public function testSecuritySubject()
  134. {
  135. $r = $this->_getAnnounceHelper();
  136. $r->notes['fm']['focus'] = Horde_Release::FOCUS_MAJORSECURITY;
  137. $this->assertContains(
  138. '[SECURITY]',
  139. $this->_announce($r)
  140. );
  141. }
  142. public function testSender()
  143. {
  144. $r = $this->_getAnnounceHelper();
  145. $this->assertContains(
  146. 'test@example.com',
  147. $this->_announce($r)
  148. );
  149. }
  150. public function testChangelog()
  151. {
  152. $r = $this->_getAnnounceHelper();
  153. $this->assertContains(
  154. '(from version 0.9)',
  155. $this->_announce($r)
  156. );
  157. }
  158. public function testChangeUrl()
  159. {
  160. $r = $this->_getAnnounceHelper();
  161. $this->assertContains(
  162. 'http://cvs.horde.org/diff.php',
  163. $this->_announce($r)
  164. );
  165. }
  166. public function testMailingList()
  167. {
  168. $r = $this->_getAnnounceHelper();
  169. $this->assertContains(
  170. 'ML-CHANGES',
  171. $this->_announce($r)
  172. );
  173. }
  174. private function _getOptions($options)
  175. {
  176. return array_merge(
  177. array(
  178. 'module' => 'test',
  179. 'branch' => 'master',
  180. 'horde' => array(
  181. 'user' => 'NONE'
  182. )
  183. ),
  184. $options
  185. );
  186. }
  187. private function _announce($r)
  188. {
  189. $r->setVersionStrings();
  190. ob_start();
  191. $r->announce();
  192. $output = ob_get_contents();
  193. ob_end_clean();
  194. return $output;
  195. }
  196. private function _getAnnounceHelper($options = array())
  197. {
  198. $r = $this->_getReleaseHelper(
  199. array_merge(
  200. $this->_getOptions(
  201. array(
  202. 'oldversion' => '0.9',
  203. 'version' => '1.0',
  204. 'noannounce' => true,
  205. 'ml' => array(
  206. 'from' => 'test@example.com'
  207. )
  208. )
  209. ),
  210. $options
  211. )
  212. );
  213. $r->notes['name'] = 'Horde';
  214. $r->notes['fm']['focus'] = 5;
  215. $r->notes['fm']['changes'] = 'FM-CHANGES';
  216. $r->notes['fm']['project'] = 'horde';
  217. $r->notes['fm']['branch'] = 'Horde 3';
  218. $r->notes['ml']['changes'] = 'ML-CHANGES';
  219. return $r;
  220. }
  221. private function _getReleaseHelper($options)
  222. {
  223. ob_start();
  224. $r = new Horde_Release_Stub_Release($options);
  225. ob_get_clean();
  226. return $r;
  227. }
  228. }