3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ declare (strict_types=1 );
7
+
6
8
namespace Magento \User \Model \ResourceModel ;
7
9
8
10
use Magento \Authorization \Model \ResourceModel \Role \Collection as UserRoleCollection ;
11
+ use Magento \Authorization \Model \ResourceModel \Role \CollectionFactory as UserRoleCollectionFactory ;
9
12
use Magento \Authorization \Model \UserContextInterface ;
10
13
use Magento \TestFramework \Helper \Bootstrap ;
11
14
use Magento \User \Model \ResourceModel \User as UserResourceModel ;
12
15
use Magento \User \Model \User ;
16
+ use Magento \User \Model \UserFactory ;
13
17
14
18
/**
15
19
* @magentoAppArea adminhtml
16
20
*/
17
21
class UserTest extends \PHPUnit \Framework \TestCase
18
22
{
19
- /** @var UserResourceModel */
23
+ /**
24
+ * @var UserResourceModel
25
+ */
20
26
private $ model ;
21
27
28
+ /**
29
+ * @var UserRoleCollectionFactory
30
+ */
31
+ private $ userRoleCollectionFactory ;
32
+
33
+ /**
34
+ * @var UserFactory
35
+ */
36
+ private $ userFactory ;
37
+
38
+ /**
39
+ * @inheritdoc
40
+ */
22
41
protected function setUp ()
23
42
{
24
- $ this ->model = Bootstrap::getObjectManager ()->get (
25
- UserResourceModel:: class
26
- );
43
+ $ this ->model = Bootstrap::getObjectManager ()->get (UserResourceModel::class);
44
+ $ this -> userRoleCollectionFactory = Bootstrap:: getObjectManager ()-> get (UserRoleCollectionFactory:: class);
45
+ $ this -> userFactory = Bootstrap:: getObjectManager ()-> get (UserFactory::class );
27
46
}
28
47
29
48
/**
30
49
* Tests if latest password is stored after user creating
31
50
* when password lifetime config value is zero (disabled as fact)
32
51
*
52
+ * @return void
33
53
* @magentoConfigFixture current_store admin/security/password_lifetime 0
34
54
* @magentoDataFixture Magento/User/_files/dummy_user.php
35
55
*/
36
- public function testGetLatestPasswordWhenZeroPasswordLifetime ()
56
+ public function testGetLatestPasswordWhenZeroPasswordLifetime (): void
37
57
{
38
58
/** @var User $user */
39
- $ user = Bootstrap::getObjectManager ()->create (
40
- User::class
41
- );
59
+ $ user = $ this ->userFactory ->create ();
42
60
$ user ->loadByUsername ('dummy_username ' );
43
61
$ latestPassword = $ this ->model ->getLatestPassword ($ user ->getId ());
44
62
@@ -49,38 +67,48 @@ public function testGetLatestPasswordWhenZeroPasswordLifetime()
49
67
}
50
68
51
69
/**
52
- * Test that user role is not deleted after deleting empty user
70
+ * Test that user role is not deleted after deleting empty user.
71
+ *
72
+ * @return void
53
73
*/
54
- public function testDelete ()
74
+ public function testDelete (): void
55
75
{
56
76
$ this ->checkRoleCollectionSize ();
57
77
/** @var User $user */
58
- $ user = Bootstrap::getObjectManager ()->create (
59
- User::class
60
- );
78
+ $ user = $ this ->userFactory ->create ();
61
79
$ this ->model ->delete ($ user );
62
80
$ this ->checkRoleCollectionSize ();
63
81
}
64
82
65
83
/**
66
- * Ensure that role collection size is correct
84
+ * Ensure that role collection size is correct.
85
+ *
86
+ * @return void
67
87
*/
68
- private function checkRoleCollectionSize ()
88
+ private function checkRoleCollectionSize (): void
69
89
{
70
90
/** @var UserRoleCollection $roleCollection */
71
- $ roleCollection = Bootstrap::getObjectManager ()->create (
72
- UserRoleCollection::class
73
- );
91
+ $ roleCollection = $ this ->userRoleCollectionFactory ->create ();
74
92
$ roleCollection ->setUserFilter (0 , UserContextInterface::USER_TYPE_ADMIN );
75
93
$ this ->assertEquals (1 , $ roleCollection ->getSize ());
76
94
}
77
95
78
- public function testCountAll ()
96
+ /**
97
+ * Check total user count.
98
+ *
99
+ * @return void
100
+ */
101
+ public function testCountAll (): void
79
102
{
80
103
$ this ->assertSame (1 , $ this ->model ->countAll ());
81
104
}
82
105
83
- public function testGetValidationRulesBeforeSave ()
106
+ /**
107
+ * Check validation rules has correct type.
108
+ *
109
+ * @return void
110
+ */
111
+ public function testGetValidationRulesBeforeSave (): void
84
112
{
85
113
$ rules = $ this ->model ->getValidationRulesBeforeSave ();
86
114
$ this ->assertInstanceOf ('Zend_Validate_Interface ' , $ rules );
0 commit comments