Skip to content

Commit 7bc09eb

Browse files
committed
Merge branch 'MC-31381' into 2.3-develop-com-pr25
2 parents fbd3fe1 + b15d665 commit 7bc09eb

10 files changed

+740
-74
lines changed
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Persistent\Block\Form;
9+
10+
use Magento\Framework\ObjectManagerInterface;
11+
use Magento\Framework\View\LayoutInterface;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
use Magento\TestFramework\Helper\Xpath;
14+
use PHPUnit\Framework\TestCase;
15+
16+
/**
17+
* Test for remember me checkbox on create customer account page
18+
*
19+
* @see \Magento\Persistent\Block\Form\Remember
20+
* @magentoAppArea frontend
21+
*/
22+
class RememberTest extends TestCase
23+
{
24+
/** @var ObjectManagerInterface */
25+
private $objectManager;
26+
27+
/** @var Remember */
28+
private $block;
29+
30+
/**
31+
* @inheritdoc
32+
*/
33+
public function setUp()
34+
{
35+
parent::setUp();
36+
37+
$this->objectManager = Bootstrap::getObjectManager();
38+
$this->block = $this->objectManager->get(LayoutInterface::class)->createBlock(Remember::class)
39+
->setTemplate('Magento_Persistent::remember_me.phtml');
40+
}
41+
42+
/**
43+
* @magentoConfigFixture current_store persistent/options/enabled 1
44+
* @magentoConfigFixture current_store persistent/options/remember_enabled 1
45+
* @magentoConfigFixture current_store persistent/options/remember_default 0
46+
*
47+
* @return void
48+
*/
49+
public function testRememberMeEnabled(): void
50+
{
51+
$html = $this->block->toHtml();
52+
$this->assertFalse($this->block->isRememberMeChecked());
53+
$this->assertEquals(
54+
1,
55+
Xpath::getElementsCountForXpath(
56+
sprintf(
57+
'//input[@name="persistent_remember_me"]/following-sibling::label/span[contains(text(), "%s")]',
58+
__('Remember Me')
59+
),
60+
$html
61+
),
62+
'Remember Me checkbox wasn\'t found.'
63+
);
64+
}
65+
66+
/**
67+
* @magentoConfigFixture current_store persistent/options/enabled 1
68+
* @magentoConfigFixture current_store persistent/options/remember_enabled 1
69+
* @magentoConfigFixture current_store persistent/options/remember_default 1
70+
*
71+
* @return void
72+
*/
73+
public function testRememberMeAndRememberDefaultEnabled(): void
74+
{
75+
$blockHtml = $this->block->toHtml();
76+
$this->assertTrue($this->block->isRememberMeChecked());
77+
$this->assertEquals(
78+
1,
79+
Xpath::getElementsCountForXpath(
80+
sprintf(
81+
'//input[@name="persistent_remember_me"]/following-sibling::label/span[contains(text(), "%s")]',
82+
__('Remember Me')
83+
),
84+
$blockHtml
85+
),
86+
'Remember Me checkbox wasn\'t found or not checked by default.'
87+
);
88+
}
89+
90+
/**
91+
* @magentoConfigFixture current_store persistent/options/enabled 0
92+
*
93+
* @return void
94+
*/
95+
public function testPersistentDisabled(): void
96+
{
97+
$this->assertEmpty($this->block->toHtml());
98+
}
99+
100+
/**
101+
* @magentoConfigFixture current_store persistent/options/enabled 1
102+
* @magentoConfigFixture current_store persistent/options/remember_enabled 0
103+
*
104+
* @return void
105+
*/
106+
public function testRememberMeDisabled(): void
107+
{
108+
$this->assertEmpty($this->block->toHtml());
109+
}
110+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Persistent\Helper;
9+
10+
use Magento\Framework\ObjectManagerInterface;
11+
use Magento\Persistent\Model\SessionFactory;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
use PHPUnit\Framework\TestCase;
14+
15+
/**
16+
* Test for persistent session helper
17+
*
18+
* @see \Magento\Persistent\Helper\Session
19+
* @magentoDbIsolation enabled
20+
*/
21+
class SessionTest extends TestCase
22+
{
23+
/** @var ObjectManagerInterface */
24+
private $objectManager;
25+
26+
/** @var Session */
27+
private $helper;
28+
29+
/** @var SessionFactory */
30+
private $sessionFactory;
31+
32+
/**
33+
* @inheritdoc
34+
*/
35+
public function setUp()
36+
{
37+
parent::setUp();
38+
39+
$this->objectManager = Bootstrap::getObjectManager();
40+
$this->helper = $this->objectManager->get(Session::class);
41+
$this->sessionFactory = $this->objectManager->get(SessionFactory::class);
42+
}
43+
44+
/**
45+
* @magentoDataFixture Magento/Persistent/_files/persistent.php
46+
* @magentoConfigFixture current_store persistent/options/enabled 1
47+
*
48+
* @return void
49+
*/
50+
public function testPersistentEnabled(): void
51+
{
52+
$session = $this->sessionFactory->create()->loadByCustomerId(1);
53+
$this->helper->setSession($session);
54+
$this->assertTrue($this->helper->isPersistent());
55+
}
56+
57+
/**
58+
* @magentoDataFixture Magento/Persistent/_files/persistent.php
59+
* @magentoConfigFixture current_store persistent/options/enabled 0
60+
*
61+
* @return void
62+
*/
63+
public function testPersistentDisabled(): void
64+
{
65+
$session = $this->sessionFactory->create()->loadByCustomerId(1);
66+
$this->helper->setSession($session);
67+
$this->assertFalse($this->helper->isPersistent());
68+
}
69+
70+
/**
71+
* @magentoDataFixture Magento/Customer/_files/customer.php
72+
* @magentoConfigFixture current_store persistent/options/enabled 1
73+
*
74+
* @return void
75+
*/
76+
public function testCustomerWithoutPersistent(): void
77+
{
78+
$session = $this->sessionFactory->create()->loadByCustomerId(1);
79+
$this->helper->setSession($session);
80+
$this->assertFalse($this->helper->isPersistent());
81+
}
82+
}
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Persistent\Model\Checkout;
9+
10+
use Magento\Customer\Model\Session as CustomerSession;
11+
use Magento\Checkout\Model\DefaultConfigProvider;
12+
use Magento\Checkout\Model\Session as CheckoutSession;
13+
use Magento\Framework\ObjectManagerInterface;
14+
use Magento\Persistent\Helper\Session as PersistentSessionHelper;
15+
use Magento\Persistent\Model\Session as PersistentSession;
16+
use Magento\Persistent\Model\SessionFactory as PersistentSessionFactory;
17+
use Magento\Quote\Model\QuoteIdMask;
18+
use Magento\Quote\Model\QuoteIdMaskFactory;
19+
use Magento\TestFramework\Helper\Bootstrap;
20+
use Magento\TestFramework\Interception\PluginList;
21+
use Magento\TestFramework\Quote\Model\GetQuoteByReservedOrderId;
22+
use PHPUnit\Framework\TestCase;
23+
24+
/**
25+
* Test for checkout config provider plugin
26+
*
27+
* @see \Magento\Persistent\Model\Checkout\ConfigProviderPlugin
28+
* @magentoAppArea frontend
29+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
30+
*/
31+
class ConfigProviderPluginTest extends TestCase
32+
{
33+
/** @var ObjectManagerInterface */
34+
private $objectManager;
35+
36+
/** @var DefaultConfigProvider */
37+
private $configProvider;
38+
39+
/** @var CustomerSession */
40+
private $customerSession;
41+
42+
/** @var CheckoutSession */
43+
private $checkoutSession;
44+
45+
/** @var QuoteIdMask */
46+
private $quoteIdMask;
47+
48+
/** @var PersistentSessionHelper */
49+
private $persistentSessionHelper;
50+
51+
/** @var PersistentSession */
52+
private $persistentSession;
53+
54+
/** @var GetQuoteByReservedOrderId */
55+
private $getQuoteByReservedOrderId;
56+
57+
/**
58+
* @inheritdoc
59+
*/
60+
protected function setUp()
61+
{
62+
parent::setUp();
63+
64+
$this->objectManager = Bootstrap::getObjectManager();
65+
$this->configProvider = $this->objectManager->get(DefaultConfigProvider::class);
66+
$this->customerSession = $this->objectManager->get(CustomerSession::class);
67+
$this->checkoutSession = $this->objectManager->get(CheckoutSession::class);
68+
$this->quoteIdMask = $this->objectManager->get(QuoteIdMaskFactory::class)->create();
69+
$this->persistentSessionHelper = $this->objectManager->get(PersistentSessionHelper::class);
70+
$this->persistentSession = $this->objectManager->get(PersistentSessionFactory::class)->create();
71+
$this->getQuoteByReservedOrderId = $this->objectManager->get(GetQuoteByReservedOrderId::class);
72+
}
73+
74+
/**
75+
* @inheritdoc
76+
*/
77+
protected function tearDown()
78+
{
79+
$this->customerSession->setCustomerId(null);
80+
$this->checkoutSession->clearQuote();
81+
$this->checkoutSession->setCustomerData(null);
82+
83+
parent::tearDown();
84+
}
85+
86+
/**
87+
* @return void
88+
*/
89+
public function testPluginIsRegistered(): void
90+
{
91+
$pluginInfo = $this->objectManager->get(PluginList::class)->get(DefaultConfigProvider::class);
92+
$this->assertSame(ConfigProviderPlugin::class, $pluginInfo['mask_quote_id_substitutor']['instance']);
93+
}
94+
95+
/**
96+
* @magentoDataFixture Magento/Persistent/_files/persistent_with_customer_quote_and_cookie.php
97+
* @magentoConfigFixture current_store persistent/options/enabled 1
98+
*
99+
* @return void
100+
*/
101+
public function testWithNotLoggedCustomer(): void
102+
{
103+
$session = $this->persistentSession->loadByCustomerId(1);
104+
$this->persistentSessionHelper->setSession($session);
105+
$quote = $this->getQuoteByReservedOrderId->execute('test_order_with_customer_without_address');
106+
$this->checkoutSession->setQuoteId($quote->getId());
107+
$result = $this->configProvider->getConfig();
108+
$this->assertEquals(
109+
$this->quoteIdMask->load($quote->getId(), 'quote_id')->getMaskedId(),
110+
$result['quoteData']['entity_id']
111+
);
112+
}
113+
114+
/**
115+
* @magentoDataFixture Magento/Persistent/_files/persistent_with_customer_quote_and_cookie.php
116+
* @magentoConfigFixture current_store persistent/options/enabled 1
117+
*
118+
* @return void
119+
*/
120+
public function testWithLoggedCustomer(): void
121+
{
122+
$this->customerSession->setCustomerId(1);
123+
$session = $this->persistentSession->loadByCustomerId(1);
124+
$this->persistentSessionHelper->setSession($session);
125+
$quote = $this->getQuoteByReservedOrderId->execute('test_order_with_customer_without_address');
126+
$this->checkoutSession->setQuoteId($quote->getId());
127+
$result = $this->configProvider->getConfig();
128+
$this->assertEquals($quote->getId(), $result['quoteData']['entity_id']);
129+
}
130+
131+
/**
132+
* @magentoDataFixture Magento/Persistent/_files/persistent_with_customer_quote_and_cookie.php
133+
* @magentoConfigFixture current_store persistent/options/enabled 0
134+
*
135+
* @return void
136+
*/
137+
public function testPersistentDisabled(): void
138+
{
139+
$quote = $this->getQuoteByReservedOrderId->execute('test_order_with_customer_without_address');
140+
$this->checkoutSession->setQuoteId($quote->getId());
141+
$result = $this->configProvider->getConfig();
142+
$this->assertNull($result['quoteData']['entity_id']);
143+
}
144+
145+
/**
146+
* @magentoDataFixture Magento/Persistent/_files/persistent_with_customer_quote_and_cookie.php
147+
* @magentoConfigFixture current_store persistent/options/enabled 1
148+
*
149+
* @return void
150+
*/
151+
public function testWithoutPersistentSession(): void
152+
{
153+
$quote = $this->getQuoteByReservedOrderId->execute('test_order_with_customer_without_address');
154+
$this->checkoutSession->setQuoteId($quote->getId());
155+
$result = $this->configProvider->getConfig();
156+
$this->assertNull($result['quoteData']['entity_id']);
157+
}
158+
}

0 commit comments

Comments
 (0)