Skip to content

Commit

Permalink
Merge pull request #43 from magento-mpi/MPI-BUGFIXES
Browse files Browse the repository at this point in the history
[MPI] Bugfixes
  • Loading branch information
Tymchynskyi, Viktor(vtymchynskyi) committed Oct 25, 2015
2 parents 4499554 + 8474b03 commit 5d9f8b3
Show file tree
Hide file tree
Showing 9 changed files with 235 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ $serializedFormData = $this->helper('Magento\Framework\Json\Helper\Data')->jsonE
</label>

<div class="control">
<?php echo $block->escapeHtml($block->countrySelect('credit_card[billing_address][country_code_alpha2]', 'billing_address_country', $default)); ?>
<?php /* @noEscape */ echo $block->countrySelect('credit_card[billing_address][country_code_alpha2]', 'billing_address_country', $default); ?>
</div>
</div>
</fieldset>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function execute(EventObserver $observer)
if ($agreement->isValid()) {
$message = __('Created billing agreement #%1.', $agreement->getReferenceId());
$order->addRelatedObject($agreement);
$agreement->addOrderRelation($order);
$this->checkoutSession->setLastBillingAgreementReferenceId($agreement->getReferenceId());
$agreementCreated = true;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public function testAddBillingAgreementToSession($isValid)
)->will(
$this->returnValue('agreement reference id')
);
$agreement->expects($this->once())->method('addOrderRelation')->with($order);
$order->expects(new MethodInvokedAtIndex(0))->method('addRelatedObject')->with($agreement);
$this->_checkoutSession->expects(
$this->once()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ $relatedOrders = $block->getRelatedOrders();
)); ?>
</td>
<td data-th="<?php echo $block->escapeHtml(__('Order Total')); ?>" class="col total">
<?php echo $block->escapeHtml($block->getOrderItemValue($order, 'order_total')); ?>
<?php /* @noEscape */ echo $block->getOrderItemValue($order, 'order_total'); ?>
</td>
<td data-th="<?php echo $block->escapeHtml(__('Order Status')); ?>" class="col status">
<?php echo $block->escapeHtml($block->getOrderItemValue(
Expand Down
14 changes: 13 additions & 1 deletion app/code/Magento/Review/Block/Product/Review.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
*/
namespace Magento\Review\Block\Product;

use Magento\Framework\DataObject\IdentityInterface;
use Magento\Framework\View\Element\Template;

/**
* Product Review Tab
*
* @author Magento Core Team <core@magentocommerce.com>
*/
class Review extends \Magento\Framework\View\Element\Template
class Review extends Template implements IdentityInterface
{
/**
* Core registry
Expand Down Expand Up @@ -98,4 +100,14 @@ public function getCollectionSize()

return $collection->getSize();
}

/**
* Return unique ID(s) for each object in system
*
* @return array
*/
public function getIdentities()
{
return [\Magento\Review\Model\Review::CACHE_TAG];
}
}
15 changes: 14 additions & 1 deletion app/code/Magento/Review/Model/Rating.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
namespace Magento\Review\Model;

use Magento\Framework\DataObject\IdentityInterface;

/**
* Rating model
*
Expand All @@ -18,7 +20,7 @@
*
* @author Magento Core Team <core@magentocommerce.com>
*/
class Rating extends \Magento\Framework\Model\AbstractModel
class Rating extends \Magento\Framework\Model\AbstractModel implements IdentityInterface
{
/**
* rating entity codes
Expand Down Expand Up @@ -161,4 +163,15 @@ public function getEntityIdByCode($entityCode)
{
return $this->getResource()->getEntityIdByCode($entityCode);
}

/**
* Return unique ID(s) for each object in system
*
* @return array
*/
public function getIdentities()
{
// clear cache for all reviews
return [Review::CACHE_TAG];
}
}
5 changes: 5 additions & 0 deletions app/code/Magento/Review/Model/Review.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ class Review extends \Magento\Framework\Model\AbstractModel implements IdentityI
*/
protected $_eventPrefix = 'review';

/**
* Cache tag
*/
const CACHE_TAG = 'review_block';

/**
* Product entity review code
*/
Expand Down
163 changes: 163 additions & 0 deletions app/code/Magento/Review/Test/Unit/Block/Product/ReviewTest.php
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);
}
}
36 changes: 36 additions & 0 deletions app/code/Magento/Review/Test/Unit/Model/RatingTest.php
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());
}
}

0 comments on commit 5d9f8b3

Please sign in to comment.