PageRenderTime 54ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/unit/suite/libraries/joomla/JVersionTest.php

https://github.com/cosmocommerce/joomla
PHP | 378 lines | 266 code | 17 blank | 95 comment | 7 complexity | e1073b8390bc84fbb4684db89d2db5a0 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * JVersionTest
  4. *
  5. * @version $Id$
  6. * @package Joomla.UnitTest
  7. * @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
  8. * @license GNU General Public License
  9. */
  10. require_once 'PHPUnit/Framework.php';
  11. /**
  12. * JVersionTest
  13. *
  14. * Test class for JVersion.
  15. * Generated by PHPUnit on 2009-10-08 at 21:36:41.
  16. *
  17. * @package Joomla.UnitTest
  18. * @subpackage Utilities
  19. */
  20. class JVersionTest extends PHPUnit_Framework_TestCase
  21. {
  22. /**
  23. * @var JVersion
  24. */
  25. protected $object;
  26. protected $PRODUCT = 'Joomla!';
  27. protected $RELEASE = '12.23';
  28. protected $DEV_STATUS = 'Testing';
  29. protected $DEV_LEVEL = '999';
  30. protected $BUILD = '99999';
  31. protected $CODENAME = 'Desperation';
  32. protected $RELDATE = '22-June-3109';
  33. protected $RELTIME = '13:13';
  34. protected $RELTZ = 'CDT';
  35. protected $COPYRIGHT = 'Copyright (C) 2005 - 3109 Open Source Matters. All rights reserved.';
  36. protected $URL = '<a href="http://www.joomla.org">Joomla!</a> is Free Software released under the GNU General Public License.';
  37. /**
  38. * Sets up the fixture, for example, opens a network connection.
  39. * This method is called before a test is executed.
  40. *
  41. * @return void
  42. */
  43. protected function setUp()
  44. {
  45. $this->object = new JVersion;
  46. $this->object->PRODUCT = $this->PRODUCT;
  47. $this->object->RELEASE = $this->RELEASE;
  48. $this->object->DEV_STATUS = $this->DEV_STATUS;
  49. $this->object->DEV_LEVEL = $this->DEV_LEVEL;
  50. $this->object->BUILD = $this->BUILD;
  51. $this->object->CODENAME = $this->CODENAME;
  52. $this->object->RELDATE = $this->RELDATE;
  53. $this->object->RELTIME = $this->RELTIME;
  54. $this->object->RELTZ = $this->RELTZ;
  55. $this->object->COPYRIGHT = $this->COPYRIGHT;
  56. $this->object->URL = $this->URL;
  57. }
  58. /**
  59. * Tears down the fixture, for example, closes a network connection.
  60. * This method is called after a test is executed.
  61. *
  62. * @return void
  63. */
  64. protected function tearDown()
  65. {
  66. }
  67. /**
  68. * This checks for the correct Long Version.
  69. *
  70. * @return void
  71. */
  72. public function testGetLongVersion()
  73. {
  74. $expected = 'Joomla! 12.23.999 Testing [ Desperation ] 22-June-3109 13:13 CDT';
  75. $this->assertEquals(
  76. $expected,
  77. $this->object->getLongVersion(),
  78. 'Should get the correct Long Version'
  79. );
  80. }
  81. /**
  82. * This checks for the correct Short Version.
  83. *
  84. * @return void
  85. */
  86. public function testGetShortVersion()
  87. {
  88. $expected = '12.23.999';
  89. $this->assertEquals(
  90. $expected,
  91. $this->object->getShortVersion(),
  92. 'Should get the correct Short Version'
  93. );
  94. }
  95. /**
  96. * Help test cases
  97. *
  98. * @return array
  99. */
  100. function casesHelp()
  101. {
  102. return array(
  103. 'AsSet' => array(
  104. null,
  105. '.1223',
  106. 'Should get the correct Help version',
  107. ),
  108. '1.0' => array(
  109. '',
  110. '',
  111. 'Should get an empty Help version',
  112. ),
  113. );
  114. }
  115. /**
  116. * This checks for the correct Help Version.
  117. *
  118. * @param string $release Joomla release number
  119. * @param string $expect Expected help Version
  120. * @param string $message Test failure message
  121. *
  122. * @return void
  123. * @dataProvider casesHelp
  124. */
  125. public function testGetHelpVersion( $release, $expect, $message )
  126. {
  127. if (is_null($release))
  128. {
  129. $output = $this->object->getHelpVersion();
  130. }
  131. else
  132. {
  133. $this->object->RELEASE = '1.0';
  134. $output = $this->object->getHelpVersion();
  135. }
  136. $this->assertEquals(
  137. $expect,
  138. $output,
  139. $message
  140. );
  141. }
  142. /**
  143. * Compatibility test cases
  144. *
  145. * @return array
  146. */
  147. function casesCompatibility()
  148. {
  149. return array(
  150. 'wrong' => array(
  151. '0.3',
  152. false,
  153. 'Should not be compatible with 0.3',
  154. ),
  155. 'empty' => array(
  156. '',
  157. false,
  158. 'Should not be compatible with empty string',
  159. ),
  160. 'null' => array(
  161. null,
  162. false,
  163. 'Should not be compatible with null',
  164. ),
  165. 'itself' => array(
  166. JVERSION,
  167. true,
  168. 'Should be compatible with itself',
  169. ),
  170. );
  171. }
  172. /**
  173. * This checks the compatibility testing method.
  174. *
  175. * @param string $input Version
  176. * @param bool $expect expected result of version check
  177. * @param string $message Test failure message
  178. *
  179. * @return void
  180. * @dataProvider casesCompatibility
  181. */
  182. public function testIsCompatible( $input, $expect, $message )
  183. {
  184. $this->assertThat(
  185. $expect,
  186. $this->equalTo($this->object->isCompatible($input)),
  187. $message
  188. );
  189. }
  190. /**
  191. * User Agent test cases
  192. *
  193. * @return array
  194. */
  195. function casesUserAgent()
  196. {
  197. return array(
  198. 'defaults' => array(
  199. '',
  200. false,
  201. true,
  202. 'Joomla!/12.23.999 Framework/12.23',
  203. 'Should get the default Framework User Agent',
  204. true
  205. ),
  206. 'Def/Null/Ver' => array(
  207. null,
  208. null,
  209. true,
  210. 'Joomla!/12.23.999 Framework/12.23',
  211. 'Should get the default Framework User Agent with version',
  212. false
  213. ),
  214. 'Def/Def/Ver' => array(
  215. null,
  216. false,
  217. true,
  218. 'Joomla!/12.23.999 Framework/12.23',
  219. 'Should get the default Framework User Agent with version',
  220. false
  221. ),
  222. 'Def/Def/noVer' => array(
  223. null,
  224. false,
  225. false,
  226. 'Joomla!/12.23.999 Framework',
  227. 'Should get the default Framework User Agent without version',
  228. false
  229. ),
  230. 'Def/Moz/noVer' => array(
  231. null,
  232. true,
  233. false,
  234. 'Mozilla/5.0 Joomla!/12.23.999 Framework',
  235. 'Should get the Mozilla Framework User Agent without version',
  236. false
  237. ),
  238. 'Def/Moz/Ver' => array(
  239. null,
  240. true,
  241. true,
  242. 'Mozilla/5.0 Joomla!/12.23.999 Framework/12.23',
  243. 'Should get the Mozilla Framework User Agent with version',
  244. false
  245. ),
  246. 'CMS/Nulls' => array(
  247. 'CMS',
  248. null,
  249. null,
  250. 'Joomla!/12.23.999 CMS/12.23',
  251. 'Should get the default CMS User Agent with version',
  252. false
  253. ),
  254. 'CMS/Def/Ver' => array(
  255. 'CMS',
  256. false,
  257. true,
  258. 'Joomla!/12.23.999 CMS/12.23',
  259. 'Should get the default CMS User Agent with version',
  260. false
  261. ),
  262. 'CMS/Def/noVer' => array(
  263. 'CMS',
  264. false,
  265. false,
  266. 'Joomla!/12.23.999 CMS',
  267. 'Should get the default CMS User Agent without version',
  268. false
  269. ),
  270. 'CMS/Moz/Ver' => array(
  271. 'CMS',
  272. true,
  273. true,
  274. 'Mozilla/5.0 Joomla!/12.23.999 CMS/12.23',
  275. 'Should get the Mozilla CMS User Agent',
  276. false
  277. ),
  278. 'CMS/Moz/noVer' => array(
  279. 'CMS',
  280. true,
  281. false,
  282. 'Mozilla/5.0 Joomla!/12.23.999 CMS',
  283. 'Should get the Mozilla CMS User Agent without version',
  284. false
  285. ),
  286. );
  287. }
  288. /**
  289. * This checks for generation of the correct user agent string.
  290. *
  291. * @param string $component default "Framework"
  292. * @param bool $mask mask user agent as Mozilla
  293. * @param bool $addVersion Add Version to UA String
  294. * @param string $expect expected result
  295. * @param string $message Test failure message
  296. * @param bool $useDefaults use no arguments, accept function default
  297. *
  298. * @return void
  299. * @dataProvider casesUserAgent
  300. */
  301. public function testSettingCorrectUserAgentString( $component, $mask, $addVersion,
  302. $expect, $message, $useDefaults ) {
  303. if ( $useDefaults )
  304. {
  305. $output = $this->object->getUserAgent();
  306. }
  307. else if (is_null($mask))
  308. {
  309. $output = $this->object->getUserAgent($component);
  310. }
  311. else if (is_null($addVersion))
  312. {
  313. $output = $this->object->getUserAgent($component, $mask);
  314. }
  315. else
  316. {
  317. $output = $this->object->getUserAgent($component, $mask, $addVersion);
  318. }
  319. $this->assertEquals(
  320. $expect,
  321. $output,
  322. $message
  323. );
  324. }
  325. /**
  326. * This checks for correct operation of the __set_state() magic function, if it exists.
  327. *
  328. * @return void
  329. */
  330. public function testSetState()
  331. {
  332. if (method_exists('JVersion', '__set_state'))
  333. {
  334. $testData = array(
  335. 'PRODUCT' => 'Joomla!',
  336. 'RELEASE' => '1.6',
  337. 'DEV_STATUS' => 'Alpha',
  338. 'DEV_LEVEL' => '0',
  339. 'BUILD' => '',
  340. 'CODENAME' => 'Hope',
  341. 'RELDATE' => '22-June-2009',
  342. 'RELTIME' => '23:00',
  343. 'RELTZ' => 'GMT',
  344. 'COPYRIGHT' => 'Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.',
  345. 'URL' => '<a href="http://www.joomla.org">Joomla!</a> is Free Software released under the GNU General Public License.'
  346. );
  347. $testInstance = $this->object->__set_state($testData);
  348. foreach ($testData as $key => $value)
  349. {
  350. $this->assertThat(
  351. $testInstance->$key,
  352. $this->equalTo($value)
  353. );
  354. }
  355. $this->assertThat(
  356. $testInstance,
  357. $this->isInstanceOf('JVersion')
  358. );
  359. }
  360. }
  361. }