-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from magento-mpi/MPI-BUGFIXES
[MPI] Bugfixes
- Loading branch information
Showing
9 changed files
with
235 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
163 changes: 163 additions & 0 deletions
163
app/code/Magento/Review/Test/Unit/Block/Product/ReviewTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
<?php | ||
/** | ||
* Copyright © 2015 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Review\Test\Unit\Block\Product; | ||
|
||
use Magento\Framework\Registry; | ||
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; | ||
use Magento\Framework\View\Element\Template\Context; | ||
use Magento\Catalog\Model\Product; | ||
use Magento\Review\Block\Product\Review as ReviewBlock; | ||
use Magento\Review\Model\ResourceModel\Review\Collection; | ||
use Magento\Review\Model\ResourceModel\Review\CollectionFactory; | ||
use Magento\Review\Model\Review; | ||
use Magento\Store\Model\Store; | ||
use Magento\Store\Model\StoreManager; | ||
|
||
/** | ||
* Class ReviewTest | ||
* @package Magento\Review\Test\Unit\Block\Product | ||
*/ | ||
class ReviewTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var \Magento\Review\Block\Product\Review | ||
*/ | ||
private $block; | ||
|
||
/** | ||
* @var \Magento\Review\Model\ResourceModel\Review\Collection|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $collection; | ||
|
||
/** | ||
* @var \Magento\Review\Model\ResourceModel\Review\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $collectionFactory; | ||
|
||
/** | ||
* @var \Magento\Framework\Registry|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $registry; | ||
|
||
/** | ||
* @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $product; | ||
|
||
/** | ||
* @var \Magento\Store\Model\StoreManager|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $storeManager; | ||
|
||
/** | ||
* @var \Magento\Store\Model\Store|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $store; | ||
|
||
protected function setUp() | ||
{ | ||
$this->initContextMock(); | ||
$this->initRegistryMock(); | ||
$this->initCollectionMocks(); | ||
|
||
$helper = new ObjectManager($this); | ||
$this->block = $helper->getObject(ReviewBlock::class, [ | ||
'storeManager' => $this->storeManager, | ||
'registry' => $this->registry, | ||
'collectionFactory' => $this->collectionFactory, | ||
]); | ||
} | ||
|
||
/** | ||
* @covers \Magento\Review\Block\Product\Review::getIdentities() | ||
*/ | ||
public function testGetIdentities() | ||
{ | ||
static::assertEquals([Review::CACHE_TAG], $this->block->getIdentities()); | ||
} | ||
|
||
/** | ||
* Create mocks for collection and its factory | ||
*/ | ||
private function initCollectionMocks() | ||
{ | ||
$this->collection = $this->getMockBuilder(Collection::class) | ||
->disableOriginalConstructor() | ||
->setMethods(['addStoreFilter', 'addStatusFilter', 'addEntityFilter', 'getSize', '__wakeup']) | ||
->getMock(); | ||
|
||
$this->collection->expects(static::any()) | ||
->method('addStoreFilter') | ||
->willReturnSelf(); | ||
|
||
$this->collection->expects(static::any()) | ||
->method('addStatusFilter') | ||
->with(Review::STATUS_APPROVED) | ||
->willReturnSelf(); | ||
|
||
$this->collection->expects(static::any()) | ||
->method('addEntityFilter') | ||
->willReturnSelf(); | ||
|
||
$this->collectionFactory = $this->getMockBuilder(CollectionFactory::class) | ||
->disableOriginalConstructor() | ||
->setMethods(['create', '__wakeup']) | ||
->getMock(); | ||
|
||
$this->collectionFactory->expects(static::once()) | ||
->method('create') | ||
->willReturn($this->collection); | ||
} | ||
|
||
/** | ||
* Create mock for registry object | ||
*/ | ||
private function initRegistryMock() | ||
{ | ||
$this->initProductMock(); | ||
$this->registry = $this->getMockBuilder(Registry::class) | ||
->disableOriginalConstructor() | ||
->setMethods(['registry']) | ||
->getMock(); | ||
|
||
$this->registry->expects(static::once()) | ||
->method('registry') | ||
->with('product') | ||
->willReturn($this->product); | ||
} | ||
|
||
/** | ||
* Create mock object for catalog product | ||
*/ | ||
private function initProductMock() | ||
{ | ||
$this->product = $this->getMockBuilder(Product::class) | ||
->disableOriginalConstructor() | ||
->setMethods(['getId']) | ||
->getMock(); | ||
} | ||
|
||
/** | ||
* Create mock object for context | ||
*/ | ||
private function initContextMock() | ||
{ | ||
$this->store = $this->getMockBuilder(Store::class) | ||
->disableOriginalConstructor() | ||
->setMethods(['getId', '__wakeup']) | ||
->getMock(); | ||
|
||
$this->storeManager = $this->getMockBuilder(StoreManager::class) | ||
->disableOriginalConstructor() | ||
->setMethods(['getStore', '__wakeup']) | ||
->getMock(); | ||
|
||
$this->storeManager->expects(static::any()) | ||
->method('getStore') | ||
->willReturn($this->store); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
/** | ||
* Copyright © 2015 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Review\Test\Unit\Model; | ||
|
||
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; | ||
use Magento\Review\Model\Review; | ||
use Magento\Review\Model\Rating; | ||
|
||
class RatingTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var \Magento\Review\Model\Rating | ||
*/ | ||
private $rating; | ||
|
||
/** | ||
* Init objects needed by tests | ||
*/ | ||
protected function setUp() | ||
{ | ||
$helper = new ObjectManager($this); | ||
$this->rating = $helper->getObject(Rating::class); | ||
} | ||
|
||
/** | ||
* @covers \Magento\Review\Model\Rating::getIdentities() | ||
* @return void | ||
*/ | ||
public function testGetIdentities() | ||
{ | ||
static::assertEquals([Review::CACHE_TAG], $this->rating->getIdentities()); | ||
} | ||
} |