Completed
Push — master ( 7d322b...0aebb5 )
by Henry
09:26
created

HashTest::testGetAlgorithmAndGetHash()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
namespace Redaxscript\Tests;
3
4
use Redaxscript\Hash;
5
6
/**
7
 * HashTest
8
 *
9
 * @since 2.6.0
10
 *
11
 * @package Redaxscript
12
 * @category Tests
13
 * @author Henry Ruhs
14
 *
15
 * @covers Redaxscript\Hash
16
 */
17
18
class HashTest extends TestCaseAbstract
19
{
20
	/**
21
	 * testInit
22
	 *
23
	 * @since 2.6.0
24
	 *
25
	 * @param string $raw
26
	 *
27
	 * @dataProvider providerAutoloader
28
	 */
29
30
	public function testInit(string $raw = null) : void
31
	{
32
		/* setup */
33
34
		$hash = new Hash();
35
		$hash->init($raw);
36
37
		/* compare */
38
39
		$this->assertNotEquals($hash->getRaw(), $hash->getHash());
40
	}
41
42
	/**
43
	 * testGetRaw
44
	 *
45
	 * @since 2.6.0
46
	 *
47
	 * @param string $raw
48
	 *
49
	 * @dataProvider providerAutoloader
50
	 */
51
52
	public function testGetRaw(string $raw = null) : void
53
	{
54
		/* setup */
55
56
		$hash = new Hash();
57
		$hash->init($raw);
58
59
		/* expect and actual */
60
61
		$expect = $raw;
62
		$actual = $hash->getRaw();
63
64
		/* compare */
65
66
		$this->assertEquals($expect, $actual);
67
	}
68
69
	/**
70
	 * testGetAlgorithmAndGetHash
71
	 *
72
	 * @since 4.3.0
73
	 *
74
	 * @param string $raw
75
	 * @param array $hashArray
76
	 *
77
	 * @dataProvider providerAutoloader
78
	 */
79
80
	public function testGetAlgorithmAndGetHash(string $raw = null, array $hashArray = []) : void
81
	{
82
		/* setup */
83
84
		$hash = new Hash();
85
		$hash->init($raw);
86
		$hashAlgorithm = $hash->getAlgorithm();
87
88
		/* expect and actual */
89
90
		$expect = $hashArray[$hashAlgorithm][0];
91
		$actual = $hash->getHash();
92
93
		/* compare */
94
95
		$this->assertIsString($hashAlgorithm);
96
		$this->assertStringStartsWith($expect, $actual);
97
	}
98
99
	/**
100
	 * testValidate
101
	 *
102
	 * @since 4.3.0
103
	 *
104
	 * @param string $raw
105
	 * @param array $hashArray
106
	 *
107
	 * @dataProvider providerAutoloader
108
	 */
109
110
	public function testValidate(string $raw = null, array $hashArray = []) : void
111
	{
112
		/* setup */
113
114
		$hash = new Hash();
115
		$hash->init($raw);
116
		$hashAlgorithm = $hash->getAlgorithm();
117
118
		/* actual */
119
120
		$actual = $hash->validate($raw, $hashArray[$hashAlgorithm][1]);
121
122
		/* compare */
123
124
		$this->assertTrue($actual);
125
	}
126
}
127