5
5
*/
6
6
namespace Magento \Sitemap \Test \Unit \Model ;
7
7
8
+ use Magento \Framework \App \Area ;
8
9
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
10
+ use Magento \Sitemap \Model \EmailNotification ;
11
+ use Magento \Store \Model \App \Emulation ;
9
12
10
13
/**
11
14
* Class ObserverTest
15
+ *
12
16
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
13
17
*/
14
18
class ObserverTest extends \PHPUnit \Framework \TestCase
@@ -33,21 +37,6 @@ class ObserverTest extends \PHPUnit\Framework\TestCase
33
37
*/
34
38
private $ collectionFactoryMock ;
35
39
36
- /**
37
- * @var \Magento\Framework\Mail\Template\TransportBuilder|\PHPUnit_Framework_MockObject_MockObject
38
- */
39
- private $ transportBuilderMock ;
40
-
41
- /**
42
- * @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
43
- */
44
- private $ storeManagerMock ;
45
-
46
- /**
47
- * @var \Magento\Framework\Translate\Inline\StateInterface|\PHPUnit_Framework_MockObject_MockObject
48
- */
49
- private $ inlineTranslationMock ;
50
-
51
40
/**
52
41
* @var \Magento\Sitemap\Model\ResourceModel\Sitemap\Collection|\PHPUnit_Framework_MockObject_MockObject
53
42
*/
@@ -63,6 +52,16 @@ class ObserverTest extends \PHPUnit\Framework\TestCase
63
52
*/
64
53
private $ objectManagerMock ;
65
54
55
+ /**
56
+ * @var Emulation|\PHPUnit_Framework_MockObject_MockObject
57
+ */
58
+ private $ appEmulationMock ;
59
+
60
+ /**
61
+ * @var EmailNotification|\PHPUnit_Framework_MockObject_MockObject
62
+ */
63
+ private $ emailNotificationMock ;
64
+
66
65
protected function setUp ()
67
66
{
68
67
$ this ->objectManagerMock = $ this ->getMockBuilder (\Magento \Framework \ObjectManagerInterface::class)
@@ -74,36 +73,36 @@ protected function setUp()
74
73
)->disableOriginalConstructor ()
75
74
->setMethods (['create ' ])
76
75
->getMock ();
77
- $ this ->transportBuilderMock = $ this ->getMockBuilder (\Magento \Framework \Mail \Template \TransportBuilder::class)
78
- ->disableOriginalConstructor ()
79
- ->getMock ();
80
- $ this ->storeManagerMock = $ this ->getMockBuilder (\Magento \Store \Model \StoreManagerInterface::class)
81
- ->getMock ();
82
- $ this ->inlineTranslationMock = $ this ->getMockBuilder (\Magento \Framework \Translate \Inline \StateInterface::class)
83
- ->getMock ();
84
76
$ this ->sitemapCollectionMock = $ this ->createPartialMock (
85
77
\Magento \Sitemap \Model \ResourceModel \Sitemap \Collection::class,
86
78
['getIterator ' ]
87
79
);
88
- $ this ->sitemapMock = $ this ->createPartialMock (\Magento \Sitemap \Model \Sitemap::class, ['generateXml ' ]);
89
-
80
+ $ this ->sitemapMock = $ this ->createPartialMock (
81
+ \Magento \Sitemap \Model \Sitemap::class,
82
+ [
83
+ 'generateXml ' ,
84
+ 'getStoreId ' ,
85
+ ]
86
+ );
87
+ $ this ->appEmulationMock = $ this ->createMock (Emulation::class);
88
+ $ this ->emailNotificationMock = $ this ->createMock (EmailNotification::class);
90
89
$ this ->objectManager = new ObjectManager ($ this );
90
+
91
91
$ this ->observer = $ this ->objectManager ->getObject (
92
92
\Magento \Sitemap \Model \Observer::class,
93
93
[
94
94
'scopeConfig ' => $ this ->scopeConfigMock ,
95
95
'collectionFactory ' => $ this ->collectionFactoryMock ,
96
- 'storeManager ' => $ this ->storeManagerMock ,
97
- 'transportBuilder ' => $ this ->transportBuilderMock ,
98
- 'inlineTranslation ' => $ this ->inlineTranslationMock
96
+ 'appEmulation ' => $ this ->appEmulationMock ,
97
+ 'emailNotification ' => $ this ->emailNotificationMock
99
98
]
100
99
);
101
100
}
102
101
103
102
public function testScheduledGenerateSitemapsSendsExceptionEmail ()
104
103
{
105
104
$ exception = 'Sitemap Exception ' ;
106
- $ transport = $ this -> createMock (\ Magento \ Framework \ Mail \TransportInterface::class) ;
105
+ $ storeId = 1 ;
107
106
108
107
$ this ->scopeConfigMock ->expects ($ this ->once ())->method ('isSetFlag ' )->willReturn (true );
109
108
@@ -115,55 +114,32 @@ public function testScheduledGenerateSitemapsSendsExceptionEmail()
115
114
->method ('getIterator ' )
116
115
->willReturn (new \ArrayIterator ([$ this ->sitemapMock ]));
117
116
118
- $ this ->sitemapMock ->expects ($ this ->once ())
117
+ $ this ->sitemapMock ->expects ($ this ->at (0 ))
118
+ ->method ('getStoreId ' )
119
+ ->willReturn ($ storeId );
120
+
121
+ $ this ->sitemapMock ->expects ($ this ->at (1 ))
119
122
->method ('generateXml ' )
120
123
->willThrowException (new \Exception ($ exception ));
121
124
122
- $ this ->scopeConfigMock ->expects ($ this ->at (1 ))
125
+ $ this ->scopeConfigMock ->expects ($ this ->at (0 ))
123
126
->method ('getValue ' )
124
127
->with (
125
128
\Magento \Sitemap \Model \Observer::XML_PATH_ERROR_RECIPIENT ,
126
129
\Magento \Store \Model \ScopeInterface::SCOPE_STORE
127
130
)
128
131
->
willReturn (
'[email protected] ' );
129
132
130
- $ this ->inlineTranslationMock ->expects ($ this ->once ())
131
- ->method ('suspend ' );
132
-
133
- $ this ->transportBuilderMock ->expects ($ this ->once ())
134
- ->method ('setTemplateIdentifier ' )
135
- ->will ($ this ->returnSelf ());
136
-
137
- $ this ->transportBuilderMock ->expects ($ this ->once ())
138
- ->method ('setTemplateOptions ' )
139
- ->with ([
140
- 'area ' => \Magento \Backend \App \Area \FrontNameResolver::AREA_CODE ,
141
- 'store ' => \Magento \Store \Model \Store::DEFAULT_STORE_ID ,
142
- ])
143
- ->will ($ this ->returnSelf ());
144
-
145
- $ this ->transportBuilderMock ->expects ($ this ->once ())
146
- ->method ('setTemplateVars ' )
147
- ->with (['warnings ' => $ exception ])
148
- ->will ($ this ->returnSelf ());
149
-
150
- $ this ->transportBuilderMock ->expects ($ this ->once ())
151
- ->method ('setFrom ' )
152
- ->will ($ this ->returnSelf ());
153
-
154
- $ this ->transportBuilderMock ->expects ($ this ->once ())
155
- ->method ('addTo ' )
156
- ->will ($ this ->returnSelf ());
157
-
158
- $ this ->transportBuilderMock ->expects ($ this ->once ())
159
- ->method ('getTransport ' )
160
- ->willReturn ($ transport );
161
-
162
- $ transport ->expects ($ this ->once ())
163
- ->method ('sendMessage ' );
133
+ $ this ->appEmulationMock ->expects ($ this ->at (0 ))
134
+ ->method ('startEnvironmentEmulation ' )
135
+ ->with (
136
+ $ storeId ,
137
+ Area::AREA_FRONTEND ,
138
+ true
139
+ );
164
140
165
- $ this ->inlineTranslationMock ->expects ($ this ->once ( ))
166
- ->method ('resume ' );
141
+ $ this ->appEmulationMock ->expects ($ this ->at ( 1 ))
142
+ ->method ('stopEnvironmentEmulation ' );
167
143
168
144
$ this ->observer ->scheduledGenerateSitemaps ();
169
145
}
0 commit comments