diff --git a/app/code/Magento/Braintree/view/frontend/templates/creditcard/edit.phtml b/app/code/Magento/Braintree/view/frontend/templates/creditcard/edit.phtml index 44dc85b5404a1b51b2b3e508cbaa6b575788215e..e866c76a8b5a452899dd74551f151eb6ce54cfe8 100644 --- a/app/code/Magento/Braintree/view/frontend/templates/creditcard/edit.phtml +++ b/app/code/Magento/Braintree/view/frontend/templates/creditcard/edit.phtml @@ -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> diff --git a/app/code/Magento/Paypal/Observer/AddBillingAgreementToSessionObserver.php b/app/code/Magento/Paypal/Observer/AddBillingAgreementToSessionObserver.php index 8bd494207b6b70faa97e1f92b775d13ade60c15f..2cc2425387b134c7c67ce9a3098a8be9ad5056c7 100644 --- a/app/code/Magento/Paypal/Observer/AddBillingAgreementToSessionObserver.php +++ b/app/code/Magento/Paypal/Observer/AddBillingAgreementToSessionObserver.php @@ -53,6 +53,7 @@ class AddBillingAgreementToSessionObserver implements ObserverInterface if ($agreement->isValid()) { $message = __('Created billing agreement #%1.', $agreement->getReferenceId()); $order->addRelatedObject($agreement); + $agreement->addOrderRelation($order); $this->checkoutSession->setLastBillingAgreementReferenceId($agreement->getReferenceId()); $agreementCreated = true; } else { diff --git a/app/code/Magento/Paypal/Test/Unit/Observer/AddBillingAgreementToSessionObserverTest.php b/app/code/Magento/Paypal/Test/Unit/Observer/AddBillingAgreementToSessionObserverTest.php index 7feea45b45d589f6485793750e1fe933a6999152..df0fc80c177e45d516f09cee03777bb887b8b3d5 100644 --- a/app/code/Magento/Paypal/Test/Unit/Observer/AddBillingAgreementToSessionObserverTest.php +++ b/app/code/Magento/Paypal/Test/Unit/Observer/AddBillingAgreementToSessionObserverTest.php @@ -122,6 +122,7 @@ class AddBillingAgreementToSessionObserverTest extends \PHPUnit_Framework_TestCa )->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() diff --git a/app/code/Magento/Paypal/view/frontend/templates/billing/agreement/view.phtml b/app/code/Magento/Paypal/view/frontend/templates/billing/agreement/view.phtml index c026c3fca5e1f8fe7fbcb4a266d1267fe89d9f0b..835f442c0daadfb6a9127ddba69865d20a9ff235 100644 --- a/app/code/Magento/Paypal/view/frontend/templates/billing/agreement/view.phtml +++ b/app/code/Magento/Paypal/view/frontend/templates/billing/agreement/view.phtml @@ -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( diff --git a/app/code/Magento/Review/Block/Product/Review.php b/app/code/Magento/Review/Block/Product/Review.php index b553291cfbf8728ae3865831d2fbf5ee10edb176..02764dc5123f1f59535e6865bb9024a361f9d635 100644 --- a/app/code/Magento/Review/Block/Product/Review.php +++ b/app/code/Magento/Review/Block/Product/Review.php @@ -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 @@ -98,4 +100,14 @@ class Review extends \Magento\Framework\View\Element\Template return $collection->getSize(); } + + /** + * Return unique ID(s) for each object in system + * + * @return array + */ + public function getIdentities() + { + return [\Magento\Review\Model\Review::CACHE_TAG]; + } } diff --git a/app/code/Magento/Review/Model/Rating.php b/app/code/Magento/Review/Model/Rating.php index f9af9a9223ee7bcb99cf2b8b5a50eae449ee8add..f251cf838cc1381e4786a54d40bcbda4db5fe683 100644 --- a/app/code/Magento/Review/Model/Rating.php +++ b/app/code/Magento/Review/Model/Rating.php @@ -5,6 +5,8 @@ */ namespace Magento\Review\Model; +use Magento\Framework\DataObject\IdentityInterface; + /** * Rating model * @@ -18,7 +20,7 @@ namespace Magento\Review\Model; * * @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 @@ -161,4 +163,15 @@ class Rating extends \Magento\Framework\Model\AbstractModel { 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]; + } } diff --git a/app/code/Magento/Review/Model/Review.php b/app/code/Magento/Review/Model/Review.php index a44da6d2f825851d1e65636140c2a8047a491af2..792babfba4e3203a536054c4555cbc48471edd64 100644 --- a/app/code/Magento/Review/Model/Review.php +++ b/app/code/Magento/Review/Model/Review.php @@ -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 */ diff --git a/app/code/Magento/Review/Test/Unit/Block/Product/ReviewTest.php b/app/code/Magento/Review/Test/Unit/Block/Product/ReviewTest.php new file mode 100644 index 0000000000000000000000000000000000000000..0bc6dd49473e2f59ec96f7313e98a4bdc1f32963 --- /dev/null +++ b/app/code/Magento/Review/Test/Unit/Block/Product/ReviewTest.php @@ -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); + } +} diff --git a/app/code/Magento/Review/Test/Unit/Model/RatingTest.php b/app/code/Magento/Review/Test/Unit/Model/RatingTest.php new file mode 100644 index 0000000000000000000000000000000000000000..82db181bedfb56dccf9af12ad10e0ce979e2b7c2 --- /dev/null +++ b/app/code/Magento/Review/Test/Unit/Model/RatingTest.php @@ -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()); + } +}