Skip to content

Commit

Permalink
magento#10045 Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrkwiecinski committed Jul 23, 2017
1 parent 79d15ad commit 6c137a8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public function testGetItemsEmpty()
CmsPageSitemapItemResolver::XML_PATH_PAGE_PRIORITY => '1.0',
]);

$cmsPageCollectionMock = $this->getCmsPageCollectionMock([]);
$cmsPageFactoryMock = $this->getCmsPageFactoryMock($cmsPageCollectionMock);
$cmsPageMock = $this->getCmsPageCollectionMock([]);
$cmsPageFactoryMock = $this->getCmsPageFactoryMock($cmsPageMock);
$itemFactoryMock = $this->getItemFactoryMock();

$resolver = new CmsPageSitemapItemResolver($storeConfigMock, $cmsPageFactoryMock, $itemFactoryMock);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ public function sitemapItemsProvider()
for ($i = 1; $i < 5; $i++) {
$itemProviders = [];
$expectedItems = [];
for ($i = 1; $i < $maxProviders = random_int(1, 5); $i++) {
$maxProviders = random_int(1, 5);
for ($i = 1; $i < $maxProviders; $i++) {
$items = [];
for ($i = 1; $i < $maxItems = random_int(2, 5); $i++) {
$maxItems = random_int(2, 5);
for ($i = 1; $i < $maxItems; $i++) {
$sitemapItem = $this->getMockForAbstractClass(SitemapItemInterface::class);
$items[] = $sitemapItem;
$expectedItems[] = $sitemapItem;
Expand Down
29 changes: 26 additions & 3 deletions app/code/Magento/Sitemap/Test/Unit/Model/SitemapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
namespace Magento\Sitemap\Test\Unit\Model;

use Magento\Sitemap\Model\SitemapItem;
use Magento\Sitemap\Model\SitemapItemResolverInterface;

/**
Expand Down Expand Up @@ -155,9 +156,6 @@ protected function setUp()
);

$this->itemResolverMock = $this->getMockForAbstractClass(SitemapItemResolverInterface::class);
$this->itemResolverMock->expects(self::any())
->method('getItems')
->willReturn([]);
}

/**
Expand Down Expand Up @@ -587,6 +585,31 @@ protected function _getModelMock($mockBeforeSave = false)
);
$this->_sitemapCmsPageMock->expects($this->any())->method('getCollection')->will($this->returnValue([]));

$this->itemResolverMock->expects(self::any())
->method('getItems')
->willReturn([
new SitemapItem('category.html', '1.0', 'daily', '2012-12-21 00:00:00'),
new SitemapItem('/category/sub-category.html', '1.0', 'daily', '2012-12-21 00:00:00'),
new SitemapItem('product.html', '0.5', 'monthly', '2012-12-21 00:00:00'),
new SitemapItem('product2.html', '0.5', 'monthly', '2012-12-21 00:00:00', new \Magento\Framework\DataObject(
[
'collection' => [
new \Magento\Framework\DataObject(
[
'url' => $storeBaseMediaUrl.'i/m/image1.png',
'caption' => 'caption & > title < "'
]
),
new \Magento\Framework\DataObject(
['url' => $storeBaseMediaUrl.'i/m/image_no_caption.png', 'caption' => null]
),
],
'thumbnail' => $storeBaseMediaUrl.'t/h/thumbnail.jpg',
'title' => 'Product & > title < "',
]
))
]);

/** @var $model \Magento\Sitemap\Model\Sitemap */
$model = $this->getMockBuilder(
\Magento\Sitemap\Model\Sitemap::class
Expand Down

0 comments on commit 6c137a8

Please sign in to comment.