From 472ff521a97b7a20bb8b6eecaa68524865e6f858 Mon Sep 17 00:00:00 2001 From: azambon Date: Thu, 17 Mar 2016 11:59:11 +0100 Subject: [PATCH 01/22] Fixes MAGETWO-49425 ( #3448 ) Fixes a wrong type hint. See https://github.com/magento/magento2/issues/3448 for further details. --- .../Customer/Block/Address/Renderer/DefaultRenderer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Customer/Block/Address/Renderer/DefaultRenderer.php b/app/code/Magento/Customer/Block/Address/Renderer/DefaultRenderer.php index 74084a8d602f0..9cd8961c17aea 100644 --- a/app/code/Magento/Customer/Block/Address/Renderer/DefaultRenderer.php +++ b/app/code/Magento/Customer/Block/Address/Renderer/DefaultRenderer.php @@ -91,11 +91,11 @@ public function setType(\Magento\Framework\DataObject $type) } /** - * @param AbstractAddress|null $address + * @param AddressModelInterface|null $address * @return string * All new code should use renderArray based on Metadata service */ - public function getFormat(AbstractAddress $address = null) + public function getFormat(AddressModelInterface $address = null) { $countryFormat = $address === null ? false : $address->getCountryModel()->getFormat( From 3e34ba088797c05daa456685510f1579d1230923 Mon Sep 17 00:00:00 2001 From: Stefan Doorn Date: Mon, 29 Feb 2016 15:36:12 +0100 Subject: [PATCH 02/22] Insert design/footer/absolute_footer before tag --- app/code/Magento/Theme/Block/Html/Footer.php | 23 +++++++++++++++++++ .../Theme/view/frontend/layout/default.xml | 3 +++ .../templates/html/absolute_footer.phtml | 7 ++++++ 3 files changed, 33 insertions(+) create mode 100644 app/code/Magento/Theme/view/frontend/templates/html/absolute_footer.phtml diff --git a/app/code/Magento/Theme/Block/Html/Footer.php b/app/code/Magento/Theme/Block/Html/Footer.php index 6aeca914b2452..a3ff551c35dbe 100644 --- a/app/code/Magento/Theme/Block/Html/Footer.php +++ b/app/code/Magento/Theme/Block/Html/Footer.php @@ -19,6 +19,13 @@ class Footer extends \Magento\Framework\View\Element\Template implements \Magent */ protected $_copyright; + /** + * Miscellaneous HTML information + * + * @var string + */ + private $miscellaneousHtml; + /** * @var \Magento\Framework\App\Http\Context */ @@ -85,6 +92,22 @@ public function getCopyright() return $this->_copyright; } + /** + * Retrieve Miscellaneous HTML information + * + * @return string + */ + public function getMiscellaneousHtml() + { + if ($this->miscellaneousHtml === null) { + $this->miscellaneousHtml = $this->_scopeConfig->getValue( + 'design/footer/absolute_footer', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + } + return $this->miscellaneousHtml; + } + /** * Return identifiers for produced content * diff --git a/app/code/Magento/Theme/view/frontend/layout/default.xml b/app/code/Magento/Theme/view/frontend/layout/default.xml index 38be75897aeb7..a2e89afcce1ee 100644 --- a/app/code/Magento/Theme/view/frontend/layout/default.xml +++ b/app/code/Magento/Theme/view/frontend/layout/default.xml @@ -122,6 +122,9 @@ + + + diff --git a/app/code/Magento/Theme/view/frontend/templates/html/absolute_footer.phtml b/app/code/Magento/Theme/view/frontend/templates/html/absolute_footer.phtml new file mode 100644 index 0000000000000..e9c9fc7d681c4 --- /dev/null +++ b/app/code/Magento/Theme/view/frontend/templates/html/absolute_footer.phtml @@ -0,0 +1,7 @@ + +getMiscellaneousHtml() ?> \ No newline at end of file From 5e9691dc88d2d47be1d127f386d2f619839e3a24 Mon Sep 17 00:00:00 2001 From: Oleksandr Karpenko Date: Thu, 5 May 2016 17:52:58 +0300 Subject: [PATCH 03/22] MAGETWO-51905: [Github] Footer Miscellaneous HTML Not working #3333 --- .../Theme/view/frontend/templates/html/absolute_footer.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Theme/view/frontend/templates/html/absolute_footer.phtml b/app/code/Magento/Theme/view/frontend/templates/html/absolute_footer.phtml index e9c9fc7d681c4..f9c9f14e3e413 100644 --- a/app/code/Magento/Theme/view/frontend/templates/html/absolute_footer.phtml +++ b/app/code/Magento/Theme/view/frontend/templates/html/absolute_footer.phtml @@ -4,4 +4,4 @@ * See COPYING.txt for license details. */ ?> -getMiscellaneousHtml() ?> \ No newline at end of file +getMiscellaneousHtml() ?> From 0b47c71947ede18d68af14775ee7aca2086f29b9 Mon Sep 17 00:00:00 2001 From: Oleksandr Karpenko Date: Fri, 6 May 2016 11:51:48 +0300 Subject: [PATCH 04/22] MAGETWO-51905: [Github] Footer Miscellaneous HTML Not working #3333 --- lib/internal/Magento/Framework/View/Element/AbstractBlock.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/View/Element/AbstractBlock.php b/lib/internal/Magento/Framework/View/Element/AbstractBlock.php index d06a42c42876f..1700186de7b20 100644 --- a/lib/internal/Magento/Framework/View/Element/AbstractBlock.php +++ b/lib/internal/Magento/Framework/View/Element/AbstractBlock.php @@ -1044,7 +1044,7 @@ protected function _loadCache() */ protected function _saveCache($data) { - if ($this->getCacheLifetime() === null || !$this->_cacheState->isEnabled(self::CACHE_GROUP)) { + if (!$this->getCacheLifetime() || !$this->_cacheState->isEnabled(self::CACHE_GROUP)) { return false; } $cacheKey = $this->getCacheKey(); From d46fb127e63639dea113811c4a8a0056fa3421e3 Mon Sep 17 00:00:00 2001 From: Oleksandr Karpenko Date: Fri, 6 May 2016 12:23:33 +0300 Subject: [PATCH 05/22] MAGETWO-51905: [Github] Footer Miscellaneous HTML Not working #3333 --- .../Theme/view/frontend/templates/html/absolute_footer.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Theme/view/frontend/templates/html/absolute_footer.phtml b/app/code/Magento/Theme/view/frontend/templates/html/absolute_footer.phtml index f9c9f14e3e413..db52d570dee08 100644 --- a/app/code/Magento/Theme/view/frontend/templates/html/absolute_footer.phtml +++ b/app/code/Magento/Theme/view/frontend/templates/html/absolute_footer.phtml @@ -4,4 +4,4 @@ * See COPYING.txt for license details. */ ?> -getMiscellaneousHtml() ?> +getMiscellaneousHtml(); From fc1d8e4158c27ca6c0907a085b2047f09c0fe49c Mon Sep 17 00:00:00 2001 From: Oleksandr Karpenko Date: Fri, 6 May 2016 18:02:02 +0300 Subject: [PATCH 06/22] MAGETWO-49767: Merchant can't save & continue editing the Design Configuration --- .../Config/Edit/SaveAndContinueButton.php | 30 +++++++++++++++++++ .../Design/Config/Edit/SaveButton.php | 2 +- .../Adminhtml/Design/Config/Save.php | 4 +++ .../Adminhtml/Design/Config/SaveTest.php | 15 ++++++---- .../ui_component/design_config_form.xml | 1 + 5 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 app/code/Magento/Theme/Block/Adminhtml/Design/Config/Edit/SaveAndContinueButton.php diff --git a/app/code/Magento/Theme/Block/Adminhtml/Design/Config/Edit/SaveAndContinueButton.php b/app/code/Magento/Theme/Block/Adminhtml/Design/Config/Edit/SaveAndContinueButton.php new file mode 100644 index 0000000000000..7a7bfb181e735 --- /dev/null +++ b/app/code/Magento/Theme/Block/Adminhtml/Design/Config/Edit/SaveAndContinueButton.php @@ -0,0 +1,30 @@ + __('Save and Continue'), + 'class' => 'save', + 'data_attribute' => [ + 'mage-init' => [ + 'button' => ['event' => 'saveAndContinue'], + ], + 'form-role' => 'saveAndContinue' + ], + 'sort_order' => 15, + ]; + } +} diff --git a/app/code/Magento/Theme/Block/Adminhtml/Design/Config/Edit/SaveButton.php b/app/code/Magento/Theme/Block/Adminhtml/Design/Config/Edit/SaveButton.php index 441f689026fb4..2a8208023f108 100644 --- a/app/code/Magento/Theme/Block/Adminhtml/Design/Config/Edit/SaveButton.php +++ b/app/code/Magento/Theme/Block/Adminhtml/Design/Config/Edit/SaveButton.php @@ -15,7 +15,7 @@ class SaveButton implements ButtonProviderInterface public function getButtonData() { return [ - 'label' => __('Save'), + 'label' => __('Save Configuration'), 'class' => 'save primary', 'data_attribute' => [ 'mage-init' => ['button' => ['event' => 'save']], diff --git a/app/code/Magento/Theme/Controller/Adminhtml/Design/Config/Save.php b/app/code/Magento/Theme/Controller/Adminhtml/Design/Config/Save.php index 6ecacda473d1f..1ac0817912a99 100644 --- a/app/code/Magento/Theme/Controller/Adminhtml/Design/Config/Save.php +++ b/app/code/Magento/Theme/Controller/Adminhtml/Design/Config/Save.php @@ -74,7 +74,11 @@ public function execute() $this->dataPersistor->clear('theme_design_config'); + $returnToEdit = (bool)$this->getRequest()->getParam('back', false); $resultRedirect->setPath('theme/design_config/'); + if ($returnToEdit) { + $resultRedirect->setPath('theme/design_config/edit', ['scope' => $scope, 'scope_id' => $scopeId]); + } return $resultRedirect; } catch (LocalizedException $e) { $messages = explode("\n", $e->getMessage()); diff --git a/app/code/Magento/Theme/Test/Unit/Controller/Adminhtml/Design/Config/SaveTest.php b/app/code/Magento/Theme/Test/Unit/Controller/Adminhtml/Design/Config/SaveTest.php index 9741033020a66..cd63f1afaeb0a 100644 --- a/app/code/Magento/Theme/Test/Unit/Controller/Adminhtml/Design/Config/SaveTest.php +++ b/app/code/Magento/Theme/Test/Unit/Controller/Adminhtml/Design/Config/SaveTest.php @@ -112,15 +112,17 @@ public function testSave() $this->redirectFactory->expects($this->once()) ->method('create') ->willReturn($this->redirect); - $this->request->expects($this->exactly(2)) + $this->request->expects($this->exactly(3)) ->method('getParam') ->withConsecutive( ['scope'], - ['scope_id'] + ['scope_id'], + ['back', false] ) ->willReturnOnConsecutiveCalls( $scope, - $scopeId + $scopeId, + true ); $this->request->expects($this->once()) ->method('getParams') @@ -150,9 +152,12 @@ public function testSave() $this->dataPersistor->expects($this->once()) ->method('clear') ->with('theme_design_config'); - $this->redirect->expects($this->once()) + $this->redirect->expects($this->exactly(2)) ->method('setPath') - ->with('theme/design_config/'); + ->withConsecutive( + ['theme/design_config/'], + ['theme/design_config/edit', ['scope' => $scope, 'scope_id' => $scopeId]] + ); $this->assertSame($this->redirect, $this->controller->execute()); } diff --git a/app/code/Magento/Theme/view/adminhtml/ui_component/design_config_form.xml b/app/code/Magento/Theme/view/adminhtml/ui_component/design_config_form.xml index 1faeadc733107..696449889d6b2 100644 --- a/app/code/Magento/Theme/view/adminhtml/ui_component/design_config_form.xml +++ b/app/code/Magento/Theme/view/adminhtml/ui_component/design_config_form.xml @@ -20,6 +20,7 @@ Magento\Theme\Block\Adminhtml\Design\Config\Edit\BackButton Magento\Theme\Block\Adminhtml\Design\Config\Edit\SaveButton + Magento\Theme\Block\Adminhtml\Design\Config\Edit\SaveAndContinueButton From eb5a041e5a4b873d23e9c06cec3ce3aa32ac296e Mon Sep 17 00:00:00 2001 From: Volodymyr Sevostianov Date: Fri, 6 May 2016 18:02:19 +0300 Subject: [PATCH 07/22] MAGETWO-52599: Fix CreateTaxWithFptTestVariation9 and CreateTaxWithFptTestVariation10 tests --- .../tests/app/Magento/Weee/Test/Block/Product/Price.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tests/functional/tests/app/Magento/Weee/Test/Block/Product/Price.php b/dev/tests/functional/tests/app/Magento/Weee/Test/Block/Product/Price.php index 7442961aaf750..ebe5f5716e080 100644 --- a/dev/tests/functional/tests/app/Magento/Weee/Test/Block/Product/Price.php +++ b/dev/tests/functional/tests/app/Magento/Weee/Test/Block/Product/Price.php @@ -18,7 +18,7 @@ class Price extends \Magento\Catalog\Test\Block\AbstractPriceBlock */ protected $mapTypePrices = [ 'regular_price' => [ - 'selector' => '[data-price-type="finalPrice"] .price', + 'selector' => '.price-wrapper', ], 'fpt_price' => [ 'selector' => '[data-price-type="weee"] .price', From f92330d520e2d7f6dcddfae517b8f38e15ffc7ca Mon Sep 17 00:00:00 2001 From: Volodymyr Sevostianov Date: Tue, 10 May 2016 12:20:57 +0300 Subject: [PATCH 08/22] MAGETWO-51917: Fix date formats for CreateCustomerBackendEntityTest and UpdateCustomerBackendEntityTest --- .../Test/TestCase/UpdateCustomerBackendEntityTest.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dev/tests/functional/tests/app/Magento/Customer/Test/TestCase/UpdateCustomerBackendEntityTest.xml b/dev/tests/functional/tests/app/Magento/Customer/Test/TestCase/UpdateCustomerBackendEntityTest.xml index c727b8739c769..e6bf2b6691c0f 100644 --- a/dev/tests/functional/tests/app/Magento/Customer/Test/TestCase/UpdateCustomerBackendEntityTest.xml +++ b/dev/tests/functional/tests/app/Magento/Customer/Test/TestCase/UpdateCustomerBackendEntityTest.xml @@ -16,7 +16,7 @@ Doe%isolation% _Suffix%isolation% JohnDoe%isolation%@example.com - Aug 01, 1986 + Aug 1, 1986 123456789001 Male @@ -52,7 +52,7 @@ Doe%isolation% _JaneSuffix%isolation% Jane%isolation%@example.com - Dec 01, 2000 + Dec 1, 2000 987654321 Female Prefix%isolation%_ From 627b68c7741bb655aff364b3c8af45d2afaa3c43 Mon Sep 17 00:00:00 2001 From: Oleksandr Karpenko Date: Wed, 11 May 2016 13:53:07 +0300 Subject: [PATCH 09/22] MAGETWO-52593: Minicart does not clean when customer session is over --- .../Customer/Model/Plugin/SessionChecker.php | 53 ++++++++++++ .../Unit/Model/Plugin/SessionCheckerTest.php | 82 +++++++++++++++++++ app/code/Magento/Customer/etc/frontend/di.xml | 3 + 3 files changed, 138 insertions(+) create mode 100644 app/code/Magento/Customer/Model/Plugin/SessionChecker.php create mode 100644 app/code/Magento/Customer/Test/Unit/Model/Plugin/SessionCheckerTest.php diff --git a/app/code/Magento/Customer/Model/Plugin/SessionChecker.php b/app/code/Magento/Customer/Model/Plugin/SessionChecker.php new file mode 100644 index 0000000000000..ff24050af75a9 --- /dev/null +++ b/app/code/Magento/Customer/Model/Plugin/SessionChecker.php @@ -0,0 +1,53 @@ +cookieManager = $cookieManager; + $this->cookieMetadataFactory = $cookieMetadataFactory; + } + + /** + * Delete frontend session cookie if customer session is expired + * + * @param Session $session + * @param bool $isLoggedIn + * @return bool + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function afterIsLoggedIn(Session $session, $isLoggedIn) + { + if (!$isLoggedIn) { + $metadata = $this->cookieMetadataFactory->createCookieMetadata(); + $metadata->setPath('/'); + $this->cookieManager->deleteCookie('mage-cache-sessid', $metadata); + } + return $isLoggedIn; + } +} diff --git a/app/code/Magento/Customer/Test/Unit/Model/Plugin/SessionCheckerTest.php b/app/code/Magento/Customer/Test/Unit/Model/Plugin/SessionCheckerTest.php new file mode 100644 index 0000000000000..168549547d52c --- /dev/null +++ b/app/code/Magento/Customer/Test/Unit/Model/Plugin/SessionCheckerTest.php @@ -0,0 +1,82 @@ +cookieManager = $this->getMockBuilder('Magento\Framework\Stdlib\Cookie\PhpCookieManager') + ->disableOriginalConstructor() + ->getMock(); + $this->metadataFactory = $this->getMockBuilder('Magento\Framework\Stdlib\Cookie\CookieMetadataFactory') + ->disableOriginalConstructor() + ->getMock(); + $this->metadata = $this->getMockBuilder('Magento\Framework\Stdlib\Cookie\CookieMetadata') + ->disableOriginalConstructor() + ->getMock(); + $this->session = $this->getMockBuilder('Magento\Customer\Model\Session') + ->disableOriginalConstructor() + ->getMock(); + + $this->plugin = new SessionChecker($this->cookieManager, $this->metadataFactory); + } + + /** + * @param bool $result + * @param string $callCount + * @return void + * @dataProvider testAfterIsLoggedInDataProvider + */ + public function testAfterIsLoggedIn($result, $callCount) + { + $this->metadataFactory->expects($this->{$callCount}()) + ->method('createCookieMetadata') + ->willReturn($this->metadata); + $this->metadata->expects($this->{$callCount}()) + ->method('setPath') + ->with('/'); + $this->cookieManager->expects($this->{$callCount}()) + ->method('deleteCookie') + ->with('mage-cache-sessid', $this->metadata); + $this->assertEquals($result, $this->plugin->afterIsLoggedIn($this->session, $result)); + } + + public function testAfterIsLoggedInDataProvider() + { + return [ + [false, 'once'], + [true, 'never'] + ]; + } +} diff --git a/app/code/Magento/Customer/etc/frontend/di.xml b/app/code/Magento/Customer/etc/frontend/di.xml index 673bb132f1db3..948977901369d 100644 --- a/app/code/Magento/Customer/etc/frontend/di.xml +++ b/app/code/Magento/Customer/etc/frontend/di.xml @@ -57,4 +57,7 @@ + + + From fffb4e6b9a7be9ba6b2c738a3d98aa871a2983e0 Mon Sep 17 00:00:00 2001 From: Oleksandr Karpenko Date: Wed, 11 May 2016 15:02:00 +0300 Subject: [PATCH 10/22] MAGETWO-52593: Minicart does not clean when customer session is over --- .../{Model/Plugin => CustomerData}/SessionChecker.php | 2 +- .../{Model/Plugin => CustomerData}/SessionCheckerTest.php | 4 ++-- app/code/Magento/Customer/etc/frontend/di.xml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) rename app/code/Magento/Customer/{Model/Plugin => CustomerData}/SessionChecker.php (97%) rename app/code/Magento/Customer/Test/Unit/{Model/Plugin => CustomerData}/SessionCheckerTest.php (96%) diff --git a/app/code/Magento/Customer/Model/Plugin/SessionChecker.php b/app/code/Magento/Customer/CustomerData/SessionChecker.php similarity index 97% rename from app/code/Magento/Customer/Model/Plugin/SessionChecker.php rename to app/code/Magento/Customer/CustomerData/SessionChecker.php index ff24050af75a9..8536dc48a644b 100644 --- a/app/code/Magento/Customer/Model/Plugin/SessionChecker.php +++ b/app/code/Magento/Customer/CustomerData/SessionChecker.php @@ -3,7 +3,7 @@ * Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Customer\Model\Plugin; +namespace Magento\Customer\CustomerData; use Magento\Customer\Model\Session; use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory; diff --git a/app/code/Magento/Customer/Test/Unit/Model/Plugin/SessionCheckerTest.php b/app/code/Magento/Customer/Test/Unit/CustomerData/SessionCheckerTest.php similarity index 96% rename from app/code/Magento/Customer/Test/Unit/Model/Plugin/SessionCheckerTest.php rename to app/code/Magento/Customer/Test/Unit/CustomerData/SessionCheckerTest.php index 168549547d52c..a75bb5ecf6feb 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Plugin/SessionCheckerTest.php +++ b/app/code/Magento/Customer/Test/Unit/CustomerData/SessionCheckerTest.php @@ -3,9 +3,9 @@ * Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Customer\Test\Unit\Model\Plugin; +namespace Magento\Customer\Test\Unit\CustomerData; -use Magento\Customer\Model\Plugin\SessionChecker; +use Magento\Customer\CustomerData\SessionChecker; class SessionCheckerTest extends \PHPUnit_Framework_TestCase { diff --git a/app/code/Magento/Customer/etc/frontend/di.xml b/app/code/Magento/Customer/etc/frontend/di.xml index 948977901369d..ebebf2745f848 100644 --- a/app/code/Magento/Customer/etc/frontend/di.xml +++ b/app/code/Magento/Customer/etc/frontend/di.xml @@ -58,6 +58,6 @@ - + From 479fe7ceb4b75bf2b88600ca531c25d0a27c1796 Mon Sep 17 00:00:00 2001 From: Oleksandr Karpenko Date: Wed, 11 May 2016 17:15:47 +0300 Subject: [PATCH 11/22] MAGETWO-52593: Minicart does not clean when customer session is over --- .../Customer/CustomerData/{ => Plugin}/SessionChecker.php | 2 +- .../Unit/CustomerData/{ => Plugin}/SessionCheckerTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename app/code/Magento/Customer/CustomerData/{ => Plugin}/SessionChecker.php (96%) rename app/code/Magento/Customer/Test/Unit/CustomerData/{ => Plugin}/SessionCheckerTest.php (95%) diff --git a/app/code/Magento/Customer/CustomerData/SessionChecker.php b/app/code/Magento/Customer/CustomerData/Plugin/SessionChecker.php similarity index 96% rename from app/code/Magento/Customer/CustomerData/SessionChecker.php rename to app/code/Magento/Customer/CustomerData/Plugin/SessionChecker.php index 8536dc48a644b..c0afcbf95ab16 100644 --- a/app/code/Magento/Customer/CustomerData/SessionChecker.php +++ b/app/code/Magento/Customer/CustomerData/Plugin/SessionChecker.php @@ -3,7 +3,7 @@ * Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Customer\CustomerData; +namespace Magento\Customer\CustomerData\Plugin; use Magento\Customer\Model\Session; use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory; diff --git a/app/code/Magento/Customer/Test/Unit/CustomerData/SessionCheckerTest.php b/app/code/Magento/Customer/Test/Unit/CustomerData/Plugin/SessionCheckerTest.php similarity index 95% rename from app/code/Magento/Customer/Test/Unit/CustomerData/SessionCheckerTest.php rename to app/code/Magento/Customer/Test/Unit/CustomerData/Plugin/SessionCheckerTest.php index a75bb5ecf6feb..72880a36db59a 100644 --- a/app/code/Magento/Customer/Test/Unit/CustomerData/SessionCheckerTest.php +++ b/app/code/Magento/Customer/Test/Unit/CustomerData/Plugin/SessionCheckerTest.php @@ -3,9 +3,9 @@ * Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Customer\Test\Unit\CustomerData; +namespace Magento\Customer\Test\Unit\CustomerData\Plugin; -use Magento\Customer\CustomerData\SessionChecker; +use Magento\Customer\CustomerData\Plugin\SessionChecker; class SessionCheckerTest extends \PHPUnit_Framework_TestCase { From d24cf2e3e6c4d8e523bb1afbe8764beebb097295 Mon Sep 17 00:00:00 2001 From: Oleksandr Karpenko Date: Wed, 11 May 2016 17:16:22 +0300 Subject: [PATCH 12/22] MAGETWO-52593: Minicart does not clean when customer session is over --- app/code/Magento/Customer/etc/frontend/di.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Customer/etc/frontend/di.xml b/app/code/Magento/Customer/etc/frontend/di.xml index ebebf2745f848..2837805a29bf8 100644 --- a/app/code/Magento/Customer/etc/frontend/di.xml +++ b/app/code/Magento/Customer/etc/frontend/di.xml @@ -58,6 +58,6 @@ - + From 6bffec6cc92095d9b47a7c2d386044016d5b86f9 Mon Sep 17 00:00:00 2001 From: Oleksandr Karpenko Date: Thu, 12 May 2016 13:27:50 +0300 Subject: [PATCH 13/22] MAGETWO-52593: Minicart does not clean when customer session is over --- .../CustomerData/Plugin/SessionChecker.php | 20 ++++++++++++------- .../Plugin/SessionCheckerTest.php | 18 ++++++++++++++--- app/code/Magento/Customer/etc/frontend/di.xml | 2 +- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/app/code/Magento/Customer/CustomerData/Plugin/SessionChecker.php b/app/code/Magento/Customer/CustomerData/Plugin/SessionChecker.php index c0afcbf95ab16..8f46ab14784a0 100644 --- a/app/code/Magento/Customer/CustomerData/Plugin/SessionChecker.php +++ b/app/code/Magento/Customer/CustomerData/Plugin/SessionChecker.php @@ -6,6 +6,7 @@ namespace Magento\Customer\CustomerData\Plugin; use Magento\Customer\Model\Session; +use Magento\Framework\App\Response\Http; use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory; use Magento\Framework\Stdlib\Cookie\PhpCookieManager; @@ -21,33 +22,38 @@ class SessionChecker */ private $cookieMetadataFactory; + /** + * @var Session + */ + private $session; + /** * @param PhpCookieManager $cookieManager * @param CookieMetadataFactory $cookieMetadataFactory + * @param Session $session */ public function __construct( PhpCookieManager $cookieManager, - CookieMetadataFactory $cookieMetadataFactory + CookieMetadataFactory $cookieMetadataFactory, + Session $session ) { $this->cookieManager = $cookieManager; $this->cookieMetadataFactory = $cookieMetadataFactory; + $this->session = $session; } /** * Delete frontend session cookie if customer session is expired * - * @param Session $session - * @param bool $isLoggedIn - * @return bool + * @param Http $response * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function afterIsLoggedIn(Session $session, $isLoggedIn) + public function beforeSendVary(Http $response) { - if (!$isLoggedIn) { + if (!$this->session->isLoggedIn()) { $metadata = $this->cookieMetadataFactory->createCookieMetadata(); $metadata->setPath('/'); $this->cookieManager->deleteCookie('mage-cache-sessid', $metadata); } - return $isLoggedIn; } } diff --git a/app/code/Magento/Customer/Test/Unit/CustomerData/Plugin/SessionCheckerTest.php b/app/code/Magento/Customer/Test/Unit/CustomerData/Plugin/SessionCheckerTest.php index 72880a36db59a..6202b9bb590e5 100644 --- a/app/code/Magento/Customer/Test/Unit/CustomerData/Plugin/SessionCheckerTest.php +++ b/app/code/Magento/Customer/Test/Unit/CustomerData/Plugin/SessionCheckerTest.php @@ -34,6 +34,11 @@ class SessionCheckerTest extends \PHPUnit_Framework_TestCase */ protected $session; + /** + * @var \Magento\Framework\App\Response\Http|\PHPUnit_Framework_MockObject_MockObject + */ + protected $response; + public function setUp() { $this->cookieManager = $this->getMockBuilder('Magento\Framework\Stdlib\Cookie\PhpCookieManager') @@ -48,8 +53,11 @@ public function setUp() $this->session = $this->getMockBuilder('Magento\Customer\Model\Session') ->disableOriginalConstructor() ->getMock(); + $this->response = $this->getMockBuilder('Magento\Framework\App\Response\Http') + ->disableOriginalConstructor() + ->getMock(); - $this->plugin = new SessionChecker($this->cookieManager, $this->metadataFactory); + $this->plugin = new SessionChecker($this->cookieManager, $this->metadataFactory, $this->session); } /** @@ -58,8 +66,12 @@ public function setUp() * @return void * @dataProvider testAfterIsLoggedInDataProvider */ - public function testAfterIsLoggedIn($result, $callCount) + public function testBeforeSendVary($result, $callCount) { + $this->session->expects($this->once()) + ->method('isLoggedIn') + ->willReturn($result); + $this->metadataFactory->expects($this->{$callCount}()) ->method('createCookieMetadata') ->willReturn($this->metadata); @@ -69,7 +81,7 @@ public function testAfterIsLoggedIn($result, $callCount) $this->cookieManager->expects($this->{$callCount}()) ->method('deleteCookie') ->with('mage-cache-sessid', $this->metadata); - $this->assertEquals($result, $this->plugin->afterIsLoggedIn($this->session, $result)); + $this->plugin->beforeSendVary($this->response); } public function testAfterIsLoggedInDataProvider() diff --git a/app/code/Magento/Customer/etc/frontend/di.xml b/app/code/Magento/Customer/etc/frontend/di.xml index 2837805a29bf8..1d200876828d0 100644 --- a/app/code/Magento/Customer/etc/frontend/di.xml +++ b/app/code/Magento/Customer/etc/frontend/di.xml @@ -57,7 +57,7 @@ - + From d40f1f35e71bdf4fd397d908d7ad3e83b4094ebf Mon Sep 17 00:00:00 2001 From: Oleksandr Karpenko Date: Fri, 13 May 2016 12:58:54 +0300 Subject: [PATCH 14/22] MAGETWO-52338: Csrf delete the customer addresses --- .../Customer/Controller/Address/Delete.php | 2 +- .../Unit/Controller/Address/DeleteTest.php | 215 ++++++++++++++++++ .../Customer/view/frontend/web/address.js | 6 +- 3 files changed, 220 insertions(+), 3 deletions(-) create mode 100644 app/code/Magento/Customer/Test/Unit/Controller/Address/DeleteTest.php diff --git a/app/code/Magento/Customer/Controller/Address/Delete.php b/app/code/Magento/Customer/Controller/Address/Delete.php index 7bf3dae270fb1..9b827e35c02b9 100644 --- a/app/code/Magento/Customer/Controller/Address/Delete.php +++ b/app/code/Magento/Customer/Controller/Address/Delete.php @@ -15,7 +15,7 @@ public function execute() { $addressId = $this->getRequest()->getParam('id', false); - if ($addressId) { + if ($addressId && $this->_formKeyValidator->validate($this->getRequest())) { try { $address = $this->_addressRepository->getById($addressId); if ($address->getCustomerId() === $this->_getSession()->getCustomerId()) { diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Address/DeleteTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Address/DeleteTest.php new file mode 100644 index 0000000000000..e234cf4708b9e --- /dev/null +++ b/app/code/Magento/Customer/Test/Unit/Controller/Address/DeleteTest.php @@ -0,0 +1,215 @@ +sessionMock = $this->getMockBuilder('Magento\Customer\Model\Session') + ->disableOriginalConstructor() + ->getMock(); + $this->validatorMock = $this->getMockBuilder('Magento\Framework\Data\Form\FormKey\Validator') + ->disableOriginalConstructor() + ->getMock(); + $this->formFactoryMock = $this->getMockBuilder('Magento\Customer\Model\Metadata\FormFactory') + ->disableOriginalConstructor() + ->getMock(); + $this->addressRepositoryMock = $this->getMockBuilder('Magento\Customer\Api\AddressRepositoryInterface') + ->getMockForAbstractClass(); + $this->addressInterfaceFactoryMock = $this->getMockBuilder('Magento\Customer\Api\Data\AddressInterfaceFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->regionInterfaceFactoryMock = $this->getMockBuilder('Magento\Customer\Api\Data\RegionInterfaceFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->dataObjectProcessorMock = $this->getMockBuilder('Magento\Framework\Reflection\DataObjectProcessor') + ->disableOriginalConstructor() + ->getMock(); + $this->dataObjectHelperMock = $this->getMockBuilder('Magento\Framework\Api\DataObjectHelper') + ->disableOriginalConstructor() + ->getMock(); + $this->forwardFactoryMock = $this->getMockBuilder('Magento\Framework\Controller\Result\ForwardFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->pageFactoryMock = $this->getMockBuilder('Magento\Framework\View\Result\PageFactory') + ->disableOriginalConstructor() + ->getMock(); + $this->request = $this->getMockBuilder('Magento\Framework\App\RequestInterface') + ->getMockForAbstractClass(); + $this->address = $this->getMockBuilder('Magento\Customer\Api\Data\AddressInterface') + ->getMockForAbstractClass(); + $this->messageManager = $this->getMockBuilder('Magento\Framework\Message\ManagerInterface') + ->getMockForAbstractClass(); + $this->resultRedirectFactory = $this->getMockBuilder('Magento\Framework\Controller\Result\RedirectFactory') + ->disableOriginalConstructor() + ->getMock(); + $this->resultRedirect = $this->getMockBuilder('Magento\Framework\Controller\Result\Redirect') + ->disableOriginalConstructor() + ->getMock(); + + $objectManager = new ObjectManagerHelper($this); + $this->context = $objectManager->getObject( + 'Magento\Framework\App\Action\Context', + [ + 'request' => $this->request, + 'messageManager' => $this->messageManager, + 'resultRedirectFactory' => $this->resultRedirectFactory, + ] + ); + + $this->model = new Delete( + $this->context, + $this->sessionMock, + $this->validatorMock, + $this->formFactoryMock, + $this->addressRepositoryMock, + $this->addressInterfaceFactoryMock, + $this->regionInterfaceFactoryMock, + $this->dataObjectProcessorMock, + $this->dataObjectHelperMock, + $this->forwardFactoryMock, + $this->pageFactoryMock + ); + } + + public function testExecute() + { + $addressId = 1; + $customerId = 2; + + $this->resultRedirectFactory->expects($this->once()) + ->method('create') + ->willReturn($this->resultRedirect); + $this->request->expects($this->once()) + ->method('getParam') + ->with('id', false) + ->willReturn($addressId); + $this->validatorMock->expects($this->once()) + ->method('validate') + ->with($this->request) + ->willReturn(true); + $this->addressRepositoryMock->expects($this->once()) + ->method('getById') + ->with($addressId) + ->willReturn($this->address); + $this->sessionMock->expects($this->once()) + ->method('getCustomerId') + ->willReturn($customerId); + $this->address->expects($this->once()) + ->method('getCustomerId') + ->willReturn($customerId); + $this->addressRepositoryMock->expects($this->once()) + ->method('deleteById') + ->with($addressId); + $this->messageManager->expects($this->once()) + ->method('addSuccess') + ->with(__('You deleted the address.')); + $this->resultRedirect->expects($this->once()) + ->method('setPath') + ->with('*/*/index') + ->willReturnSelf(); + $this->assertSame($this->resultRedirect, $this->model->execute()); + } + + public function testExecuteWithException() + { + $addressId = 1; + $customerId = 2; + + $this->resultRedirectFactory->expects($this->once()) + ->method('create') + ->willReturn($this->resultRedirect); + $this->request->expects($this->once()) + ->method('getParam') + ->with('id', false) + ->willReturn($addressId); + $this->validatorMock->expects($this->once()) + ->method('validate') + ->with($this->request) + ->willReturn(true); + $this->addressRepositoryMock->expects($this->once()) + ->method('getById') + ->with($addressId) + ->willReturn($this->address); + $this->sessionMock->expects($this->once()) + ->method('getCustomerId') + ->willReturn($customerId); + $this->address->expects($this->once()) + ->method('getCustomerId') + ->willReturn(34); + $exception = new \Exception('Exception'); + $this->messageManager->expects($this->once()) + ->method('addError') + ->with(__('We can\'t delete the address right now.')) + ->willThrowException($exception); + $this->messageManager->expects($this->once()) + ->method('addException') + ->with($exception, __('We can\'t delete the address right now.')); + $this->resultRedirect->expects($this->once()) + ->method('setPath') + ->with('*/*/index') + ->willReturnSelf(); + $this->assertSame($this->resultRedirect, $this->model->execute()); + } +} diff --git a/app/code/Magento/Customer/view/frontend/web/address.js b/app/code/Magento/Customer/view/frontend/web/address.js index e35203cae263b..78443af9a3ab2 100644 --- a/app/code/Magento/Customer/view/frontend/web/address.js +++ b/app/code/Magento/Customer/view/frontend/web/address.js @@ -61,10 +61,12 @@ define([ actions: { confirm: function() { if (typeof $(e.target).parent().data('address') !== 'undefined') { - window.location = self.options.deleteUrlPrefix + $(e.target).parent().data('address'); + window.location = self.options.deleteUrlPrefix + $(e.target).parent().data('address') + + '/form_key/' + $.mage.cookies.get('form_key'); } else { - window.location = self.options.deleteUrlPrefix + $(e.target).data('address'); + window.location = self.options.deleteUrlPrefix + $(e.target).data('address') + + '/form_key/' + $.mage.cookies.get('form_key'); } } } From 94f3f2d4920dc0fbd3a5c4f852af8ac16171f3c8 Mon Sep 17 00:00:00 2001 From: Oleksandr Karpenko Date: Fri, 13 May 2016 13:08:43 +0300 Subject: [PATCH 15/22] MAGETWO-49767: Merchant can't save & continue editing the Design Configuration --- .../Unit/Block/Adminhtml/Design/Config/Edit/SaveButtonTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Theme/Test/Unit/Block/Adminhtml/Design/Config/Edit/SaveButtonTest.php b/app/code/Magento/Theme/Test/Unit/Block/Adminhtml/Design/Config/Edit/SaveButtonTest.php index 5f1f47c8e8ded..3c254fd613465 100644 --- a/app/code/Magento/Theme/Test/Unit/Block/Adminhtml/Design/Config/Edit/SaveButtonTest.php +++ b/app/code/Magento/Theme/Test/Unit/Block/Adminhtml/Design/Config/Edit/SaveButtonTest.php @@ -32,7 +32,7 @@ public function testGetButtonData() $result = $this->block->getButtonData(); $this->assertArrayHasKey('label', $result); - $this->assertEquals($result['label'], __('Save')); + $this->assertEquals($result['label'], __('Save Configuration')); $this->assertArrayHasKey('data_attribute', $result); $this->assertTrue(is_array($result['data_attribute'])); } From 0b52926102d36f972029998622de94623264b050 Mon Sep 17 00:00:00 2001 From: Sviatoslav Mankivskyi Date: Fri, 13 May 2016 13:15:52 +0300 Subject: [PATCH 16/22] MAGETWO-51786: Escape Js Quote "confirmRemoveMessage" on WishList view #4050 --- app/code/Magento/Wishlist/view/frontend/templates/view.phtml | 1 - 1 file changed, 1 deletion(-) diff --git a/app/code/Magento/Wishlist/view/frontend/templates/view.phtml b/app/code/Magento/Wishlist/view/frontend/templates/view.phtml index 046033d730e3f..31217431a4ea4 100644 --- a/app/code/Magento/Wishlist/view/frontend/templates/view.phtml +++ b/app/code/Magento/Wishlist/view/frontend/templates/view.phtml @@ -14,7 +14,6 @@
From 92572906e8298bfec552e9eacdc7dbfd818bf298 Mon Sep 17 00:00:00 2001 From: Oleksandr Karpenko Date: Fri, 13 May 2016 13:17:08 +0300 Subject: [PATCH 17/22] MAGETWO-52338: Csrf delete the customer addresses --- .../Customer/Test/Unit/Controller/Address/DeleteTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Address/DeleteTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Address/DeleteTest.php index e234cf4708b9e..92a5edb86c105 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Address/DeleteTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Address/DeleteTest.php @@ -8,6 +8,9 @@ use Magento\Customer\Controller\Address\Delete; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; +/** + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class DeleteTest extends \PHPUnit_Framework_TestCase { /** @var Delete */ From 93413532c88874a45d8748c954bd300395bb1bc8 Mon Sep 17 00:00:00 2001 From: Oleksandr Karpenko Date: Fri, 13 May 2016 13:26:44 +0300 Subject: [PATCH 18/22] MAGETWO-52593: Minicart does not clean when customer session is over --- app/code/Magento/Customer/CustomerData/Plugin/SessionChecker.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Customer/CustomerData/Plugin/SessionChecker.php b/app/code/Magento/Customer/CustomerData/Plugin/SessionChecker.php index 8f46ab14784a0..4426af2a61d8f 100644 --- a/app/code/Magento/Customer/CustomerData/Plugin/SessionChecker.php +++ b/app/code/Magento/Customer/CustomerData/Plugin/SessionChecker.php @@ -47,6 +47,7 @@ public function __construct( * * @param Http $response * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @return void */ public function beforeSendVary(Http $response) { From badd0309f4c76ec76fed9637a3bf822855dfd15b Mon Sep 17 00:00:00 2001 From: Oleksandr Karpenko Date: Fri, 13 May 2016 13:35:10 +0300 Subject: [PATCH 19/22] MAGETWO-52338: Csrf delete the customer addresses --- .../Unit/Controller/Address/DeleteTest.php | 49 ++++++------------- 1 file changed, 14 insertions(+), 35 deletions(-) diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Address/DeleteTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Address/DeleteTest.php index 92a5edb86c105..1f5d92791269a 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Address/DeleteTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Address/DeleteTest.php @@ -25,30 +25,9 @@ class DeleteTest extends \PHPUnit_Framework_TestCase /** @var \Magento\Framework\Data\Form\FormKey\Validator|\PHPUnit_Framework_MockObject_MockObject */ protected $validatorMock; - /** @var \Magento\Customer\Model\Metadata\FormFactory|\PHPUnit_Framework_MockObject_MockObject */ - protected $formFactoryMock; - /** @var \Magento\Customer\Api\AddressRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject */ protected $addressRepositoryMock; - /** @var \Magento\Customer\Api\Data\AddressInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject */ - protected $addressInterfaceFactoryMock; - - /** @var \Magento\Customer\Api\Data\RegionInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject */ - protected $regionInterfaceFactoryMock; - - /** @var \Magento\Framework\Reflection\DataObjectProcessor|\PHPUnit_Framework_MockObject_MockObject */ - protected $dataObjectProcessorMock; - - /** @var \Magento\Framework\Api\DataObjectHelper|\PHPUnit_Framework_MockObject_MockObject */ - protected $dataObjectHelperMock; - - /** @var \Magento\Framework\Controller\Result\ForwardFactory|\PHPUnit_Framework_MockObject_MockObject */ - protected $forwardFactoryMock; - - /** @var \Magento\Framework\View\Result\PageFactory|\PHPUnit_Framework_MockObject_MockObject */ - protected $pageFactoryMock; - /** @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject */ protected $request; @@ -72,30 +51,30 @@ protected function setUp() $this->validatorMock = $this->getMockBuilder('Magento\Framework\Data\Form\FormKey\Validator') ->disableOriginalConstructor() ->getMock(); - $this->formFactoryMock = $this->getMockBuilder('Magento\Customer\Model\Metadata\FormFactory') + $formFactoryMock = $this->getMockBuilder('Magento\Customer\Model\Metadata\FormFactory') ->disableOriginalConstructor() ->getMock(); $this->addressRepositoryMock = $this->getMockBuilder('Magento\Customer\Api\AddressRepositoryInterface') ->getMockForAbstractClass(); - $this->addressInterfaceFactoryMock = $this->getMockBuilder('Magento\Customer\Api\Data\AddressInterfaceFactory') + $addressInterfaceFactoryMock = $this->getMockBuilder('Magento\Customer\Api\Data\AddressInterfaceFactory') ->disableOriginalConstructor() ->setMethods(['create']) ->getMock(); - $this->regionInterfaceFactoryMock = $this->getMockBuilder('Magento\Customer\Api\Data\RegionInterfaceFactory') + $regionInterfaceFactoryMock = $this->getMockBuilder('Magento\Customer\Api\Data\RegionInterfaceFactory') ->disableOriginalConstructor() ->setMethods(['create']) ->getMock(); - $this->dataObjectProcessorMock = $this->getMockBuilder('Magento\Framework\Reflection\DataObjectProcessor') + $dataObjectProcessorMock = $this->getMockBuilder('Magento\Framework\Reflection\DataObjectProcessor') ->disableOriginalConstructor() ->getMock(); - $this->dataObjectHelperMock = $this->getMockBuilder('Magento\Framework\Api\DataObjectHelper') + $dataObjectHelperMock = $this->getMockBuilder('Magento\Framework\Api\DataObjectHelper') ->disableOriginalConstructor() ->getMock(); - $this->forwardFactoryMock = $this->getMockBuilder('Magento\Framework\Controller\Result\ForwardFactory') + $forwardFactoryMock = $this->getMockBuilder('Magento\Framework\Controller\Result\ForwardFactory') ->disableOriginalConstructor() ->setMethods(['create']) ->getMock(); - $this->pageFactoryMock = $this->getMockBuilder('Magento\Framework\View\Result\PageFactory') + $pageFactoryMock = $this->getMockBuilder('Magento\Framework\View\Result\PageFactory') ->disableOriginalConstructor() ->getMock(); $this->request = $this->getMockBuilder('Magento\Framework\App\RequestInterface') @@ -125,14 +104,14 @@ protected function setUp() $this->context, $this->sessionMock, $this->validatorMock, - $this->formFactoryMock, + $formFactoryMock, $this->addressRepositoryMock, - $this->addressInterfaceFactoryMock, - $this->regionInterfaceFactoryMock, - $this->dataObjectProcessorMock, - $this->dataObjectHelperMock, - $this->forwardFactoryMock, - $this->pageFactoryMock + $addressInterfaceFactoryMock, + $regionInterfaceFactoryMock, + $dataObjectProcessorMock, + $dataObjectHelperMock, + $forwardFactoryMock, + $pageFactoryMock ); } From 3fc2286351a1692e1d59abbd5869e2c2121c3634 Mon Sep 17 00:00:00 2001 From: Oleksandr Karpenko Date: Fri, 13 May 2016 15:46:05 +0300 Subject: [PATCH 20/22] MAGETWO-52338: Csrf delete the customer addresses --- .../Magento/Customer/Controller/AddressTest.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Customer/Controller/AddressTest.php b/dev/tests/integration/testsuite/Magento/Customer/Controller/AddressTest.php index d321ed00ac495..cbbbbf1733306 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Controller/AddressTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Controller/AddressTest.php @@ -5,13 +5,18 @@ */ namespace Magento\Customer\Controller; +use Magento\Customer\Api\AccountManagementInterface; +use Magento\Framework\Data\Form\FormKey; use Magento\TestFramework\Helper\Bootstrap; class AddressTest extends \Magento\TestFramework\TestCase\AbstractController { - /** @var \Magento\Customer\Api\AccountManagementInterface */ + /** @var AccountManagementInterface */ private $accountManagement; + /** @var FormKey */ + private $formKey; + protected function setUp() { parent::setUp(); @@ -20,9 +25,8 @@ protected function setUp() 'Magento\Customer\Model\Session', [$logger] ); - $this->accountManagement = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( - 'Magento\Customer\Api\AccountManagementInterface' - ); + $this->accountManagement = Bootstrap::getObjectManager()->create(AccountManagementInterface::class); + $this->formKey = Bootstrap::getObjectManager()->create(FormKey::class); $customer = $this->accountManagement->authenticate('customer@example.com', 'password'); $session->setCustomerDataAsLoggedIn($customer); } @@ -152,6 +156,7 @@ public function testFailedFormPostAction() public function testDeleteAction() { $this->getRequest()->setParam('id', 1); + $this->getRequest()->setParam('form_key', $this->formKey->getFormKey()); // we are overwriting the address coming from the fixture $this->dispatch('customer/address/delete'); @@ -169,6 +174,7 @@ public function testDeleteAction() public function testWrongAddressDeleteAction() { $this->getRequest()->setParam('id', 555); + $this->getRequest()->setParam('form_key', $this->formKey->getFormKey()); // we are overwriting the address coming from the fixture $this->dispatch('customer/address/delete'); From d10867f282bd2c5af21eeb92ad7c008d6d1df691 Mon Sep 17 00:00:00 2001 From: Ievgen Sentiabov Date: Sat, 14 May 2016 10:21:12 +0300 Subject: [PATCH 21/22] MAGETWO-52308: [Github] Not full request information in collectRates() method on Checkout page - Added api method to estimate shipping methods by extended address data --- .../shipping-rate-processor/new-address.js | 23 +- .../Api/GuestShipmentEstimationInterface.php | 12 + ...GuestShippingMethodManagementInterface.php | 1 + .../Quote/Api/ShipmentEstimationInterface.php | 23 ++ .../Api/ShippingMethodManagementInterface.php | 1 + .../GuestShippingMethodManagement.php | 38 +- .../Quote/Model/ShippingMethodManagement.php | 49 ++- .../GuestShippingMethodManagementTest.php | 57 ++- .../Model/ShippingMethodManagementTest.php | 378 +++++++++++------- app/code/Magento/Quote/etc/di.xml | 2 + app/code/Magento/Quote/etc/webapi.xml | 6 +- 11 files changed, 420 insertions(+), 170 deletions(-) create mode 100644 app/code/Magento/Quote/Api/GuestShipmentEstimationInterface.php create mode 100644 app/code/Magento/Quote/Api/ShipmentEstimationInterface.php diff --git a/app/code/Magento/Checkout/view/frontend/web/js/model/shipping-rate-processor/new-address.js b/app/code/Magento/Checkout/view/frontend/web/js/model/shipping-rate-processor/new-address.js index 9e776288fe784..0e8fb8c889f4d 100644 --- a/app/code/Magento/Checkout/view/frontend/web/js/model/shipping-rate-processor/new-address.js +++ b/app/code/Magento/Checkout/view/frontend/web/js/model/shipping-rate-processor/new-address.js @@ -25,10 +25,25 @@ define( serviceUrl = resourceUrlManager.getUrlForEstimationShippingMethodsForNewAddress(quote), payload = JSON.stringify({ address: { - country_id: address.countryId, - region_id: address.regionId, - region: address.region, - postcode: address.postcode + 'street': address.street, + 'city': address.city, + 'region_id': address.regionId, + 'region': address.region, + 'country_id': address.countryId, + 'postcode': address.postcode, + 'email': address.email, + 'customer_id': address.customerId, + 'firstname': address.firstname, + 'lastname': address.lastname, + 'middlename': address.middlename, + 'prefix': address.prefix, + 'suffix': address.suffix, + 'vat_id': address.vatId, + 'company': address.company, + 'telephone': address.telephone, + 'fax': address.fax, + 'custom_attributes': address.customAttributes, + 'save_in_address_book': address.saveInAddressBook } } ); diff --git a/app/code/Magento/Quote/Api/GuestShipmentEstimationInterface.php b/app/code/Magento/Quote/Api/GuestShipmentEstimationInterface.php new file mode 100644 index 0000000000000..01befb6c7a964 --- /dev/null +++ b/app/code/Magento/Quote/Api/GuestShipmentEstimationInterface.php @@ -0,0 +1,12 @@ +quoteIdMaskFactory->create()->load($cartId, 'masked_id'); return $this->shippingMethodManagement->estimateByAddress($quoteIdMask->getQuoteId(), $address); } + + /** + * @inheritdoc + */ + public function estimateByExtendedAddress($cartId, AddressInterface $address) + { + /** @var $quoteIdMask QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + + return $this->getShipmentEstimationManagement() + ->estimateByExtendedAddress((int) $quoteIdMask->getQuoteId(), $address); + } + + /** + * Get shipment estimation management service + * @return ShipmentEstimationInterface + * @deprecated + */ + private function getShipmentEstimationManagement() + { + if ($this->shipmentEstimationManagement === null) { + $this->shipmentEstimationManagement = ObjectManager::getInstance() + ->get(ShipmentEstimationInterface::class); + } + return $this->shipmentEstimationManagement; + } } diff --git a/app/code/Magento/Quote/Model/ShippingMethodManagement.php b/app/code/Magento/Quote/Model/ShippingMethodManagement.php index 44bf4d2d06465..efc0dfbe41255 100644 --- a/app/code/Magento/Quote/Model/ShippingMethodManagement.php +++ b/app/code/Magento/Quote/Model/ShippingMethodManagement.php @@ -5,10 +5,14 @@ */ namespace Magento\Quote\Model; +use Magento\Framework\Exception\CouldNotSaveException; use Magento\Framework\Exception\InputException; -use Magento\Framework\Exception\StateException; use Magento\Framework\Exception\NoSuchEntityException; -use Magento\Framework\Exception\CouldNotSaveException; +use Magento\Framework\Exception\StateException; +use Magento\Quote\Api\Data\AddressInterface; +use Magento\Quote\Api\Data\EstimateAddressInterface; +use Magento\Quote\Api\ShipmentEstimationInterface; +use Magento\Quote\Model\Quote; /** * Shipping method read service. @@ -16,7 +20,8 @@ */ class ShippingMethodManagement implements \Magento\Quote\Api\ShippingMethodManagementInterface, - \Magento\Quote\Model\ShippingMethodManagementInterface + \Magento\Quote\Model\ShippingMethodManagementInterface, + ShipmentEstimationInterface { /** * Quote repository. @@ -193,6 +198,21 @@ public function estimateByAddress($cartId, \Magento\Quote\Api\Data\EstimateAddre ); } + /** + * @inheritdoc + */ + public function estimateByExtendedAddress($cartId, AddressInterface $address) + { + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $this->quoteRepository->getActive($cartId); + + // no methods applicable for empty carts or carts with virtual products + if ($quote->isVirtual() || 0 == $quote->getItemsCount()) { + return []; + } + return $this->getShippingMethods($quote, $address->getData()); + } + /** * {@inheritDoc} */ @@ -227,14 +247,29 @@ public function estimateByAddressId($cartId, $addressId) * @return \Magento\Quote\Api\Data\ShippingMethodInterface[] An array of shipping methods. */ protected function getEstimatedRates(\Magento\Quote\Model\Quote $quote, $country, $postcode, $regionId, $region) + { + $data = [ + EstimateAddressInterface::KEY_COUNTRY_ID => $country, + EstimateAddressInterface::KEY_POSTCODE => $postcode, + EstimateAddressInterface::KEY_REGION_ID => $regionId, + EstimateAddressInterface::KEY_REGION => $region + ]; + return $this->getShippingMethods($quote, $data); + } + + /** + * Get list of available shipping methods + * @param \Magento\Quote\Model\Quote $quote + * @param array $addressData + * @return \Magento\Quote\Api\Data\ShippingMethodInterface[] + */ + private function getShippingMethods(Quote $quote, array $addressData) { $output = []; $shippingAddress = $quote->getShippingAddress(); - $shippingAddress->setCountryId($country); - $shippingAddress->setPostcode($postcode); - $shippingAddress->setRegionId($regionId); - $shippingAddress->setRegion($region); + $shippingAddress->addData($addressData); $shippingAddress->setCollectShippingRates(true); + $this->totalsCollector->collectAddressTotals($quote, $shippingAddress); $shippingRates = $shippingAddress->getGroupedAllShippingRates(); foreach ($shippingRates as $carrierRates) { diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestShippingMethodManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestShippingMethodManagementTest.php index 2b428728ca7cf..9521040920874 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestShippingMethodManagementTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestShippingMethodManagementTest.php @@ -7,10 +7,17 @@ namespace Magento\Quote\Test\Unit\Model\GuestCart; +use PHPUnit_Framework_MockObject_MockObject as MockObject; +use Magento\Quote\Model\QuoteIdMask; +use Magento\Quote\Api\Data\AddressInterface; +use Magento\Quote\Api\ShipmentEstimationInterface; +use Magento\Quote\Api\Data\ShippingMethodInterface; +use Magento\Quote\Model\GuestCart\GuestShippingMethodManagement; + class GuestShippingMethodManagementTest extends \PHPUnit_Framework_TestCase { /** - * @var \Magento\Quote\Api\GuestShippingMethodManagementInterface + * @var GuestShippingMethodManagement */ private $model; @@ -25,19 +32,24 @@ class GuestShippingMethodManagementTest extends \PHPUnit_Framework_TestCase private $quoteIdMaskFactoryMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var ShipmentEstimationInterface|MockObject */ - private $quoteIdMaskMock; + private $shipmentEstimationManagement; /** - * @var string + * @var QuoteIdMask|MockObject */ - private $maskedCartId; + private $quoteIdMask; /** * @var string */ - private $cartId; + private $maskedCartId = 'f216207248d65c789b17be8545e0aa73'; + + /** + * @var int + */ + private $cartId = 867; protected function setUp() { @@ -46,22 +58,26 @@ protected function setUp() $this->shippingMethodManagementMock = $this->getMock('Magento\Quote\Model\ShippingMethodManagement', [], [], '', false); - $this->maskedCartId = 'f216207248d65c789b17be8545e0aa73'; - $this->cartId = 867; - $guestCartTestHelper = new GuestCartTestHelper($this); - list($this->quoteIdMaskFactoryMock, $this->quoteIdMaskMock) = $guestCartTestHelper->mockQuoteIdMask( + list($this->quoteIdMaskFactoryMock, $this->quoteIdMask) = $guestCartTestHelper->mockQuoteIdMask( $this->maskedCartId, $this->cartId ); + $this->shipmentEstimationManagement = $this->getMockForAbstractClass(ShipmentEstimationInterface::class); + $this->model = $objectManager->getObject( - 'Magento\Quote\Model\GuestCart\GuestShippingMethodManagement', + GuestShippingMethodManagement::class, [ 'shippingMethodManagement' => $this->shippingMethodManagementMock, 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock, ] ); + + $refObject = new \ReflectionClass(GuestShippingMethodManagement::class); + $refProperty = $refObject->getProperty('shipmentEstimationManagement'); + $refProperty->setAccessible(true); + $refProperty->setValue($this->model, $this->shipmentEstimationManagement); } public function testSet() @@ -99,4 +115,23 @@ public function testGet() $this->assertEquals($retValue, $this->model->get($this->maskedCartId)); } + + /** + * @covers \Magento\Quote\Model\GuestCart\GuestShippingMethodManagement::getShipmentEstimationManagement + */ + public function testEstimateByExtendedAddress() + { + $address = $this->getMockForAbstractClass(AddressInterface::class); + + $methodObject = $this->getMockForAbstractClass(ShippingMethodInterface::class); + $expectedRates = [$methodObject]; + + $this->shipmentEstimationManagement->expects(static::once()) + ->method('estimateByExtendedAddress') + ->with($this->cartId, $address) + ->willReturn($expectedRates); + + $carriersRates = $this->model->estimateByExtendedAddress($this->maskedCartId, $address); + static::assertEquals($expectedRates, $carriersRates); + } } diff --git a/app/code/Magento/Quote/Test/Unit/Model/ShippingMethodManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/ShippingMethodManagementTest.php index 8be6c8befe20b..0ad933fb379ac 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/ShippingMethodManagementTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/ShippingMethodManagementTest.php @@ -7,10 +7,16 @@ namespace Magento\Quote\Test\Unit\Model; -use \Magento\Quote\Model\ShippingMethodManagement; - -use Magento\Quote\Api\Data\ShippingMethodInterface; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; +use Magento\Quote\Api\Data\ShippingMethodInterface; +use Magento\Quote\Model\Cart\ShippingMethodConverter; +use Magento\Quote\Model\Quote; +use Magento\Quote\Model\Quote\Address; +use Magento\Quote\Model\Quote\Address\Rate; +use Magento\Quote\Model\Quote\TotalsCollector; +use Magento\Quote\Model\QuoteRepository; +use Magento\Quote\Model\ShippingMethodManagement; +use PHPUnit_Framework_MockObject_MockObject as MockObject; class ShippingMethodManagementTest extends \PHPUnit_Framework_TestCase { @@ -22,42 +28,47 @@ class ShippingMethodManagementTest extends \PHPUnit_Framework_TestCase /** * @var \PHPUnit_Framework_MockObject_MockObject */ - protected $quoteRepositoryMock; + protected $shippingMethodMock; /** * @var \PHPUnit_Framework_MockObject_MockObject */ - protected $quoteMock; + protected $methodDataFactoryMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var ShippingMethodConverter|MockObject */ - protected $shippingAddressMock; + protected $converter; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager */ - protected $shippingMethodMock; + protected $objectManager; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var QuoteRepository|MockObject */ - protected $methodDataFactoryMock; + private $quoteRepository; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var Quote|MockObject */ - protected $converterMock; + private $quote; /** - * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager + * @var Address|MockObject */ - protected $objectManager; + private $shippingAddress; + + /** + * @var TotalsCollector|MockObject + */ + private $totalsCollector; protected function setUp() { $this->objectManager = new ObjectManager($this); - $this->quoteRepositoryMock = $this->getMock('\Magento\Quote\Api\CartRepositoryInterface'); + $this->quoteRepository = $this->getMock('\Magento\Quote\Api\CartRepositoryInterface'); $this->methodDataFactoryMock = $this->getMock( '\Magento\Quote\Api\Data\ShippingMethodInterfaceFactory', [ @@ -69,9 +80,9 @@ protected function setUp() ); $this->storeMock = $this->getMock('\Magento\Store\Model\Store', [], [], '', false); - $this->quoteMock = $this->getMock( - '\Magento\Quote\Model\Quote', - [ + $this->quote = $this->getMockBuilder(Quote::class) + ->disableOriginalConstructor() + ->setMethods([ 'getShippingAddress', 'isVirtual', 'getItemsCount', @@ -80,14 +91,12 @@ protected function setUp() 'collectTotals', 'save', '__wakeup', - ], - [], - '', - false - ); - $this->shippingAddressMock = $this->getMock( - '\Magento\Quote\Model\Quote\Address', - [ + ]) + ->getMock(); + + $this->shippingAddress = $this->getMockBuilder(Address::class) + ->disableOriginalConstructor() + ->setMethods([ 'getCountryId', 'getShippingMethod', 'getShippingDescription', @@ -97,27 +106,30 @@ protected function setUp() 'collectShippingRates', 'requestShippingRates', 'setShippingMethod', - '__wakeup', 'getShippingRateByCode', - ], - [], - '', - false - ); - $this->converterMock = $this->getMock( - '\Magento\Quote\Model\Cart\ShippingMethodConverter', - [], - [], - '', - false - ); + 'addData', + 'setCollectShippingRates', + '__wakeup', + ]) + ->getMock(); + + $this->converter = $this->getMockBuilder(ShippingMethodConverter::class) + ->disableOriginalConstructor() + ->setMethods(['modelToDataObject']) + ->getMock(); + + $this->totalsCollector = $this->getMockBuilder(TotalsCollector::class) + ->disableOriginalConstructor() + ->setMethods(['collectAddressTotals']) + ->getMock(); $this->model = $this->objectManager->getObject( - 'Magento\Quote\Model\ShippingMethodManagement', + ShippingMethodManagement::class, [ - 'quoteRepository' => $this->quoteRepositoryMock, + 'quoteRepository' => $this->quoteRepository, 'methodDataFactory' => $this->methodDataFactoryMock, - 'converter' => $this->converterMock, + 'converter' => $this->converter, + 'totalsCollector' => $this->totalsCollector ] ); } @@ -129,11 +141,11 @@ protected function setUp() public function testGetMethodWhenShippingAddressIsNotSet() { $cartId = 666; - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once()) - ->method('getShippingAddress')->will($this->returnValue($this->shippingAddressMock)); - $this->shippingAddressMock->expects($this->once())->method('getCountryId')->will($this->returnValue(null)); + $this->quoteRepository->expects($this->once()) + ->method('getActive')->with($cartId)->will($this->returnValue($this->quote)); + $this->quote->expects($this->once()) + ->method('getShippingAddress')->will($this->returnValue($this->shippingAddress)); + $this->shippingAddress->expects($this->once())->method('getCountryId')->will($this->returnValue(null)); $this->assertNull($this->model->get($cartId)); } @@ -143,27 +155,27 @@ public function testGetMethod() $cartId = 666; $countryId = 1; $currencyCode = 'US_dollar'; - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once()) - ->method('getShippingAddress')->will($this->returnValue($this->shippingAddressMock)); - $this->quoteMock->expects($this->once()) + $this->quoteRepository->expects($this->once()) + ->method('getActive')->with($cartId)->will($this->returnValue($this->quote)); + $this->quote->expects($this->once()) + ->method('getShippingAddress')->will($this->returnValue($this->shippingAddress)); + $this->quote->expects($this->once()) ->method('getQuoteCurrencyCode')->willReturn($currencyCode); - $this->shippingAddressMock->expects($this->any()) + $this->shippingAddress->expects($this->any()) ->method('getCountryId')->will($this->returnValue($countryId)); - $this->shippingAddressMock->expects($this->any()) + $this->shippingAddress->expects($this->any()) ->method('getShippingMethod')->will($this->returnValue('one_two')); - $this->shippingAddressMock->expects($this->once())->method('collectShippingRates')->willReturnSelf(); + $this->shippingAddress->expects($this->once())->method('collectShippingRates')->willReturnSelf(); $shippingRateMock = $this->getMock('\Magento\Quote\Model\Quote\Address\Rate', [], [], '', false); - $this->shippingAddressMock->expects($this->once()) + $this->shippingAddress->expects($this->once()) ->method('getShippingRateByCode') ->with('one_two') ->willReturn($shippingRateMock); $this->shippingMethodMock = $this->getMock('\Magento\Quote\Api\Data\ShippingMethodInterface'); - $this->converterMock->expects($this->once()) + $this->converter->expects($this->once()) ->method('modelToDataObject') ->with($shippingRateMock, $currencyCode) ->willReturn($this->shippingMethodMock); @@ -175,13 +187,13 @@ public function testGetMethodIfMethodIsNotSet() $cartId = 666; $countryId = 1; - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once()) - ->method('getShippingAddress')->will($this->returnValue($this->shippingAddressMock)); - $this->shippingAddressMock->expects($this->any()) + $this->quoteRepository->expects($this->once()) + ->method('getActive')->with($cartId)->will($this->returnValue($this->quote)); + $this->quote->expects($this->once()) + ->method('getShippingAddress')->will($this->returnValue($this->shippingAddress)); + $this->shippingAddress->expects($this->any()) ->method('getCountryId')->will($this->returnValue($countryId)); - $this->shippingAddressMock->expects($this->any()) + $this->shippingAddress->expects($this->any()) ->method('getShippingMethod')->will($this->returnValue(null)); $this->assertNull($this->model->get($cartId)); @@ -190,9 +202,9 @@ public function testGetMethodIfMethodIsNotSet() public function testGetListForVirtualCart() { $cartId = 834; - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once()) + $this->quoteRepository->expects($this->once()) + ->method('getActive')->with($cartId)->will($this->returnValue($this->quote)); + $this->quote->expects($this->once()) ->method('isVirtual')->will($this->returnValue(true)); $this->assertEquals([], $this->model->getList($cartId)); @@ -201,11 +213,11 @@ public function testGetListForVirtualCart() public function testGetListForEmptyCart() { $cartId = 834; - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once()) + $this->quoteRepository->expects($this->once()) + ->method('getActive')->with($cartId)->will($this->returnValue($this->quote)); + $this->quote->expects($this->once()) ->method('isVirtual')->will($this->returnValue(false)); - $this->quoteMock->expects($this->once()) + $this->quote->expects($this->once()) ->method('getItemsCount')->will($this->returnValue(0)); $this->assertEquals([], $this->model->getList($cartId)); @@ -218,15 +230,15 @@ public function testGetListForEmptyCart() public function testGetListWhenShippingAddressIsNotSet() { $cartId = 834; - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once()) + $this->quoteRepository->expects($this->once()) + ->method('getActive')->with($cartId)->will($this->returnValue($this->quote)); + $this->quote->expects($this->once()) ->method('isVirtual')->will($this->returnValue(false)); - $this->quoteMock->expects($this->once()) + $this->quote->expects($this->once()) ->method('getItemsCount')->will($this->returnValue(3)); - $this->quoteMock->expects($this->once()) - ->method('getShippingAddress')->will($this->returnValue($this->shippingAddressMock)); - $this->shippingAddressMock->expects($this->once())->method('getCountryId')->will($this->returnValue(null)); + $this->quote->expects($this->once()) + ->method('getShippingAddress')->will($this->returnValue($this->shippingAddress)); + $this->shippingAddress->expects($this->once())->method('getCountryId')->will($this->returnValue(null)); $this->model->getList($cartId); } @@ -234,27 +246,27 @@ public function testGetListWhenShippingAddressIsNotSet() public function testGetList() { $cartId = 834; - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once()) + $this->quoteRepository->expects($this->once()) + ->method('getActive')->with($cartId)->will($this->returnValue($this->quote)); + $this->quote->expects($this->once()) ->method('isVirtual')->will($this->returnValue(false)); - $this->quoteMock->expects($this->once()) + $this->quote->expects($this->once()) ->method('getItemsCount')->will($this->returnValue(3)); - $this->quoteMock->expects($this->once()) - ->method('getShippingAddress')->will($this->returnValue($this->shippingAddressMock)); - $this->shippingAddressMock->expects($this->once())->method('getCountryId')->will($this->returnValue(345)); - $this->shippingAddressMock->expects($this->once())->method('collectShippingRates'); + $this->quote->expects($this->once()) + ->method('getShippingAddress')->will($this->returnValue($this->shippingAddress)); + $this->shippingAddress->expects($this->once())->method('getCountryId')->will($this->returnValue(345)); + $this->shippingAddress->expects($this->once())->method('collectShippingRates'); $shippingRateMock = $this->getMock('\Magento\Quote\Model\Quote\Address\Rate', [], [], '', false); - $this->shippingAddressMock->expects($this->once()) + $this->shippingAddress->expects($this->once()) ->method('getGroupedAllShippingRates') ->will($this->returnValue([[$shippingRateMock]])); $currencyCode = 'EUR'; - $this->quoteMock->expects($this->once()) + $this->quote->expects($this->once()) ->method('getQuoteCurrencyCode') ->will($this->returnValue($currencyCode)); - $this->converterMock->expects($this->once()) + $this->converter->expects($this->once()) ->method('modelToDataObject') ->with($shippingRateMock, $currencyCode) ->will($this->returnValue('RateValue')); @@ -271,10 +283,10 @@ public function testSetMethodWithInputException() $cartId = 12; $carrierCode = 34; $methodCode = 56; - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once())->method('getItemsCount')->will($this->returnValue(0)); - $this->quoteMock->expects($this->never())->method('isVirtual'); + $this->quoteRepository->expects($this->once()) + ->method('getActive')->with($cartId)->will($this->returnValue($this->quote)); + $this->quote->expects($this->once())->method('getItemsCount')->will($this->returnValue(0)); + $this->quote->expects($this->never())->method('isVirtual'); $this->model->set($cartId, $carrierCode, $methodCode); } @@ -290,10 +302,10 @@ public function testSetMethodWithVirtualProduct() $carrierCode = 34; $methodCode = 56; - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once())->method('getItemsCount')->will($this->returnValue(1)); - $this->quoteMock->expects($this->once())->method('isVirtual')->will($this->returnValue(true)); + $this->quoteRepository->expects($this->once()) + ->method('getActive')->with($cartId)->will($this->returnValue($this->quote)); + $this->quote->expects($this->once())->method('getItemsCount')->will($this->returnValue(1)); + $this->quote->expects($this->once())->method('isVirtual')->will($this->returnValue(true)); $this->model->set($cartId, $carrierCode, $methodCode); } @@ -308,13 +320,13 @@ public function testSetMethodWithoutShippingAddress() $cartId = 12; $carrierCode = 34; $methodCode = 56; - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once())->method('getItemsCount')->will($this->returnValue(1)); - $this->quoteMock->expects($this->once())->method('isVirtual')->will($this->returnValue(false)); - $this->quoteMock->expects($this->once()) - ->method('getShippingAddress')->will($this->returnValue($this->shippingAddressMock)); - $this->shippingAddressMock->expects($this->once())->method('getCountryId')->will($this->returnValue(null)); + $this->quoteRepository->expects($this->once()) + ->method('getActive')->with($cartId)->will($this->returnValue($this->quote)); + $this->quote->expects($this->once())->method('getItemsCount')->will($this->returnValue(1)); + $this->quote->expects($this->once())->method('isVirtual')->will($this->returnValue(false)); + $this->quote->expects($this->once()) + ->method('getShippingAddress')->will($this->returnValue($this->shippingAddress)); + $this->shippingAddress->expects($this->once())->method('getCountryId')->will($this->returnValue(null)); $this->model->set($cartId, $carrierCode, $methodCode); } @@ -330,19 +342,19 @@ public function testSetMethodWithNotFoundMethod() $carrierCode = 34; $methodCode = 56; $countryId = 1; - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once())->method('getItemsCount')->will($this->returnValue(1)); - $this->quoteMock->expects($this->once())->method('isVirtual')->will($this->returnValue(false)); - $this->quoteMock->expects($this->once()) - ->method('getShippingAddress')->will($this->returnValue($this->shippingAddressMock)); - $this->shippingAddressMock->expects($this->once()) + $this->quoteRepository->expects($this->once()) + ->method('getActive')->with($cartId)->will($this->returnValue($this->quote)); + $this->quote->expects($this->once())->method('getItemsCount')->will($this->returnValue(1)); + $this->quote->expects($this->once())->method('isVirtual')->will($this->returnValue(false)); + $this->quote->expects($this->once()) + ->method('getShippingAddress')->will($this->returnValue($this->shippingAddress)); + $this->shippingAddress->expects($this->once()) ->method('getCountryId')->will($this->returnValue($countryId)); - $this->shippingAddressMock->expects($this->once()) + $this->shippingAddress->expects($this->once()) ->method('setShippingMethod')->with($carrierCode . '_' . $methodCode); - $this->shippingAddressMock->expects($this->once()) + $this->shippingAddress->expects($this->once()) ->method('getShippingRateByCode')->will($this->returnValue(false)); - $this->shippingAddressMock->expects($this->never())->method('save'); + $this->shippingAddress->expects($this->never())->method('save'); $this->model->set($cartId, $carrierCode, $methodCode); } @@ -359,23 +371,23 @@ public function testSetMethodWithCouldNotSaveException() $methodCode = 56; $countryId = 1; - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once())->method('getItemsCount')->will($this->returnValue(1)); - $this->quoteMock->expects($this->once())->method('isVirtual')->will($this->returnValue(false)); - $this->quoteMock->expects($this->once()) - ->method('getShippingAddress')->will($this->returnValue($this->shippingAddressMock)); - $this->shippingAddressMock->expects($this->once()) + $this->quoteRepository->expects($this->once()) + ->method('getActive')->with($cartId)->will($this->returnValue($this->quote)); + $this->quote->expects($this->once())->method('getItemsCount')->will($this->returnValue(1)); + $this->quote->expects($this->once())->method('isVirtual')->will($this->returnValue(false)); + $this->quote->expects($this->once()) + ->method('getShippingAddress')->will($this->returnValue($this->shippingAddress)); + $this->shippingAddress->expects($this->once()) ->method('getCountryId')->will($this->returnValue($countryId)); - $this->shippingAddressMock->expects($this->once()) + $this->shippingAddress->expects($this->once()) ->method('setShippingMethod')->with($carrierCode . '_' . $methodCode); - $this->shippingAddressMock->expects($this->once()) + $this->shippingAddress->expects($this->once()) ->method('getShippingRateByCode')->will($this->returnValue(true)); $exception = new \Exception('Custom Error'); - $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnSelf()); - $this->quoteRepositoryMock->expects($this->once()) + $this->quote->expects($this->once())->method('collectTotals')->will($this->returnSelf()); + $this->quoteRepository->expects($this->once()) ->method('save') - ->with($this->quoteMock) + ->with($this->quote) ->willThrowException($exception); $this->model->set($cartId, $carrierCode, $methodCode); @@ -391,13 +403,13 @@ public function testSetMethodWithoutAddress() $cartId = 12; $carrierCode = 34; $methodCode = 56; - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once())->method('getItemsCount')->will($this->returnValue(1)); - $this->quoteMock->expects($this->once())->method('isVirtual')->will($this->returnValue(false)); - $this->quoteMock->expects($this->once()) - ->method('getShippingAddress')->will($this->returnValue($this->shippingAddressMock)); - $this->shippingAddressMock->expects($this->once())->method('getCountryId'); + $this->quoteRepository->expects($this->once()) + ->method('getActive')->with($cartId)->will($this->returnValue($this->quote)); + $this->quote->expects($this->once())->method('getItemsCount')->will($this->returnValue(1)); + $this->quote->expects($this->once())->method('isVirtual')->will($this->returnValue(false)); + $this->quote->expects($this->once()) + ->method('getShippingAddress')->will($this->returnValue($this->shippingAddress)); + $this->shippingAddress->expects($this->once())->method('getCountryId'); $this->model->set($cartId, $carrierCode, $methodCode); } @@ -409,21 +421,99 @@ public function testSetMethod() $carrierCode = 34; $methodCode = 56; $countryId = 1; - $this->quoteRepositoryMock->expects($this->once()) - ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock)); - $this->quoteMock->expects($this->once())->method('getItemsCount')->will($this->returnValue(1)); - $this->quoteMock->expects($this->once())->method('isVirtual')->will($this->returnValue(false)); - $this->quoteMock->expects($this->once()) - ->method('getShippingAddress')->will($this->returnValue($this->shippingAddressMock)); - $this->shippingAddressMock->expects($this->once()) + $this->quoteRepository->expects($this->once()) + ->method('getActive')->with($cartId)->will($this->returnValue($this->quote)); + $this->quote->expects($this->once())->method('getItemsCount')->will($this->returnValue(1)); + $this->quote->expects($this->once())->method('isVirtual')->will($this->returnValue(false)); + $this->quote->expects($this->once()) + ->method('getShippingAddress')->will($this->returnValue($this->shippingAddress)); + $this->shippingAddress->expects($this->once()) ->method('getCountryId')->will($this->returnValue($countryId)); - $this->shippingAddressMock->expects($this->once()) + $this->shippingAddress->expects($this->once()) ->method('setShippingMethod')->with($carrierCode . '_' . $methodCode); - $this->shippingAddressMock->expects($this->once()) + $this->shippingAddress->expects($this->once()) ->method('getShippingRateByCode')->will($this->returnValue(true)); - $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnSelf()); - $this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock); + $this->quote->expects($this->once())->method('collectTotals')->will($this->returnSelf()); + $this->quoteRepository->expects($this->once())->method('save')->with($this->quote); $this->assertTrue($this->model->set($cartId, $carrierCode, $methodCode)); } + + /** + * @covers \Magento\Quote\Model\ShippingMethodManagement::estimateByExtendedAddress + */ + public function testEstimateByExtendedAddress() + { + $cartId = 1; + + $addressData = [ + 'region' => 'California', + 'region_id' => 23, + 'country_id' => 1, + 'postcode' => 90200 + ]; + $currencyCode = 'UAH'; + + $address = $this->getMockBuilder(Address::class) + ->disableOriginalConstructor() + ->setMethods(['getData']) + ->getMock(); + + $this->quoteRepository->expects(static::once()) + ->method('getActive') + ->with($cartId) + ->willReturn($this->quote); + + $this->quote->expects(static::once()) + ->method('isVirtual') + ->willReturn(false); + $this->quote->expects(static::once()) + ->method('getItemsCount') + ->willReturn(1); + + $address->expects(static::once()) + ->method('getData') + ->willReturn($addressData); + + $this->quote->expects(static::once()) + ->method('getShippingAddress') + ->willReturn($this->shippingAddress); + + $this->shippingAddress->expects(static::once()) + ->method('addData') + ->with($addressData) + ->willReturnSelf(); + $this->shippingAddress->expects(static::once()) + ->method('setCollectShippingRates') + ->with(true) + ->willReturnSelf(); + + $this->totalsCollector->expects(static::once()) + ->method('collectAddressTotals') + ->with($this->quote, $this->shippingAddress) + ->willReturnSelf(); + + $rate = $this->getMockBuilder(Rate::class) + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + $methodObject = $this->getMockForAbstractClass(ShippingMethodInterface::class); + $expectedRates = [$methodObject]; + + $this->shippingAddress->expects(static::once()) + ->method('getGroupedAllShippingRates') + ->willReturn([[$rate]]); + + $this->quote->expects(static::once()) + ->method('getQuoteCurrencyCode') + ->willReturn($currencyCode); + + $this->converter->expects(static::once()) + ->method('modelToDataObject') + ->with($rate, $currencyCode) + ->willReturn($methodObject); + + $carriersRates = $this->model->estimateByExtendedAddress($cartId, $address); + static::assertEquals($expectedRates, $carriersRates); + } } diff --git a/app/code/Magento/Quote/etc/di.xml b/app/code/Magento/Quote/etc/di.xml index 80446c2bcce64..e3192f1c1d58e 100644 --- a/app/code/Magento/Quote/etc/di.xml +++ b/app/code/Magento/Quote/etc/di.xml @@ -7,6 +7,7 @@ --> + @@ -34,6 +35,7 @@ + diff --git a/app/code/Magento/Quote/etc/webapi.xml b/app/code/Magento/Quote/etc/webapi.xml index a71be0f762203..1947be77c2a76 100644 --- a/app/code/Magento/Quote/etc/webapi.xml +++ b/app/code/Magento/Quote/etc/webapi.xml @@ -114,7 +114,7 @@ - + @@ -137,7 +137,7 @@ - + @@ -163,7 +163,7 @@ - + From d04a4390a3da0a941545b9b334af84396f0fba58 Mon Sep 17 00:00:00 2001 From: Ievgen Sentiabov Date: Sat, 14 May 2016 10:37:37 +0300 Subject: [PATCH 22/22] MAGETWO-52308: [Github] Not full request information in collectRates() method on Checkout page - Fixed failed static tests --- .../Magento/Quote/Api/GuestShipmentEstimationInterface.php | 5 ++++- .../Quote/Test/Unit/Model/ShippingMethodManagementTest.php | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Quote/Api/GuestShipmentEstimationInterface.php b/app/code/Magento/Quote/Api/GuestShipmentEstimationInterface.php index 01befb6c7a964..b0690c6be445b 100644 --- a/app/code/Magento/Quote/Api/GuestShipmentEstimationInterface.php +++ b/app/code/Magento/Quote/Api/GuestShipmentEstimationInterface.php @@ -9,4 +9,7 @@ * Interface GuestShipmentEstimationInterface * @api */ -interface GuestShipmentEstimationInterface extends ShipmentEstimationInterface{} +interface GuestShipmentEstimationInterface extends ShipmentEstimationInterface +{ + +} diff --git a/app/code/Magento/Quote/Test/Unit/Model/ShippingMethodManagementTest.php b/app/code/Magento/Quote/Test/Unit/Model/ShippingMethodManagementTest.php index 0ad933fb379ac..51cbdea420cc1 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/ShippingMethodManagementTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/ShippingMethodManagementTest.php @@ -18,6 +18,9 @@ use Magento\Quote\Model\ShippingMethodManagement; use PHPUnit_Framework_MockObject_MockObject as MockObject; +/** + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class ShippingMethodManagementTest extends \PHPUnit_Framework_TestCase { /**