18
18
namespace OpenMage \Tests \Unit \Mage \Admin \Model ;
19
19
20
20
use Exception ;
21
- use Generator ;
22
21
use Mage ;
23
22
use Mage_Admin_Model_Block as Subject ;
24
- use PHPUnit \Framework \TestCase ;
23
+ use OpenMage \Tests \Unit \OpenMageTest ;
24
+ use OpenMage \Tests \Unit \Traits \DataProvider \Mage \Admin \Model \BlockTrait ;
25
25
26
- class BlockTest extends TestCase
26
+ class BlockTest extends OpenMageTest
27
27
{
28
+ use BlockTrait;
29
+
28
30
private static Subject $ subject ;
29
31
30
32
public static function setUpBeforeClass (): void
31
33
{
32
- Mage:: app ();
34
+ parent :: setUpBeforeClass ();
33
35
self ::$ subject = Mage::getModel ('admin/block ' );
34
36
}
35
37
@@ -43,90 +45,12 @@ public static function setUpBeforeClass(): void
43
45
*/
44
46
public function testValidate (bool |array $ expectedResult , array $ methods ): void
45
47
{
46
- $ mock = $ this ->getMockBuilder (Subject::class)
47
- ->setMethods ([
48
- 'getBlockName ' ,
49
- 'getIsAllowed ' ,
50
- ])
51
- ->getMock ();
48
+ $ mock = $ this ->getMockWithCalledMethods (Subject::class, $ methods );
52
49
53
- $ mock ->method ('getBlockName ' )->willReturn ($ methods ['getBlockName ' ]);
54
- $ mock ->method ('getIsAllowed ' )->willReturn ($ methods ['getIsAllowed ' ]);
50
+ static ::assertInstanceOf (Subject::class, $ mock );
55
51
static ::assertEquals ($ expectedResult , $ mock ->validate ());
56
52
}
57
53
58
- public function provideValidateAdminBlockData (): Generator
59
- {
60
- $ errorIncorrectBlockName = 'Block Name is incorrect. ' ;
61
-
62
- yield 'valid ' => [
63
- true ,
64
- [
65
- 'getBlockName ' => 'test/block ' ,
66
- 'getIsAllowed ' => '1 ' ,
67
- ],
68
- ];
69
- yield 'invalid ' => [
70
- [$ errorIncorrectBlockName ],
71
- [
72
- 'getBlockName ' => 'Test_Block ' ,
73
- 'getIsAllowed ' => '1 ' ,
74
- ],
75
- ];
76
- yield 'errors: blank blockname ' => [
77
- [
78
- 0 => 'Block Name is required field. ' ,
79
- 1 => 'Is Allowed is required field. ' ,
80
- ],
81
- [
82
- 'getBlockName ' => '' ,
83
- 'getIsAllowed ' => '' ,
84
- ],
85
- ];
86
- yield 'errors: invalid char blockname ' => [
87
- [$ errorIncorrectBlockName ],
88
- [
89
- 'getBlockName ' => '~ ' ,
90
- 'getIsAllowed ' => '1 ' ,
91
- ],
92
- ];
93
- yield 'errors: invalid blockname ' => [
94
- [$ errorIncorrectBlockName ],
95
- [
96
- 'getBlockName ' => 'test ' ,
97
- 'getIsAllowed ' => '0 ' ,
98
- ],
99
- ];
100
- yield 'errors: null blockname ' => [
101
- ['Block Name is required field. ' ],
102
- [
103
- 'getBlockName ' => null ,
104
- 'getIsAllowed ' => '1 ' ,
105
- ],
106
- ];
107
- yield 'errors: special chars in blockname ' => [
108
- [$ errorIncorrectBlockName ],
109
- [
110
- 'getBlockName ' => '!@#$%^&*() ' ,
111
- 'getIsAllowed ' => '1 ' ,
112
- ],
113
- ];
114
- yield 'errors: numeric blockname ' => [
115
- [$ errorIncorrectBlockName ],
116
- [
117
- 'getBlockName ' => '12345 ' ,
118
- 'getIsAllowed ' => '1 ' ,
119
- ],
120
- ];
121
- yield 'valid: mixed case blockname ' => [
122
- true ,
123
- [
124
- 'getBlockName ' => 'Test/Block ' ,
125
- 'getIsAllowed ' => '1 ' ,
126
- ],
127
- ];
128
- }
129
-
130
54
/**
131
55
* @group Mage_Admin
132
56
* @group Mage_Admin_Model
0 commit comments