Completed
Push — master ( a39039...f37c71 )
by Henry
06:01
created

UserTest::testGetByUserOrEmail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 1
nc 1
nop 3
1
<?php
2
namespace Redaxscript\Tests\Model;
3
4
use Redaxscript\Db;
5
use Redaxscript\Model;
6
use Redaxscript\Tests\TestCaseAbstract;
7
8
/**
9
 * UserTest
10
 *
11
 * @since 4.0.0
12
 *
13
 * @package Redaxscript
14
 * @category Tests
15
 * @author Henry Ruhs
16
 *
17
 * @covers Redaxscript\Model\User
18
 */
19
20
class UserTest extends TestCaseAbstract
21
{
22
	/**
23
	 * setUp
24
	 *
25
	 * @since 4.0.0
26
	 */
27
28
	public function setUp() : void
29
	{
30
		parent::setUp();
31
		$installer = $this->installerFactory();
32
		$installer->init();
33
		$installer->rawCreate();
34
		Db::forTablePrefix('users')
35
			->create()
36
			->set(
37
			[
38
				'name' => 'Test One',
39
				'user' => 'testOne',
40
				'password' => 'testOne',
41
				'email' => '[email protected]'
42
			])
43
			->save();
44
		Db::forTablePrefix('users')
45
			->create()
46
			->set(
47
			[
48
				'name' => 'Test Two',
49
				'user' => 'testTwo',
50
				'password' => 'testTwo',
51
				'email' => '[email protected]'
52
			])
53
			->save();
54
	}
55
56
	/**
57
	 * tearDown
58
	 *
59
	 * @since 4.0.0
60
	 */
61
62
	public function tearDown() : void
63
	{
64
		$this->dropDatabase();
65
	}
66
67
	/**
68
	 * testGetByUser
69
	 *
70
	 * @since 4.0.0
71
	 *
72
	 * @param string $user
73
	 * @param int $expect
74
	 *
75
	 * @dataProvider providerAutoloader
76
	 */
77
78
	public function testGetByUser(string $user = null, int $expect = null) : void
79
	{
80
		/* setup */
81
82
		$userModel = new Model\User();
83
84
		/* actual */
85
86
		$actual = $userModel->getByUser($user)->id;
87
88
		/* compare */
89
90
		$this->assertEquals($expect, $actual);
91
	}
92
93
	/**
94
	 * testGetByUserOrEmail
95
	 *
96
	 * @since 4.0.0
97
	 *
98
	 * @param string $user
99
	 * @param string $email
100
	 * @param int $expect
101
	 *
102
	 * @dataProvider providerAutoloader
103
	 */
104
105
	public function testGetByUserOrEmail(string $user = null, string $email = null, int $expect = null) : void
106
	{
107
		/* setup */
108
109
		$userModel = new Model\User();
110
111
		/* actual */
112
113
		$actual = $userModel->getByUserOrEmail($user, $email)->id;
114
115
		/* compare */
116
117
		$this->assertEquals($expect, $actual);
118
	}
119
120
	/**
121
	 * testCreateByArray
122
	 *
123
	 * @since 4.0.0
124
	 *
125
	 * @param array $createArray
126
	 * @param bool $expect
127
	 *
128
	 * @dataProvider providerAutoloader
129
	 */
130
131
	public function testCreateByArray(array $createArray = [], bool $expect = null) : void
132
	{
133
		/* setup */
134
135
		$userModel = new Model\User();
136
137
		/* actual */
138
139
		$actual = $userModel->createByArray($createArray);
140
141
		/* compare */
142
143
		$this->assertEquals($expect, $actual);
144
	}
145
146
	/**
147
	 * testResetPasswordById
148
	 *
149
	 * @since 4.0.0
150
	 *
151
	 * @param int $userId
152
	 * @param string $password
153
	 * @param string $expect
154
	 *
155
	 * @dataProvider providerAutoloader
156
	 */
157
158
	public function testResetPasswordById(int $userId = null, string $password = null, string $expect = null) : void
159
	{
160
		/* setup */
161
162
		$userModel = new Model\User();
163
		$userModel->resetPasswordById($userId, $password);
164
165
		/* actual */
166
167
		$actual = $userModel->query()->whereIdIs($userId)->findOne()->password;
168
169
		/* compare */
170
171
		$this->assertEquals($expect, $actual);
172
	}
173
}
174