Skip to content

Commit

Permalink
MAGETWO-85672: Add customer login url from Customer Url model to chec…
Browse files Browse the repository at this point in the history
…kout config so … #12630
  • Loading branch information
Oleksii Korshenko authored Dec 22, 2017
2 parents 0eaac68 + 9b0b867 commit ea1ebff
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
15 changes: 13 additions & 2 deletions app/code/Magento/Customer/Model/Checkout/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,6 +23,7 @@ class ConfigProvider implements ConfigProviderInterface

/**
* @var UrlInterface
* @deprecated
*/
protected $urlBuilder;

Expand All @@ -30,19 +32,28 @@ class ConfigProvider implements ConfigProviderInterface
*/
protected $scopeConfig;

/**
* @var Url
*/
private $customerUrl;

/**
* @param UrlInterface $urlBuilder
* @param StoreManagerInterface $storeManager
* @param ScopeConfigInterface $scopeConfig
* @param Url|null $customerUrl
*/
public function __construct(
UrlInterface $urlBuilder,
StoreManagerInterface $storeManager,
ScopeConfigInterface $scopeConfig
ScopeConfigInterface $scopeConfig,
Url $customerUrl = null
) {
$this->urlBuilder = $urlBuilder;
$this->storeManager = $storeManager;
$this->scopeConfig = $scopeConfig;
$this->customerUrl = $customerUrl ?? ObjectManager::getInstance()
->get(Url::class);
}

/**
Expand Down Expand Up @@ -78,7 +89,7 @@ protected function isAutocompleteEnabled()
*/
protected function getLoginUrl()
{
return $this->urlBuilder->getUrl(Url::ROUTE_ACCOUNT_LOGIN);
return $this->customerUrl->getLoginUrl();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -49,12 +54,14 @@ protected function setUp()
'',
false
);

$this->urlBuilder = $this->getMockForAbstractClass(
\Magento\Framework\UrlInterface::class,
[],
'',
false
);

$this->scopeConfig = $this->getMockForAbstractClass(
\Magento\Framework\App\Config\ScopeConfigInterface::class,
[],
Expand All @@ -71,10 +78,13 @@ protected function setUp()
['getBaseUrl']
);

$this->customerUrl = $this->createMock(\Magento\Customer\Model\Url::class);

$this->provider = new ConfigProvider(
$this->urlBuilder,
$this->storeManager,
$this->scopeConfig
$this->scopeConfig,
$this->customerUrl
);
}

Expand All @@ -83,9 +93,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')
Expand All @@ -112,9 +121,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')
Expand Down

0 comments on commit ea1ebff

Please sign in to comment.