| @@ 15-63 (lines=49) @@ | ||
| 12 | ||
| 13 | use SecurityLib\Strength; |
|
| 14 | ||
| 15 | class HashTest extends \PHPUnit_Framework_TestCase |
|
| 16 | { |
|
| 17 | public static function provideMix() |
|
| 18 | { |
|
| 19 | $data = array( |
|
| 20 | array(array(), ''), |
|
| 21 | array(array('1', '1'), '0d'), |
|
| 22 | array(array('a'), '61'), |
|
| 23 | // This expects 'b' because of how the mock hmac function works |
|
| 24 | array(array('a', 'b'), '9a'), |
|
| 25 | array(array('aa', 'ba'), '6e84'), |
|
| 26 | array(array('ab', 'bb'), 'b0cb'), |
|
| 27 | array(array('aa', 'bb'), 'ae8d'), |
|
| 28 | array(array('aa', 'bb', 'cc'), 'a14c'), |
|
| 29 | array(array('aabbcc', 'bbccdd', 'ccddee'), 'a8aff3939934'), |
|
| 30 | ); |
|
| 31 | ||
| 32 | return $data; |
|
| 33 | } |
|
| 34 | ||
| 35 | public function testConstructWithoutArgument() |
|
| 36 | { |
|
| 37 | $hash = new Hash(); |
|
| 38 | $this->assertTrue($hash instanceof \RandomLib\Mixer); |
|
| 39 | } |
|
| 40 | ||
| 41 | public function testGetStrength() |
|
| 42 | { |
|
| 43 | $strength = new Strength(Strength::MEDIUM); |
|
| 44 | $actual = Hash::getStrength(); |
|
| 45 | $this->assertEquals($actual, $strength); |
|
| 46 | } |
|
| 47 | ||
| 48 | public function testTest() |
|
| 49 | { |
|
| 50 | $actual = Hash::test(); |
|
| 51 | $this->assertTrue($actual); |
|
| 52 | } |
|
| 53 | ||
| 54 | /** |
|
| 55 | * @dataProvider provideMix |
|
| 56 | */ |
|
| 57 | public function testMix($parts, $result) |
|
| 58 | { |
|
| 59 | $mixer = new Hash('md5'); |
|
| 60 | $actual = $mixer->mix($parts); |
|
| 61 | $this->assertEquals($result, bin2hex($actual)); |
|
| 62 | } |
|
| 63 | } |
|
| 64 | ||
| @@ 15-69 (lines=55) @@ | ||
| 12 | ||
| 13 | use SecurityLib\Strength; |
|
| 14 | ||
| 15 | class McryptRijndael128Test extends \PHPUnit_Framework_TestCase |
|
| 16 | { |
|
| 17 | public static function provideMix() |
|
| 18 | { |
|
| 19 | $data = array( |
|
| 20 | array(array(), ''), |
|
| 21 | array(array('', ''), ''), |
|
| 22 | array(array('a'), '61'), |
|
| 23 | array(array('a', 'b'), '6a'), |
|
| 24 | array(array('aa', 'ba'), '688d'), |
|
| 25 | array(array('ab', 'bb'), 'f8bc'), |
|
| 26 | array(array('aa', 'bb'), 'a0f3'), |
|
| 27 | array(array('aa', 'bb', 'cc'), '87c3'), |
|
| 28 | array(array('aabbcc', 'bbccdd', 'ccddee'), '7cf2273e46c7'), |
|
| 29 | ); |
|
| 30 | ||
| 31 | return $data; |
|
| 32 | } |
|
| 33 | ||
| 34 | protected function setUp() |
|
| 35 | { |
|
| 36 | if (!extension_loaded('mcrypt')) { |
|
| 37 | $this->markTestSkipped('mcrypt extension is not available'); |
|
| 38 | } |
|
| 39 | } |
|
| 40 | ||
| 41 | public function testConstructWithoutArgument() |
|
| 42 | { |
|
| 43 | $hash = new McryptRijndael128(); |
|
| 44 | $this->assertTrue($hash instanceof \RandomLib\Mixer); |
|
| 45 | } |
|
| 46 | ||
| 47 | public function testGetStrength() |
|
| 48 | { |
|
| 49 | $strength = new Strength(Strength::HIGH); |
|
| 50 | $actual = McryptRijndael128::getStrength(); |
|
| 51 | $this->assertEquals($actual, $strength); |
|
| 52 | } |
|
| 53 | ||
| 54 | public function testTest() |
|
| 55 | { |
|
| 56 | $actual = McryptRijndael128::test(); |
|
| 57 | $this->assertTrue($actual); |
|
| 58 | } |
|
| 59 | ||
| 60 | /** |
|
| 61 | * @dataProvider provideMix |
|
| 62 | */ |
|
| 63 | public function testMix($parts, $result) |
|
| 64 | { |
|
| 65 | $mixer = new McryptRijndael128(); |
|
| 66 | $actual = $mixer->mix($parts); |
|
| 67 | $this->assertEquals($result, bin2hex($actual)); |
|
| 68 | } |
|
| 69 | } |
|
| 70 | ||