23 private $storeResolver;
28 private $sitemapCollectionFactory;
33 private $sitemapHelper;
43 private $eventManagerMock;
48 private $scopeConfigMock;
53 private $storeManager;
57 $this->eventManagerMock = $this->getMockBuilder(\
Magento\Framework\Event\ManagerInterface::class)
58 ->getMockForAbstractClass();
60 $this->scopeConfigMock = $this->getMockBuilder(\
Magento\Framework\
App\Config\ScopeConfigInterface::class)
61 ->getMockForAbstractClass();
63 $this->context = $this->getMockBuilder(\
Magento\Framework\View\Element\Context::class)
64 ->disableOriginalConstructor()
67 $this->context->expects($this->any())
68 ->method(
'getEventManager')
69 ->willReturn($this->eventManagerMock);
71 $this->context->expects($this->any())
72 ->method(
'getScopeConfig')
73 ->willReturn($this->scopeConfigMock);
75 $this->storeResolver = $this->getMockBuilder(\
Magento\Store\Model\StoreResolver::class)
76 ->disableOriginalConstructor()
79 $this->sitemapCollectionFactory = $this->getMockBuilder(
82 ->setMethods([
'create'])
83 ->disableOriginalConstructor()
86 $this->sitemapHelper = $this->getMockBuilder(\
Magento\Sitemap\Helper\Data::class)
87 ->disableOriginalConstructor()
90 $this->storeManager = $this->getMockBuilder(\
Magento\Store\Model\StoreManagerInterface::class)
91 ->getMockForAbstractClass();
93 $this->block = new \Magento\Sitemap\Block\Robots(
96 $this->sitemapCollectionFactory,
108 $defaultWebsiteId = 1;
113 $this->scopeConfigMock->expects($this->once())->method(
'getValue')->willReturn(
false);
115 $storeMock = $this->getMockBuilder(\
Magento\Store\Api\Data\StoreInterface::class)
116 ->getMockForAbstractClass();
118 $storeMock->expects($this->once())
119 ->method(
'getWebsiteId')
120 ->willReturn($defaultWebsiteId);
122 $this->storeManager->expects($this->once())
123 ->method(
'getDefaultStoreView')
124 ->willReturn($storeMock);
126 $storeMock->expects($this->any())
127 ->method(
'getWebsiteId')
128 ->willReturn($defaultWebsiteId);
130 $websiteMock = $this->getMockBuilder(\
Magento\Store\Model\Website::class)
131 ->disableOriginalConstructor()
133 $websiteMock->expects($this->any())
134 ->method(
'getStoreIds')
135 ->willReturn([$defaultStoreId]);
137 $this->storeManager->expects($this->once())
138 ->method(
'getWebsite')
139 ->with($defaultWebsiteId)
140 ->willReturn($websiteMock);
142 $this->sitemapHelper->expects($this->once())
143 ->method(
'getEnableSubmissionRobots')
144 ->with($defaultStoreId)
147 $this->assertEquals($expected, $this->block->toHtml());
157 $defaultWebsiteId = 1;
160 $sitemapFilenameOne =
'sitemap.xml';
161 $sitemapFilenameTwo =
'sitemap_custom.xml';
162 $sitemapFilenameThree =
'sitemap.xml';
164 $expected =
'Sitemap: ' . $sitemapFilenameOne
166 .
'Sitemap: ' . $sitemapFilenameTwo
170 $this->scopeConfigMock->expects($this->once())->method(
'getValue')->willReturn(
false);
172 $storeMock = $this->getMockBuilder(\
Magento\Store\Api\Data\StoreInterface::class)
173 ->getMockForAbstractClass();
175 $this->storeManager->expects($this->once())
176 ->method(
'getDefaultStoreView')
177 ->willReturn($storeMock);
179 $storeMock->expects($this->any())
180 ->method(
'getWebsiteId')
181 ->willReturn($defaultWebsiteId);
183 $websiteMock = $this->getMockBuilder(\
Magento\Store\Model\Website::class)
184 ->disableOriginalConstructor()
186 $websiteMock->expects($this->any())
187 ->method(
'getStoreIds')
190 $this->storeManager->expects($this->once())
191 ->method(
'getWebsite')
192 ->with($defaultWebsiteId)
193 ->willReturn($websiteMock);
195 $this->sitemapHelper->expects($this->any())
196 ->method(
'getEnableSubmissionRobots')
198 [$defaultStoreId,
true],
202 $sitemapMockOne = $this->
getSitemapMock($sitemapPath, $sitemapFilenameOne);
203 $sitemapMockTwo = $this->
getSitemapMock($sitemapPath, $sitemapFilenameTwo);
204 $sitemapMockThree = $this->
getSitemapMock($sitemapPath, $sitemapFilenameThree);
206 $sitemapCollectionMock = $this->getMockBuilder(\
Magento\Sitemap\Model\
ResourceModel\Sitemap\Collection::class)
207 ->disableOriginalConstructor()
209 $sitemapCollectionMock->expects($this->any())
210 ->method(
'addStoreFilter')
211 ->with([$defaultStoreId])
214 $sitemapCollectionMock->expects($this->any())
215 ->method(
'getIterator')
216 ->willReturn(
new \ArrayIterator([$sitemapMockOne, $sitemapMockTwo, $sitemapMockThree]));
218 $this->sitemapCollectionFactory->expects($this->once())
220 ->willReturn($sitemapCollectionMock);
222 $this->assertEquals($expected, $this->block->toHtml());
232 $storeMock = $this->getMockBuilder(\
Magento\Store\Api\Data\StoreInterface::class)->getMockForAbstractClass();
234 $this->storeManager->expects($this->once())
235 ->method(
'getDefaultStoreView')
236 ->willReturn($storeMock);
238 $storeMock->expects($this->once())
245 $this->assertEquals($expected, $this->block->getIdentities());
256 $this->eventManagerMock->expects($this->any())
260 'view_block_abstract_to_html_before',
262 'block' => $this->block,
266 'view_block_abstract_to_html_after',
268 'block' => $this->block,
269 'transport' =>
new \
Magento\Framework\DataObject([
'html' =>
$data]),
284 $sitemapMock = $this->getMockBuilder(\
Magento\Sitemap\Model\Sitemap::class)
285 ->disableOriginalConstructor()
287 'getSitemapFilename',
293 $sitemapMock->expects($this->any())
294 ->method(
'getSitemapFilename')
295 ->willReturn($sitemapFilename);
296 $sitemapMock->expects($this->any())
297 ->method(
'getSitemapPath')
298 ->willReturn($sitemapPath);
299 $sitemapMock->expects($this->any())
300 ->method(
'getSitemapUrl')
301 ->with($sitemapPath, $sitemapFilename)
302 ->willReturn($sitemapFilename);
getSitemapMock($sitemapPath, $sitemapFilename)
testAfterGetDataRobotsSubmissionIsEnabled()
testToHtmlRobotsSubmissionIsDisabled()
initEventManagerMock($data)