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
59
$ user = Bootstrap::getObjectManager ()->create (
@@ -49,38 +69,48 @@ public function testGetLatestPasswordWhenZeroPasswordLifetime()
49
69
}
50
70
51
71
/**
52
- * Test that user role is not deleted after deleting empty user
72
+ * Test that user role is not deleted after deleting empty user.
73
+ *
74
+ * @return void
53
75
*/
54
- public function testDelete ()
76
+ public function testDelete (): void
55
77
{
56
78
$ this ->checkRoleCollectionSize ();
57
79
/** @var User $user */
58
- $ user = Bootstrap::getObjectManager ()->create (
59
- User::class
60
- );
80
+ $ user = $ this ->userFactory ->create ();
61
81
$ this ->model ->delete ($ user );
62
82
$ this ->checkRoleCollectionSize ();
63
83
}
64
84
65
85
/**
66
- * Ensure that role collection size is correct
86
+ * Ensure that role collection size is correct.
87
+ *
88
+ * @return void
67
89
*/
68
- private function checkRoleCollectionSize ()
90
+ private function checkRoleCollectionSize (): void
69
91
{
70
92
/** @var UserRoleCollection $roleCollection */
71
- $ roleCollection = Bootstrap::getObjectManager ()->create (
72
- UserRoleCollection::class
73
- );
93
+ $ roleCollection = $ this ->userRoleCollectionFactory ->create ();
74
94
$ roleCollection ->setUserFilter (0 , UserContextInterface::USER_TYPE_ADMIN );
75
95
$ this ->assertEquals (1 , $ roleCollection ->getSize ());
76
96
}
77
97
78
- public function testCountAll ()
98
+ /**
99
+ * Check total user count.
100
+ *
101
+ * @return void
102
+ */
103
+ public function testCountAll (): void
79
104
{
80
105
$ this ->assertSame (1 , $ this ->model ->countAll ());
81
106
}
82
107
83
- public function testGetValidationRulesBeforeSave ()
108
+ /**
109
+ * Check validation rules has correct type.
110
+ *
111
+ * @return void
112
+ */
113
+ public function testGetValidationRulesBeforeSave (): void
84
114
{
85
115
$ rules = $ this ->model ->getValidationRulesBeforeSave ();
86
116
$ this ->assertInstanceOf ('Zend_Validate_Interface ' , $ rules );
0 commit comments