19 private $objectManager;
29 private $scopeConfigMock;
34 private $collectionFactoryMock;
39 private $transportBuilderMock;
44 private $storeManagerMock;
49 private $inlineTranslationMock;
54 private $sitemapCollectionMock;
64 private $objectManagerMock;
68 $this->objectManagerMock = $this->getMockBuilder(\
Magento\Framework\ObjectManagerInterface::class)
70 $this->scopeConfigMock = $this->getMockBuilder(\
Magento\Framework\
App\Config\ScopeConfigInterface::class)
72 $this->collectionFactoryMock = $this->getMockBuilder(
74 )->disableOriginalConstructor()
75 ->setMethods([
'create'])
77 $this->transportBuilderMock = $this->getMockBuilder(\
Magento\Framework\Mail\Template\TransportBuilder::class)
78 ->disableOriginalConstructor()
80 $this->storeManagerMock = $this->getMockBuilder(\
Magento\
Store\Model\StoreManagerInterface::class)
82 $this->inlineTranslationMock = $this->getMockBuilder(\
Magento\Framework\Translate\
Inline\StateInterface::class)
84 $this->sitemapCollectionMock = $this->createPartialMock(
88 $this->sitemapMock = $this->createPartialMock(\
Magento\
Sitemap\Model\Sitemap::class, [
'generateXml']);
91 $this->observer = $this->objectManager->getObject(
94 'scopeConfig' => $this->scopeConfigMock,
95 'collectionFactory' => $this->collectionFactoryMock,
96 'storeManager' => $this->storeManagerMock,
97 'transportBuilder' => $this->transportBuilderMock,
98 'inlineTranslation' => $this->inlineTranslationMock
105 $exception =
'Sitemap Exception';
106 $transport = $this->createMock(\
Magento\Framework\Mail\TransportInterface::class);
108 $this->scopeConfigMock->expects($this->once())->method(
'isSetFlag')->willReturn(
true);
110 $this->collectionFactoryMock->expects($this->once())
112 ->willReturn($this->sitemapCollectionMock);
114 $this->sitemapCollectionMock->expects($this->any())
115 ->method(
'getIterator')
116 ->willReturn(
new \ArrayIterator([$this->sitemapMock]));
118 $this->sitemapMock->expects($this->once())
119 ->method(
'generateXml')
120 ->willThrowException(
new \Exception($exception));
122 $this->scopeConfigMock->expects($this->at(1))
130 $this->inlineTranslationMock->expects($this->once())
133 $this->transportBuilderMock->expects($this->once())
134 ->method(
'setTemplateIdentifier')
135 ->will($this->returnSelf());
137 $this->transportBuilderMock->expects($this->once())
138 ->method(
'setTemplateOptions')
140 'area' => \
Magento\Backend\
App\Area\FrontNameResolver::AREA_CODE,
143 ->will($this->returnSelf());
145 $this->transportBuilderMock->expects($this->once())
146 ->method(
'setTemplateVars')
147 ->with([
'warnings' => $exception])
148 ->will($this->returnSelf());
150 $this->transportBuilderMock->expects($this->once())
152 ->will($this->returnSelf());
154 $this->transportBuilderMock->expects($this->once())
156 ->will($this->returnSelf());
158 $this->transportBuilderMock->expects($this->once())
159 ->method(
'getTransport')
160 ->willReturn($transport);
162 $transport->expects($this->once())
163 ->method(
'sendMessage');
165 $this->inlineTranslationMock->expects($this->once())
168 $this->observer->scheduledGenerateSitemaps();
testScheduledGenerateSitemapsSendsExceptionEmail()