@@ -26,39 +26,74 @@ 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 ('Magento\Theme\Model\Theme ' , [], [], '' , false );
40
59
$ this ->appState ->expects ($ this ->once ())->method ('getMode ' )->willReturn ('default ' );
41
60
$ 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 );
61
+ $ this ->themeCollection ->expects ($ this ->once ())->method ('loadData ' )->willReturn ([$ theme ]);
62
+ $ theme ->expects ($ this ->once ())->method ('getArea ' )->willReturn ('frontend ' );
63
+ $ theme ->expects ($ this ->once ())->method ('getThemePath ' )->willReturn ('Magento/luma ' );
64
+ $ this ->themeLoader ->expects ($ this ->once ())
65
+ ->method ('getThemeByFullPath ' )
66
+ ->with ('frontend/Magento/luma ' )
67
+ ->willReturn ($ theme );
68
+ $ theme ->expects ($ this ->once ())
69
+ ->method ('toArray ' )
70
+ ->willReturn ([
71
+ 'title ' => 'Magento Luma '
72
+ ]);
73
+ $ theme ->expects ($ this ->once ())
74
+ ->method ('addData ' )
75
+ ->with ([
76
+ 'title ' => 'Magento Luma '
77
+ ])
78
+ ->willReturnSelf ();
79
+ $ theme ->expects ($ this ->once ())
80
+ ->method ('save ' );
81
+
82
+ $ this ->plugin ->beforeDispatch ($ this ->abstractAction , $ this ->request );
45
83
}
46
84
47
85
public function testBeforeDispatchWithProductionMode ()
48
86
{
49
87
$ 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 );
88
+ $ this ->plugin ->beforeDispatch ($ this ->abstractAction , $ this ->request );
54
89
}
55
90
56
91
public function testBeforeDispatchWithException ()
57
92
{
58
93
$ exception = new LocalizedException (new Phrase ('Phrase ' ));
59
94
$ this ->themeRegistration ->expects ($ this ->once ())->method ('register ' )->willThrowException ($ exception );
60
95
$ this ->logger ->expects ($ this ->once ())->method ('critical ' );
61
- $ object = new Registration ( $ this -> themeRegistration , $ this -> logger , $ this -> appState );
62
- $ object ->beforeDispatch ($ this ->abstractAction , $ this ->request );
96
+
97
+ $ this -> plugin ->beforeDispatch ($ this ->abstractAction , $ this ->request );
63
98
}
64
99
}
0 commit comments