From 398d685772f2fe37534bc7356191284ad3d20170 Mon Sep 17 00:00:00 2001 From: Ievgen Sentiabov Date: Tue, 20 Oct 2015 14:21:42 +0300 Subject: [PATCH 1/6] MAGETWO-44113: Creating Ratings in the Frontend (not available after Magento installation) - Added cache skipping after rating entity saving --- app/code/Magento/Review/Model/Rating.php | 16 ++++++++- .../Review/Test/Unit/Model/RatingTest.php | 36 +++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 app/code/Magento/Review/Test/Unit/Model/RatingTest.php diff --git a/app/code/Magento/Review/Model/Rating.php b/app/code/Magento/Review/Model/Rating.php index f9af9a9223ee7..b209b680c8274 100644 --- a/app/code/Magento/Review/Model/Rating.php +++ b/app/code/Magento/Review/Model/Rating.php @@ -5,6 +5,9 @@ */ namespace Magento\Review\Model; +use Magento\Framework\DataObject\IdentityInterface; +use Magento\Store\Model\Store; + /** * Rating model * @@ -18,7 +21,7 @@ * * @author Magento Core Team */ -class Rating extends \Magento\Framework\Model\AbstractModel +class Rating extends \Magento\Framework\Model\AbstractModel implements IdentityInterface { /** * rating entity codes @@ -161,4 +164,15 @@ public function getEntityIdByCode($entityCode) { return $this->getResource()->getEntityIdByCode($entityCode); } + + /** + * Return unique ID(s) for each object in system + * + * @return array + */ + public function getIdentities() + { + // skip cache for all store + return [Store::CACHE_TAG]; + } } 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 0000000000000..bf657b86a6be7 --- /dev/null +++ b/app/code/Magento/Review/Test/Unit/Model/RatingTest.php @@ -0,0 +1,36 @@ +rating = $helper->getObject(Rating::class); + } + + /** + * @covers \Magento\Review\Model\Rating::getIdentities() + * @return void + */ + public function testGetIdentities() + { + static::assertEquals([Store::CACHE_TAG], $this->rating->getIdentities()); + } +} From 5fe41a9590fe141696cee58c96e1c9d8618a86bd Mon Sep 17 00:00:00 2001 From: Ievgen Sentiabov Date: Tue, 20 Oct 2015 15:00:28 +0300 Subject: [PATCH 2/6] MAGETWO-44113: Creating Ratings in the Frontend (not available after Magento installation) - Fixed namespace --- app/code/Magento/Review/Test/Unit/Model/RatingTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Review/Test/Unit/Model/RatingTest.php b/app/code/Magento/Review/Test/Unit/Model/RatingTest.php index bf657b86a6be7..64bf2e99b7dbb 100644 --- a/app/code/Magento/Review/Test/Unit/Model/RatingTest.php +++ b/app/code/Magento/Review/Test/Unit/Model/RatingTest.php @@ -3,7 +3,7 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Review\Model; +namespace Magento\Review\Test\Unit\Model; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\Store\Model\Store; From 4617d920dbef66bb13328dd7747fa4cc206b51a1 Mon Sep 17 00:00:00 2001 From: "Yushkin, Dmytro" Date: Thu, 22 Oct 2015 16:10:18 +0300 Subject: [PATCH 3/6] MAGETWO-44452: Unable to select country while adding new credit card for Braintree --- .../Braintree/view/frontend/templates/creditcard/edit.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 6fcac2eae9c41..05e55e01a5023 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
- escapeHtml($block->countrySelect('credit_card[billing_address][country_code_alpha2]', 'billing_address_country', $default)); ?> + countrySelect('credit_card[billing_address][country_code_alpha2]', 'billing_address_country', $default); ?>
From 0001ee34ce4dc2d903484acbf0b1d8b4caa7b9df Mon Sep 17 00:00:00 2001 From: Ievgen Sentiabov Date: Thu, 22 Oct 2015 18:21:15 +0300 Subject: [PATCH 4/6] MAGETWO-44113: Creating Ratings in the Frontend (not available after Magento installation) - Changed cache tag - Added unit tests --- .../Magento/Review/Block/Product/Review.php | 14 +- app/code/Magento/Review/Model/Rating.php | 5 +- app/code/Magento/Review/Model/Review.php | 5 + .../Test/Unit/Block/Product/ReviewTest.php | 172 ++++++++++++++++++ .../Review/Test/Unit/Model/RatingTest.php | 4 +- 5 files changed, 194 insertions(+), 6 deletions(-) create mode 100644 app/code/Magento/Review/Test/Unit/Block/Product/ReviewTest.php diff --git a/app/code/Magento/Review/Block/Product/Review.php b/app/code/Magento/Review/Block/Product/Review.php index b553291cfbf87..02764dc5123f1 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 */ -class Review extends \Magento\Framework\View\Element\Template +class Review extends Template implements IdentityInterface { /** * Core registry @@ -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]; + } } diff --git a/app/code/Magento/Review/Model/Rating.php b/app/code/Magento/Review/Model/Rating.php index b209b680c8274..f251cf838cc13 100644 --- a/app/code/Magento/Review/Model/Rating.php +++ b/app/code/Magento/Review/Model/Rating.php @@ -6,7 +6,6 @@ namespace Magento\Review\Model; use Magento\Framework\DataObject\IdentityInterface; -use Magento\Store\Model\Store; /** * Rating model @@ -172,7 +171,7 @@ public function getEntityIdByCode($entityCode) */ public function getIdentities() { - // skip cache for all store - return [Store::CACHE_TAG]; + // 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 a44da6d2f8258..792babfba4e32 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 0000000000000..8e0b4b31e97f2 --- /dev/null +++ b/app/code/Magento/Review/Test/Unit/Block/Product/ReviewTest.php @@ -0,0 +1,172 @@ +initContextMock(); + $this->initRegistryMock(); + $this->initCollectionMocks(); + + $helper = new ObjectManager($this); + $this->block = $helper->getObject(ReviewBlock::class, [ + 'context' => $this->contextMock, + 'registry' => $this->registryMock, + 'collectionFactory' => $this->collectionFactoryMock, + ]); + } + + /** + * @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->collectionMock = $this->getMockBuilder(Collection::class) + ->disableOriginalConstructor() + ->setMethods(['addStoreFilter', 'addStatusFilter', 'addEntityFilter', 'getSize', '__wakeup']) + ->getMock(); + + $this->collectionMock->expects(static::any()) + ->method('addStoreFilter') + ->willReturnSelf(); + + $this->collectionMock->expects(static::any()) + ->method('addStatusFilter') + ->with(Review::STATUS_APPROVED) + ->willReturnSelf(); + + $this->collectionMock->expects(static::any()) + ->method('addEntityFilter') + ->willReturnSelf(); + + $this->collectionFactoryMock = $this->getMockBuilder(CollectionFactory::class) + ->disableOriginalConstructor() + ->setMethods(['create', '__wakeup']) + ->getMock(); + + $this->collectionFactoryMock->expects(static::once()) + ->method('create') + ->willReturn($this->collectionMock); + } + + /** + * Create mock for registry object + */ + private function initRegistryMock() + { + $this->initProductMock(); + $this->registryMock = $this->getMockBuilder(Registry::class) + ->disableOriginalConstructor() + ->setMethods(['registry']) + ->getMock(); + + $this->registryMock->expects(static::once()) + ->method('registry') + ->with('product') + ->willReturn($this->productMock); + } + + /** + * Create mock object for catalog product + */ + private function initProductMock() + { + $this->productMock = $this->getMockBuilder(Product::class) + ->disableOriginalConstructor() + ->setMethods(['getId']) + ->getMock(); + } + + /** + * Create mock object for context + */ + private function initContextMock() + { + $this->storeMock = $this->getMockBuilder(Store::class) + ->disableOriginalConstructor() + ->setMethods(['getId', '__wakeup']) + ->getMock(); + + $storeManager = $this->getMockBuilder(StoreManager::class) + ->disableOriginalConstructor() + ->setMethods(['getStore', '__wakeup']) + ->getMock(); + + $storeManager->expects(static::once()) + ->method('getStore') + ->willReturn($this->storeMock); + + $this->contextMock = $this->getMockBuilder(Context::class) + ->disableOriginalConstructor() + ->setMethods(['getStoreManager']) + ->getMock(); + + $this->contextMock->expects(static::once()) + ->method('getStoreManager') + ->willReturn($storeManager); + } +} diff --git a/app/code/Magento/Review/Test/Unit/Model/RatingTest.php b/app/code/Magento/Review/Test/Unit/Model/RatingTest.php index 64bf2e99b7dbb..82db181bedfb5 100644 --- a/app/code/Magento/Review/Test/Unit/Model/RatingTest.php +++ b/app/code/Magento/Review/Test/Unit/Model/RatingTest.php @@ -6,7 +6,7 @@ namespace Magento\Review\Test\Unit\Model; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; -use Magento\Store\Model\Store; +use Magento\Review\Model\Review; use Magento\Review\Model\Rating; class RatingTest extends \PHPUnit_Framework_TestCase @@ -31,6 +31,6 @@ protected function setUp() */ public function testGetIdentities() { - static::assertEquals([Store::CACHE_TAG], $this->rating->getIdentities()); + static::assertEquals([Review::CACHE_TAG], $this->rating->getIdentities()); } } From 6154e186e0faa0a2c382c61d8e3b764971bf4329 Mon Sep 17 00:00:00 2001 From: Ievgen Sentiabov Date: Fri, 23 Oct 2015 10:38:08 +0300 Subject: [PATCH 5/6] MAGETWO-44113: Creating Ratings in the Frontend (not available after Magento installation) - Changed constructor mocks - Refactored code related to code review --- .../Test/Unit/Block/Product/ReviewTest.php | 61 ++++++++----------- 1 file changed, 26 insertions(+), 35 deletions(-) diff --git a/app/code/Magento/Review/Test/Unit/Block/Product/ReviewTest.php b/app/code/Magento/Review/Test/Unit/Block/Product/ReviewTest.php index 8e0b4b31e97f2..0bc6dd49473e2 100644 --- a/app/code/Magento/Review/Test/Unit/Block/Product/ReviewTest.php +++ b/app/code/Magento/Review/Test/Unit/Block/Product/ReviewTest.php @@ -31,32 +31,32 @@ class ReviewTest extends \PHPUnit_Framework_TestCase /** * @var \Magento\Review\Model\ResourceModel\Review\Collection|\PHPUnit_Framework_MockObject_MockObject */ - private $collectionMock; + private $collection; /** * @var \Magento\Review\Model\ResourceModel\Review\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject */ - private $collectionFactoryMock; + private $collectionFactory; /** * @var \Magento\Framework\Registry|\PHPUnit_Framework_MockObject_MockObject */ - private $registryMock; + private $registry; /** * @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject */ - private $productMock; + private $product; /** - * @var \Magento\Framework\View\Element\Template\Context|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Store\Model\StoreManager|\PHPUnit_Framework_MockObject_MockObject */ - private $contextMock; + private $storeManager; /** - * @va rMagento\Store\Model\Store|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Store\Model\Store|\PHPUnit_Framework_MockObject_MockObject */ - private $storeMock; + private $store; protected function setUp() { @@ -66,9 +66,9 @@ protected function setUp() $helper = new ObjectManager($this); $this->block = $helper->getObject(ReviewBlock::class, [ - 'context' => $this->contextMock, - 'registry' => $this->registryMock, - 'collectionFactory' => $this->collectionFactoryMock, + 'storeManager' => $this->storeManager, + 'registry' => $this->registry, + 'collectionFactory' => $this->collectionFactory, ]); } @@ -85,32 +85,32 @@ public function testGetIdentities() */ private function initCollectionMocks() { - $this->collectionMock = $this->getMockBuilder(Collection::class) + $this->collection = $this->getMockBuilder(Collection::class) ->disableOriginalConstructor() ->setMethods(['addStoreFilter', 'addStatusFilter', 'addEntityFilter', 'getSize', '__wakeup']) ->getMock(); - $this->collectionMock->expects(static::any()) + $this->collection->expects(static::any()) ->method('addStoreFilter') ->willReturnSelf(); - $this->collectionMock->expects(static::any()) + $this->collection->expects(static::any()) ->method('addStatusFilter') ->with(Review::STATUS_APPROVED) ->willReturnSelf(); - $this->collectionMock->expects(static::any()) + $this->collection->expects(static::any()) ->method('addEntityFilter') ->willReturnSelf(); - $this->collectionFactoryMock = $this->getMockBuilder(CollectionFactory::class) + $this->collectionFactory = $this->getMockBuilder(CollectionFactory::class) ->disableOriginalConstructor() ->setMethods(['create', '__wakeup']) ->getMock(); - $this->collectionFactoryMock->expects(static::once()) + $this->collectionFactory->expects(static::once()) ->method('create') - ->willReturn($this->collectionMock); + ->willReturn($this->collection); } /** @@ -119,15 +119,15 @@ private function initCollectionMocks() private function initRegistryMock() { $this->initProductMock(); - $this->registryMock = $this->getMockBuilder(Registry::class) + $this->registry = $this->getMockBuilder(Registry::class) ->disableOriginalConstructor() ->setMethods(['registry']) ->getMock(); - $this->registryMock->expects(static::once()) + $this->registry->expects(static::once()) ->method('registry') ->with('product') - ->willReturn($this->productMock); + ->willReturn($this->product); } /** @@ -135,7 +135,7 @@ private function initRegistryMock() */ private function initProductMock() { - $this->productMock = $this->getMockBuilder(Product::class) + $this->product = $this->getMockBuilder(Product::class) ->disableOriginalConstructor() ->setMethods(['getId']) ->getMock(); @@ -146,27 +146,18 @@ private function initProductMock() */ private function initContextMock() { - $this->storeMock = $this->getMockBuilder(Store::class) + $this->store = $this->getMockBuilder(Store::class) ->disableOriginalConstructor() ->setMethods(['getId', '__wakeup']) ->getMock(); - $storeManager = $this->getMockBuilder(StoreManager::class) + $this->storeManager = $this->getMockBuilder(StoreManager::class) ->disableOriginalConstructor() ->setMethods(['getStore', '__wakeup']) ->getMock(); - $storeManager->expects(static::once()) + $this->storeManager->expects(static::any()) ->method('getStore') - ->willReturn($this->storeMock); - - $this->contextMock = $this->getMockBuilder(Context::class) - ->disableOriginalConstructor() - ->setMethods(['getStoreManager']) - ->getMock(); - - $this->contextMock->expects(static::once()) - ->method('getStoreManager') - ->willReturn($storeManager); + ->willReturn($this->store); } } From 6211bbc3c2c93263ffcf06df123a78ee15b364bf Mon Sep 17 00:00:00 2001 From: Viktor Tymchynskyi Date: Fri, 23 Oct 2015 15:36:42 +0300 Subject: [PATCH 6/6] MAGETWO-44496: Paypal billing agreement order relation table is empty --- .../Paypal/Observer/AddBillingAgreementToSessionObserver.php | 1 + .../Unit/Observer/AddBillingAgreementToSessionObserverTest.php | 1 + .../Paypal/view/frontend/templates/billing/agreement/view.phtml | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Paypal/Observer/AddBillingAgreementToSessionObserver.php b/app/code/Magento/Paypal/Observer/AddBillingAgreementToSessionObserver.php index 8bd494207b6b7..2cc2425387b13 100644 --- a/app/code/Magento/Paypal/Observer/AddBillingAgreementToSessionObserver.php +++ b/app/code/Magento/Paypal/Observer/AddBillingAgreementToSessionObserver.php @@ -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 { diff --git a/app/code/Magento/Paypal/Test/Unit/Observer/AddBillingAgreementToSessionObserverTest.php b/app/code/Magento/Paypal/Test/Unit/Observer/AddBillingAgreementToSessionObserverTest.php index 7feea45b45d58..df0fc80c177e4 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 @@ 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() 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 c026c3fca5e1f..835f442c0daad 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(); )); ?> - escapeHtml($block->getOrderItemValue($order, 'order_total')); ?> + getOrderItemValue($order, 'order_total'); ?> escapeHtml($block->getOrderItemValue(