Example #1
0
 /**
  * Get model mock object
  *
  * @param bool $mockBeforeSave
  * @return \Magento\Sitemap\Model\Sitemap|PHPUnit_Framework_MockObject_MockObject
  */
 protected function _getModelMock($mockBeforeSave = false)
 {
     $methods = ['_construct', '_getResource', '_getBaseDir', '_getFileObject', '_afterSave', '_getStoreBaseUrl', '_getCurrentDateTime', '_getCategoryItemsCollection', '_getProductItemsCollection', '_getPageItemsCollection', '_getDocumentRoot'];
     if ($mockBeforeSave) {
         $methods[] = 'beforeSave';
     }
     $this->_sitemapCategoryMock->expects($this->any())->method('getCollection')->will($this->returnValue([new \Magento\Framework\DataObject(['url' => 'category.html', 'updated_at' => '2012-12-21 00:00:00']), new \Magento\Framework\DataObject(['url' => '/category/sub-category.html', 'updated_at' => '2012-12-21 00:00:00'])]));
     $this->_sitemapProductMock->expects($this->any())->method('getCollection')->will($this->returnValue([new \Magento\Framework\DataObject(['url' => 'product.html', 'updated_at' => '2012-12-21 00:00:00']), new \Magento\Framework\DataObject(['url' => 'product2.html', 'updated_at' => '2012-12-21 00:00:00', 'images' => new \Magento\Framework\DataObject(['collection' => [new \Magento\Framework\DataObject(['url' => 'image1.png', 'caption' => 'caption & > title < "']), new \Magento\Framework\DataObject(['url' => 'image_no_caption.png', 'caption' => null])], 'thumbnail' => 'thumbnail.jpg', 'title' => 'Product & > title < "'])])]));
     $this->_sitemapCmsPageMock->expects($this->any())->method('getCollection')->will($this->returnValue([]));
     /** @var $model \Magento\Sitemap\Model\Sitemap */
     $model = $this->getMockBuilder('Magento\\Sitemap\\Model\\Sitemap')->setMethods($methods)->setConstructorArgs($this->_getModelConstructorArgs())->getMock();
     $model->expects($this->any())->method('_getResource')->will($this->returnValue($this->_resourceMock));
     $model->expects($this->any())->method('_getStoreBaseUrl')->will($this->returnValue('http://store.com/'));
     $model->expects($this->any())->method('_getCurrentDateTime')->will($this->returnValue('2012-12-21T00:00:00-08:00'));
     $model->expects($this->any())->method('_getDocumentRoot')->will($this->returnValue('/project'));
     $model->setSitemapFilename('sitemap.xml');
     $model->setStoreId(1);
     $model->setSitemapPath('/');
     return $model;
 }