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