@@ -26,39 +26,100 @@ class RegistrationTest extends \PHPUnit_Framework_TestCase
26
26
/** @var \Magento\Framework\App\State|\PHPUnit_Framework_MockObject_MockObject */
27
27
protected $ appState ;
28
28
29
+ /** @var \Magento\Theme\Model\Theme\Collection|\PHPUnit_Framework_MockObject_MockObject */
30
+ protected $ themeCollection ;
31
+
32
+ /** @var \Magento\Theme\Model\ResourceModel\Theme\Collection|\PHPUnit_Framework_MockObject_MockObject */
33
+ protected $ themeLoader ;
34
+
35
+ /** @var Registration */
36
+ protected $ plugin ;
37
+
29
38
public function setUp ()
30
39
{
31
40
$ this ->themeRegistration = $ this ->getMock ('Magento\Theme\Model\Theme\Registration ' , [], [], '' , false );
32
41
$ this ->logger = $ this ->getMockForAbstractClass ('Psr\Log\LoggerInterface ' , [], '' , false );
33
42
$ this ->abstractAction = $ this ->getMockForAbstractClass ('Magento\Backend\App\AbstractAction ' , [], '' , false );
34
43
$ this ->request = $ this ->getMockForAbstractClass ('Magento\Framework\App\RequestInterface ' , [], '' , false );
35
44
$ this ->appState = $ this ->getMock ('Magento\Framework\App\State ' , [], [], '' , false );
45
+ $ this ->themeCollection = $ this ->getMock ('Magento\Theme\Model\Theme\Collection ' , [], [], '' , false );
46
+ $ this ->themeLoader = $ this ->getMock ('Magento\Theme\Model\ResourceModel\Theme\Collection ' , [], [], '' , false );
47
+ $ this ->plugin = new Registration (
48
+ $ this ->themeRegistration ,
49
+ $ this ->themeCollection ,
50
+ $ this ->themeLoader ,
51
+ $ this ->logger ,
52
+ $ this ->appState
53
+ );
36
54
}
37
55
38
56
public function testBeforeDispatch ()
39
57
{
58
+ $ theme = $ this ->getMock (
59
+ 'Magento\Theme\Model\Theme ' ,
60
+ [
61
+ 'setParentId ' ,
62
+ 'getArea ' ,
63
+ 'getThemePath ' ,
64
+ 'getParentTheme ' ,
65
+ 'getId ' ,
66
+ 'getFullPath ' ,
67
+ 'toArray ' ,
68
+ 'addData ' ,
69
+ 'save ' ,
70
+ ],
71
+ [],
72
+ '' ,
73
+ false
74
+ );
40
75
$ this ->appState ->expects ($ this ->once ())->method ('getMode ' )->willReturn ('default ' );
41
76
$ this ->themeRegistration ->expects ($ this ->once ())->method ('register ' );
42
- $ this ->logger ->expects ($ this ->never ())->method ('critical ' );
43
- $ object = new Registration ($ this ->themeRegistration , $ this ->logger , $ this ->appState );
44
- $ object ->beforeDispatch ($ this ->abstractAction , $ this ->request );
77
+ $ this ->themeCollection ->expects ($ this ->once ())->method ('loadData ' )->willReturn ([$ theme ]);
78
+ $ theme ->expects ($ this ->once ())->method ('getArea ' )->willReturn ('frontend ' );
79
+ $ theme ->expects ($ this ->once ())->method ('getThemePath ' )->willReturn ('Magento/luma ' );
80
+ $ theme ->expects ($ this ->exactly (2 ))->method ('getParentTheme ' )->willReturnSelf ();
81
+ $ theme ->expects ($ this ->once ())->method ('getId ' )->willReturn (1 );
82
+ $ theme ->expects ($ this ->once ())->method ('getFullPath ' )->willReturn ('frontend/Magento/blank ' );
83
+ $ theme ->expects ($ this ->once ())->method ('setParentId ' )->with (1 );
84
+ $ this ->themeLoader ->expects ($ this ->exactly (2 ))
85
+ ->method ('getThemeByFullPath ' )
86
+ ->withConsecutive (
87
+ ['frontend/Magento/blank ' ],
88
+ ['frontend/Magento/luma ' ]
89
+ )
90
+ ->will ($ this ->onConsecutiveCalls (
91
+ $ theme ,
92
+ $ theme
93
+ ));
94
+ $ theme ->expects ($ this ->once ())
95
+ ->method ('toArray ' )
96
+ ->willReturn ([
97
+ 'title ' => 'Magento Luma '
98
+ ]);
99
+ $ theme ->expects ($ this ->once ())
100
+ ->method ('addData ' )
101
+ ->with ([
102
+ 'title ' => 'Magento Luma '
103
+ ])
104
+ ->willReturnSelf ();
105
+ $ theme ->expects ($ this ->once ())
106
+ ->method ('save ' );
107
+
108
+ $ this ->plugin ->beforeDispatch ($ this ->abstractAction , $ this ->request );
45
109
}
46
110
47
111
public function testBeforeDispatchWithProductionMode ()
48
112
{
49
113
$ this ->appState ->expects ($ this ->once ())->method ('getMode ' )->willReturn ('production ' );
50
- $ this ->themeRegistration ->expects ($ this ->never ())->method ('register ' );
51
- $ this ->logger ->expects ($ this ->never ())->method ('critical ' );
52
- $ object = new Registration ($ this ->themeRegistration , $ this ->logger , $ this ->appState );
53
- $ object ->beforeDispatch ($ this ->abstractAction , $ this ->request );
114
+ $ this ->plugin ->beforeDispatch ($ this ->abstractAction , $ this ->request );
54
115
}
55
116
56
117
public function testBeforeDispatchWithException ()
57
118
{
58
119
$ exception = new LocalizedException (new Phrase ('Phrase ' ));
59
120
$ this ->themeRegistration ->expects ($ this ->once ())->method ('register ' )->willThrowException ($ exception );
60
121
$ this ->logger ->expects ($ this ->once ())->method ('critical ' );
61
- $ object = new Registration ( $ this -> themeRegistration , $ this -> logger , $ this -> appState );
62
- $ object ->beforeDispatch ($ this ->abstractAction , $ this ->request );
122
+
123
+ $ this -> plugin ->beforeDispatch ($ this ->abstractAction , $ this ->request );
63
124
}
64
125
}
0 commit comments