@@ -18,9 +18,9 @@ class ThemeTest extends \PHPUnit_Framework_TestCase
18
18
protected $ model ;
19
19
20
20
/**
21
- * @var \Magento\Framework\Model\Context
21
+ * @var \Magento\Framework\Model\Context|\PHPUnit_Framework_MockObject_MockObject
22
22
*/
23
- protected $ context ;
23
+ protected $ contextMock ;
24
24
25
25
/**
26
26
* @var \Magento\Framework\View\DesignInterface|\PHPUnit_Framework_MockObject_MockObject
@@ -32,50 +32,30 @@ class ThemeTest extends \PHPUnit_Framework_TestCase
32
32
*/
33
33
protected $ cacheTypeListMock ;
34
34
35
- /**
36
- * @var \Magento\Framework\Event\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject
37
- */
38
- protected $ eventManagerMock ;
39
-
40
- /**
41
- * @var \Magento\Framework\App\CacheInterface | \PHPUnit_Framework_MockObject_MockObject
42
- */
43
- protected $ cacheManagerMock ;
44
-
45
35
/**
46
36
* @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
47
37
*/
48
38
protected $ configMock ;
49
39
50
40
protected function setUp ()
51
41
{
52
- $ objectManager = new ObjectManager ($ this );
53
- $ this ->cacheManagerMock = $ this ->getMockBuilder ('Magento\Framework\App\CacheInterface ' )
42
+ $ this ->contextMock = $ this ->getMockBuilder ('Magento\Framework\Model\Context ' )
54
43
->disableOriginalConstructor ()
55
44
->getMock ();
56
- $ this ->eventManagerMock = $ this ->getMockBuilder ('Magento\Framework\Event\ManagerInterface ' )
57
- ->disableOriginalConstructor ()
58
- ->getMock ();
59
- $ this ->context = $ objectManager ->getObject (
60
- 'Magento\Framework\Model\Context ' ,
61
- [
62
- 'cacheManager ' => $ this ->cacheManagerMock ,
63
- 'eventDispatcher ' => $ this ->eventManagerMock ,
64
- ]
65
- );
66
-
67
45
$ this ->designMock = $ this ->getMockBuilder ('Magento\Framework\View\DesignInterface ' )->getMock ();
68
46
$ this ->cacheTypeListMock = $ this ->getMockBuilder ('Magento\Framework\App\Cache\TypeListInterface ' )
69
47
->disableOriginalConstructor ()
70
48
->getMock ();
49
+ $ this ->contextMock ->expects ($ this ->once ())
50
+ ->method ('getEventDispatcher ' )
51
+ ->willReturn ($ this ->getMockBuilder ('Magento\Framework\Event\ManagerInterface ' )->getMock ());
71
52
$ this ->configMock = $ this ->getMockBuilder ('Magento\Framework\App\Config\ScopeConfigInterface ' )->getMock ();
72
53
73
-
74
- $ this ->model = $ objectManager ->getObject (
54
+ $ this ->model = (new ObjectManager ($ this ))->getObject (
75
55
'Magento\Theme\Model\Design\Backend\Theme ' ,
76
56
[
77
57
'design ' => $ this ->designMock ,
78
- 'context ' => $ this ->context ,
58
+ 'context ' => $ this ->contextMock ,
79
59
'cacheTypeList ' => $ this ->cacheTypeListMock ,
80
60
'config ' => $ this ->configMock ,
81
61
]
@@ -106,16 +86,25 @@ public function testAfterSave($callNumber, $oldValue)
106
86
{
107
87
$ this ->cacheTypeListMock ->expects ($ this ->exactly ($ callNumber ))
108
88
->method ('invalidate ' );
109
- $ this ->cacheManagerMock ->expects ($ this ->exactly ($ callNumber ))
110
- ->method ('clean ' );
111
89
$ this ->configMock ->expects ($ this ->any ())
112
90
->method ('getValue ' )
113
- ->willReturn ($ oldValue );
114
- if ($ callNumber ) {
115
- $ this ->eventManagerMock ->expects ($ this ->at (3 ))
116
- ->method ('dispatch ' )
117
- ->with ('adminhtml_cache_flush_system ' );
118
- }
91
+ ->willReturnMap (
92
+ [
93
+ [
94
+ Theme::XML_PATH_INVALID_CACHES ,
95
+ \Magento \Store \Model \ScopeInterface::SCOPE_STORE ,
96
+ null ,
97
+ ['block_html ' => 1 , 'layout ' => 1 , 'translate ' => 1 ]
98
+ ],
99
+ [
100
+ null ,
101
+ \Magento \Framework \App \Config \ScopeConfigInterface::SCOPE_TYPE_DEFAULT ,
102
+ null ,
103
+ $ oldValue
104
+ ],
105
+
106
+ ]
107
+ );
119
108
$ this ->model ->setValue ('some_value ' );
120
109
$ this ->assertInstanceOf (get_class ($ this ->model ), $ this ->model ->afterSave ());
121
110
}
@@ -124,7 +113,7 @@ public function afterSaveDataProvider()
124
113
{
125
114
return [
126
115
[0 , 'some_value ' ],
127
- [1 , 'other_value ' ],
116
+ [2 , 'other_value ' ],
128
117
];
129
118
}
130
119
}
0 commit comments