Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 3c3168b

Browse files
committed
Update scheduledGenerateSitemaps unit test
1 parent 3fc3c1d commit 3c3168b

File tree

1 file changed

+51
-5
lines changed

1 file changed

+51
-5
lines changed

app/code/Magento/Sitemap/Test/Unit/Model/ObserverTest.php

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ protected function setUp()
9696
);
9797
}
9898

99-
/**
100-
* @expectedException \Exception
101-
*/
102-
public function testScheduledGenerateSitemapsThrowsException()
99+
public function testScheduledGenerateSitemapsSendsExceptionEmail()
103100
{
101+
$exception = 'Sitemap Exception';
102+
$transport = $this->createMock(\Magento\Framework\Mail\TransportInterface::class);
103+
104104
$this->scopeConfigMock->expects($this->once())->method('isSetFlag')->willReturn(true);
105105

106106
$this->collectionFactoryMock->expects($this->once())
@@ -111,7 +111,53 @@ public function testScheduledGenerateSitemapsThrowsException()
111111
->method('getIterator')
112112
->willReturn(new \ArrayIterator([$this->sitemapMock]));
113113

114-
$this->sitemapMock->expects($this->once())->method('generateXml')->willThrowException(new \Exception());
114+
$this->sitemapMock->expects($this->once())->method('generateXml')->willThrowException(new \Exception($exception));
115+
116+
$this->scopeConfigMock->expects($this->at(1))
117+
->method('getValue')
118+
->with(
119+
\Magento\Sitemap\Model\Observer::XML_PATH_ERROR_RECIPIENT,
120+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
121+
)
122+
->willReturn('[email protected]');
123+
124+
$this->inlineTranslationMock->expects($this->once())
125+
->method('suspend');
126+
127+
$this->transportBuilderMock->expects($this->once())
128+
->method('setTemplateIdentifier')
129+
->will($this->returnSelf());
130+
131+
$this->transportBuilderMock->expects($this->once())
132+
->method('setTemplateOptions')
133+
->with([
134+
'area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE,
135+
'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
136+
])
137+
->will($this->returnSelf());
138+
139+
$this->transportBuilderMock->expects($this->once())
140+
->method('setTemplateVars')
141+
->with(['warnings' => $exception])
142+
->will($this->returnSelf());
143+
144+
$this->transportBuilderMock->expects($this->once())
145+
->method('setFrom')
146+
->will($this->returnSelf());
147+
148+
$this->transportBuilderMock->expects($this->once())
149+
->method('addTo')
150+
->will($this->returnSelf());
151+
152+
$this->transportBuilderMock->expects($this->once())
153+
->method('getTransport')
154+
->willReturn($transport);
155+
156+
$transport->expects($this->once())
157+
->method('sendMessage');
158+
159+
$this->inlineTranslationMock->expects($this->once())
160+
->method('resume');
115161

116162
$this->observer->scheduledGenerateSitemaps();
117163
}

0 commit comments

Comments
 (0)