PageRenderTime 40ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/unit/suite/libraries/joomla/utilities/JSimpleCryptTest.php

https://github.com/cosmocommerce/joomla
PHP | 128 lines | 65 code | 7 blank | 56 comment | 0 complexity | 8c9061257350598ee905f1b3f3573328 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * JSimpleCryptTest.php
  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. require_once JPATH_BASE. DS . 'libraries' . DS . 'joomla' . DS . 'utilities' . DS . 'simplecrypt.php';
  12. /**
  13. * Test class for JSimpleCrypt.
  14. * Generated by PHPUnit on 2009-10-26 at 22:30:43.
  15. *
  16. * @package Joomla.UnitTest
  17. * @subpackage Utilities
  18. */
  19. class JSimpleCryptTest extends PHPUnit_Framework_TestCase
  20. {
  21. /**
  22. * @var JSimpleCrypt
  23. */
  24. protected $object;
  25. /**
  26. * Sets up the fixture, for example, opens a network connection.
  27. * This method is called before a test is executed.
  28. *
  29. * @return void
  30. */
  31. protected function setUp()
  32. {
  33. //$this->object = new JSimpleCrypt;
  34. }
  35. /**
  36. * Tears down the fixture, for example, closes a network connection.
  37. * This method is called after a test is executed.
  38. *
  39. * @return void
  40. */
  41. protected function tearDown()
  42. {
  43. }
  44. /**
  45. * Test cases for encryption/decryption
  46. *
  47. * @return void
  48. */
  49. function casesEncryption()
  50. {
  51. return array(
  52. "HelloDef" => array(
  53. "Hello, World!",
  54. null,
  55. "2C515D 8574F446E57145C5443",
  56. ),
  57. "HelloKey" => array(
  58. "Hello, World!",
  59. "This is a new key",
  60. "1C D 51F4F455377 E52 2 156",
  61. ),
  62. "TypiDef" => array(
  63. "Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum",
  64. null,
  65. "304D41 D18 D B5718 E5152 75C4414 6555942594D584C 0 E46515A415E11 559 A445D1010194D154543425E5553 0574C594319505645 A F4B144342 C445250 75117445C5714455D",
  66. ),
  67. "TypiKey" => array(
  68. "Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum",
  69. "This is a new key",
  70. " 011191A 0 71C4E4148 F 7124E1F451A38 91B1A54 8 745 C 0 7 B 4491F 4146F48 C 05449 65314534E 91247 E B D3D1B491A4E491A4912 01F101E 0 D 41A3D1C49164F1B 64D",
  71. ),
  72. "WildDef" => array(
  73. chr(101).chr(23).chr(116).chr(3).chr(177).chr(99).chr(207).chr(249).chr(56).chr(107).chr(223).chr(49).chr(65).chr(119).chr(87).chr(189).chr(111).chr(133).chr(232).chr(48).chr(62).chr(201),
  74. null,
  75. " 123456789 0ABC0 0 DEF 123456789 ABCD0 0 EF0",
  76. ),
  77. "WildKey" => array(
  78. chr(101).chr(23).chr(116).chr(3).chr(177).chr(99).chr(207).chr(249).chr(56).chr(107).chr(223).chr(49).chr(65).chr(119).chr(87).chr(189).chr(111).chr(133).chr(232).chr(48).chr(62).chr(201),
  79. "This is a new key",
  80. "317F1D7091 ABCD9594BB15436573CD816D180594DE9",
  81. ),
  82. );
  83. }
  84. /**
  85. * Testing testDecrypt().
  86. *
  87. * @param string $expected The expected result of decryption
  88. * @param string $key The key to use
  89. * @param string $text The decrypted text
  90. *
  91. * @return void
  92. * @dataProvider casesEncryption
  93. */
  94. public function testDecrypt( $expected, $key, $text )
  95. {
  96. $this->object = new JSimpleCrypt($key);
  97. $this->assertThat(
  98. $this->object->decrypt($text),
  99. $this->equalTo($expected)
  100. );
  101. }
  102. /**
  103. * Testing testEncrypt().
  104. *
  105. * @param string $text The text to be encrypted
  106. * @param string $key The key to use
  107. * @param string $expected The expected result of encryption
  108. *
  109. * @return void
  110. * @dataProvider casesEncryption
  111. */
  112. public function testEncrypt( $text, $key, $expected )
  113. {
  114. $this->object = new JSimpleCrypt($key);
  115. $this->assertThat(
  116. $this->object->encrypt($text),
  117. $this->equalTo($expected)
  118. );
  119. }
  120. }
  121. ?>