From 40e8a16654f31b5036097648cb3c8c92a55fc94a Mon Sep 17 00:00:00 2001 From: Tommy Quissens Date: Mon, 11 Dec 2017 15:25:53 +0100 Subject: [PATCH 1/7] Add customer login url from Customer Url model to checkout config so it contains the referer url if necessary --- .../Magento/Customer/Model/Checkout/ConfigProvider.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Customer/Model/Checkout/ConfigProvider.php b/app/code/Magento/Customer/Model/Checkout/ConfigProvider.php index a333fe8df594a..6b84ca9aaaa9a 100644 --- a/app/code/Magento/Customer/Model/Checkout/ConfigProvider.php +++ b/app/code/Magento/Customer/Model/Checkout/ConfigProvider.php @@ -23,7 +23,7 @@ class ConfigProvider implements ConfigProviderInterface /** * @var UrlInterface */ - protected $urlBuilder; + protected $customerUrl; /** * @var ScopeConfigInterface @@ -31,16 +31,16 @@ class ConfigProvider implements ConfigProviderInterface protected $scopeConfig; /** - * @param UrlInterface $urlBuilder + * @param Url $customerUrl * @param StoreManagerInterface $storeManager * @param ScopeConfigInterface $scopeConfig */ public function __construct( - UrlInterface $urlBuilder, + Url $customerUrl, StoreManagerInterface $storeManager, ScopeConfigInterface $scopeConfig ) { - $this->urlBuilder = $urlBuilder; + $this->customerUrl = $customerUrl; $this->storeManager = $storeManager; $this->scopeConfig = $scopeConfig; } @@ -78,7 +78,7 @@ protected function isAutocompleteEnabled() */ protected function getLoginUrl() { - return $this->urlBuilder->getUrl(Url::ROUTE_ACCOUNT_LOGIN); + return $this->customerUrl->getLoginUrl(); } /** From 73b90076e69925773f3d219cfcc8136f9b20c4a6 Mon Sep 17 00:00:00 2001 From: Tommy Quissens Date: Tue, 12 Dec 2017 22:40:37 +0100 Subject: [PATCH 2/7] fixed unit test for checkout configprovider --- .../Model/Checkout/ConfigProviderTest.php | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/app/code/Magento/Customer/Test/Unit/Model/Checkout/ConfigProviderTest.php b/app/code/Magento/Customer/Test/Unit/Model/Checkout/ConfigProviderTest.php index 011ba9091eaf2..6b4a3a4bc4d8e 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Checkout/ConfigProviderTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Checkout/ConfigProviderTest.php @@ -29,7 +29,7 @@ class ConfigProviderTest extends \PHPUnit\Framework\TestCase /** * @var UrlInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $urlBuilder; + protected $customerUrl; /** * @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject @@ -49,12 +49,9 @@ protected function setUp() '', false ); - $this->urlBuilder = $this->getMockForAbstractClass( - \Magento\Framework\UrlInterface::class, - [], - '', - false - ); + + $this->customerUrl = $this->createMock(\Magento\Customer\Model\Url::class); + $this->scopeConfig = $this->getMockForAbstractClass( \Magento\Framework\App\Config\ScopeConfigInterface::class, [], @@ -72,7 +69,7 @@ protected function setUp() ); $this->provider = new ConfigProvider( - $this->urlBuilder, + $this->customerUrl, $this->storeManager, $this->scopeConfig ); @@ -83,9 +80,8 @@ public function testGetConfigWithoutRedirect() $loginUrl = 'http://url.test/customer/login'; $baseUrl = 'http://base-url.test'; - $this->urlBuilder->expects($this->exactly(2)) - ->method('getUrl') - ->with(Url::ROUTE_ACCOUNT_LOGIN) + $this->customerUrl->expects($this->exactly(2)) + ->method('getLoginUrl') ->willReturn($loginUrl); $this->storeManager->expects($this->once()) ->method('getStore') @@ -112,9 +108,8 @@ public function testGetConfig() $loginUrl = 'http://base-url.test/customer/login'; $baseUrl = 'http://base-url.test'; - $this->urlBuilder->expects($this->exactly(2)) - ->method('getUrl') - ->with(Url::ROUTE_ACCOUNT_LOGIN) + $this->customerUrl->expects($this->exactly(2)) + ->method('getLoginUrl') ->willReturn($loginUrl); $this->storeManager->expects($this->once()) ->method('getStore') From bbf865f09479360b06301fa3401b3de44874bd97 Mon Sep 17 00:00:00 2001 From: Tommy Quissens Date: Thu, 14 Dec 2017 10:02:52 +0100 Subject: [PATCH 3/7] updated code following code review & backward compatible development guide --- .../Model/Checkout/ConfigProvider.php | 17 +++++++++++---- .../Model/Checkout/ConfigProviderTest.php | 21 +++++++++++++++---- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/Customer/Model/Checkout/ConfigProvider.php b/app/code/Magento/Customer/Model/Checkout/ConfigProvider.php index 6b84ca9aaaa9a..4b87b3fa502e9 100644 --- a/app/code/Magento/Customer/Model/Checkout/ConfigProvider.php +++ b/app/code/Magento/Customer/Model/Checkout/ConfigProvider.php @@ -22,6 +22,12 @@ class ConfigProvider implements ConfigProviderInterface /** * @var UrlInterface + * @deprecated + */ + protected $urlBuilder; + + /** + * @var Url */ protected $customerUrl; @@ -31,18 +37,21 @@ class ConfigProvider implements ConfigProviderInterface protected $scopeConfig; /** - * @param Url $customerUrl + * @param UrlInterface $urlBuilder * @param StoreManagerInterface $storeManager * @param ScopeConfigInterface $scopeConfig + * @param Url $customerUrl */ public function __construct( - Url $customerUrl, + UrlInterface $urlBuilder, StoreManagerInterface $storeManager, - ScopeConfigInterface $scopeConfig + ScopeConfigInterface $scopeConfig, + Url $customerUrl = null ) { - $this->customerUrl = $customerUrl; + $this->urlBuilder=$urlBuilder; $this->storeManager = $storeManager; $this->scopeConfig = $scopeConfig; + $this->customerUrl = $customerUrl ?? \Magento\Framework\App\ObjectManager::getInstance()->get(\Magento\Customer\Model\Url::class); } /** diff --git a/app/code/Magento/Customer/Test/Unit/Model/Checkout/ConfigProviderTest.php b/app/code/Magento/Customer/Test/Unit/Model/Checkout/ConfigProviderTest.php index 6b4a3a4bc4d8e..58b099a1d387d 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Checkout/ConfigProviderTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Checkout/ConfigProviderTest.php @@ -29,7 +29,7 @@ class ConfigProviderTest extends \PHPUnit\Framework\TestCase /** * @var UrlInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $customerUrl; + protected $urlBuilder; /** * @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject @@ -41,6 +41,11 @@ class ConfigProviderTest extends \PHPUnit\Framework\TestCase */ protected $store; + /** + * @var Url|\PHPUnit_Framework_MockObject_MockObject + */ + private $customerUrl; + protected function setUp() { $this->storeManager = $this->getMockForAbstractClass( @@ -50,7 +55,12 @@ protected function setUp() false ); - $this->customerUrl = $this->createMock(\Magento\Customer\Model\Url::class); + $this->urlBuilder = $this->getMockForAbstractClass( + \Magento\Framework\UrlInterface::class, + [], + '', + false + ); $this->scopeConfig = $this->getMockForAbstractClass( \Magento\Framework\App\Config\ScopeConfigInterface::class, @@ -68,10 +78,13 @@ protected function setUp() ['getBaseUrl'] ); + $this->customerUrl = $this->createMock(\Magento\Customer\Model\Url::class); + $this->provider = new ConfigProvider( - $this->customerUrl, + $this->urlBuilder, $this->storeManager, - $this->scopeConfig + $this->scopeConfig, + $this->customerUrl ); } From 71d1dfe98d455cb7c2142e6d80d448f8c7796581 Mon Sep 17 00:00:00 2001 From: Tommy Quissens Date: Thu, 14 Dec 2017 10:04:46 +0100 Subject: [PATCH 4/7] updated code following code review & backward compatible development guide --- .../Magento/Customer/Model/Checkout/ConfigProvider.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Customer/Model/Checkout/ConfigProvider.php b/app/code/Magento/Customer/Model/Checkout/ConfigProvider.php index 4b87b3fa502e9..1e8b3daddae93 100644 --- a/app/code/Magento/Customer/Model/Checkout/ConfigProvider.php +++ b/app/code/Magento/Customer/Model/Checkout/ConfigProvider.php @@ -27,14 +27,14 @@ class ConfigProvider implements ConfigProviderInterface protected $urlBuilder; /** - * @var Url + * @var ScopeConfigInterface */ - protected $customerUrl; + protected $scopeConfig; /** - * @var ScopeConfigInterface + * @var Url */ - protected $scopeConfig; + private $customerUrl; /** * @param UrlInterface $urlBuilder From 91213183b9190f348b5c87f35f5c2a4683fcb698 Mon Sep 17 00:00:00 2001 From: Tommy Quissens Date: Thu, 14 Dec 2017 10:27:01 +0100 Subject: [PATCH 5/7] fixed code styles --- app/code/Magento/Customer/Model/Checkout/ConfigProvider.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Customer/Model/Checkout/ConfigProvider.php b/app/code/Magento/Customer/Model/Checkout/ConfigProvider.php index 1e8b3daddae93..2ad32b0b42209 100644 --- a/app/code/Magento/Customer/Model/Checkout/ConfigProvider.php +++ b/app/code/Magento/Customer/Model/Checkout/ConfigProvider.php @@ -51,7 +51,8 @@ public function __construct( $this->urlBuilder=$urlBuilder; $this->storeManager = $storeManager; $this->scopeConfig = $scopeConfig; - $this->customerUrl = $customerUrl ?? \Magento\Framework\App\ObjectManager::getInstance()->get(\Magento\Customer\Model\Url::class); + $this->customerUrl = $customerUrl ?? \Magento\Framework\App\ObjectManager::getInstance() + ->get(\Magento\Customer\Model\Url::class); } /** From 1313861fbd00fae8d62ad6f7dda464700fc8ada3 Mon Sep 17 00:00:00 2001 From: Tommy Quissens Date: Thu, 14 Dec 2017 11:46:01 +0100 Subject: [PATCH 6/7] add nullable in comment & code cleanup --- app/code/Magento/Customer/Model/Checkout/ConfigProvider.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Customer/Model/Checkout/ConfigProvider.php b/app/code/Magento/Customer/Model/Checkout/ConfigProvider.php index 2ad32b0b42209..3746e0ae2a819 100644 --- a/app/code/Magento/Customer/Model/Checkout/ConfigProvider.php +++ b/app/code/Magento/Customer/Model/Checkout/ConfigProvider.php @@ -40,7 +40,7 @@ class ConfigProvider implements ConfigProviderInterface * @param UrlInterface $urlBuilder * @param StoreManagerInterface $storeManager * @param ScopeConfigInterface $scopeConfig - * @param Url $customerUrl + * @param Url|null $customerUrl */ public function __construct( UrlInterface $urlBuilder, @@ -48,7 +48,7 @@ public function __construct( ScopeConfigInterface $scopeConfig, Url $customerUrl = null ) { - $this->urlBuilder=$urlBuilder; + $this->urlBuilder = $urlBuilder; $this->storeManager = $storeManager; $this->scopeConfig = $scopeConfig; $this->customerUrl = $customerUrl ?? \Magento\Framework\App\ObjectManager::getInstance() From 202503562a66f999b6fec76b967ec8fb0c53a11c Mon Sep 17 00:00:00 2001 From: Tommy Quissens Date: Thu, 14 Dec 2017 12:10:22 +0100 Subject: [PATCH 7/7] code cleanup --- app/code/Magento/Customer/Model/Checkout/ConfigProvider.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Customer/Model/Checkout/ConfigProvider.php b/app/code/Magento/Customer/Model/Checkout/ConfigProvider.php index 3746e0ae2a819..36eabe3571ceb 100644 --- a/app/code/Magento/Customer/Model/Checkout/ConfigProvider.php +++ b/app/code/Magento/Customer/Model/Checkout/ConfigProvider.php @@ -7,6 +7,7 @@ use Magento\Checkout\Model\ConfigProviderInterface; use Magento\Customer\Model\Url; +use Magento\Framework\App\ObjectManager; use Magento\Framework\UrlInterface; use Magento\Store\Model\StoreManagerInterface; use Magento\Framework\App\Config\ScopeConfigInterface; @@ -51,8 +52,8 @@ public function __construct( $this->urlBuilder = $urlBuilder; $this->storeManager = $storeManager; $this->scopeConfig = $scopeConfig; - $this->customerUrl = $customerUrl ?? \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Customer\Model\Url::class); + $this->customerUrl = $customerUrl ?? ObjectManager::getInstance() + ->get(Url::class); } /**