Completed
Push — master ( 0aebb5...e4bdd5 )
by Henry
06:26
created

HashTest::testGetHash()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.7
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
	 * testGetHash
71
	 *
72
	 * @since 4.3.0
73
	 *
74
	 * @param string $raw
75
	 * @param array $hashArray
76
	 *
77
	 * @dataProvider providerAutoloader
78
	 */
79
80
	public function testGetHash(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->assertStringStartsWith($expect, $actual);
96
	}
97
98
	/**
99
	 * testValidate
100
	 *
101
	 * @since 4.3.0
102
	 *
103
	 * @param string $raw
104
	 * @param array $hashArray
105
	 *
106
	 * @dataProvider providerAutoloader
107
	 */
108
109
	public function testValidate(string $raw = null, array $hashArray = []) : void
110
	{
111
		/* setup */
112
113
		$hash = new Hash();
114
		$hash->init($raw);
115
		$hashAlgorithm = $hash->getAlgorithm();
116
117
		/* actual */
118
119
		$actual = $hash->validate($raw, $hashArray[$hashAlgorithm][1]);
120
121
		/* compare */
122
123
		$this->assertTrue($actual);
124
	}
125
}
126