init
This commit is contained in:
+59
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Customer\Block\Account;
|
||||
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\View\LayoutInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Tests for authentication popup block.
|
||||
*
|
||||
* @see \Magento\Customer\Block\Account\AuthenticationPopup
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class AuthenticationPopupTest extends TestCase
|
||||
{
|
||||
/** @var ObjectManagerInterface */
|
||||
private $objectManager;
|
||||
|
||||
/** @var AuthenticationPopup */
|
||||
private $block;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->block = $this->objectManager->get(LayoutInterface::class)->createBlock(AuthenticationPopup::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoConfigFixture current_store customer/password/autocomplete_on_storefront 1
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAutocompletePasswordEnabled(): void
|
||||
{
|
||||
$this->assertEquals('on', $this->block->getConfig()['autocomplete']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoConfigFixture current_store customer/password/autocomplete_on_storefront 0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAutocompletePasswordDisabled(): void
|
||||
{
|
||||
$this->assertEquals('off', $this->block->getConfig()['autocomplete']);
|
||||
}
|
||||
}
|
||||
+175
@@ -0,0 +1,175 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Customer\Block\Account\Dashboard;
|
||||
|
||||
use Magento\Customer\Api\CustomerRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Class address test.
|
||||
*/
|
||||
class AddressTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Customer\Block\Account\Dashboard\Address
|
||||
*/
|
||||
protected $_block;
|
||||
|
||||
/** @var \Magento\Customer\Model\Session */
|
||||
protected $_customerSession;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
protected $objectManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->_customerSession = $this->objectManager->get(\Magento\Customer\Model\Session::class);
|
||||
$this->_block = $this->objectManager->get(\Magento\Framework\View\LayoutInterface::class)
|
||||
->createBlock(
|
||||
\Magento\Customer\Block\Account\Dashboard\Address::class,
|
||||
'',
|
||||
['customerSession' => $this->_customerSession]
|
||||
);
|
||||
$this->objectManager->get(\Magento\Framework\App\ViewInterface::class)->setIsLayoutLoaded(true);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->_customerSession->unsCustomerId();
|
||||
/** @var \Magento\Customer\Model\CustomerRegistry $customerRegistry */
|
||||
$customerRegistry = $this->objectManager->get(\Magento\Customer\Model\CustomerRegistry::class);
|
||||
//Cleanup customer from registry
|
||||
$customerRegistry->remove(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
*/
|
||||
public function testGetCustomer()
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$layout = $objectManager->get(\Magento\Framework\View\LayoutInterface::class);
|
||||
$layout->setIsCacheable(false);
|
||||
/** @var CustomerRepositoryInterface $customerRepository */
|
||||
$customerRepository = $objectManager
|
||||
->get(\Magento\Customer\Api\CustomerRepositoryInterface::class);
|
||||
$customer = $customerRepository->getById(1);
|
||||
$this->_customerSession->setCustomerId(1);
|
||||
$object = $this->_block->getCustomer();
|
||||
$this->assertEquals($customer, $object);
|
||||
$layout->setIsCacheable(true);
|
||||
}
|
||||
|
||||
public function testGetCustomerMissingCustomer()
|
||||
{
|
||||
$moduleManager = $this->objectManager->get(\Magento\Framework\Module\Manager::class);
|
||||
if ($moduleManager->isEnabled('Magento_PageCache')) {
|
||||
$customerDataFactory = $this->objectManager->create(
|
||||
\Magento\Customer\Api\Data\CustomerInterfaceFactory::class
|
||||
);
|
||||
$customerData = $customerDataFactory->create()->setGroupId($this->_customerSession->getCustomerGroupId());
|
||||
$this->assertEquals($customerData, $this->_block->getCustomer());
|
||||
} else {
|
||||
$this->assertNull($this->_block->getCustomer());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_two_addresses.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_no_address.php
|
||||
* @dataProvider getPrimaryShippingAddressHtmlDataProvider
|
||||
*/
|
||||
public function testGetPrimaryShippingAddressHtml($customerId, $expected)
|
||||
{
|
||||
// todo: this test is sensitive to caching impact
|
||||
|
||||
if (!empty($customerId)) {
|
||||
$this->_customerSession->setCustomerId($customerId);
|
||||
}
|
||||
$html = $this->_block->getPrimaryShippingAddressHtml();
|
||||
$this->assertEquals($expected, $html);
|
||||
}
|
||||
|
||||
public function getPrimaryShippingAddressHtmlDataProvider()
|
||||
{
|
||||
$expected = "John Smith<br />\nCompanyName<br />\nGreen str, 67<br />\n\n\n\nCityM, Alabama, 75477<br />"
|
||||
. "\nUnited States<br />\nT: <a href=\"tel:3468676\">3468676</a>\n\n";
|
||||
|
||||
return [
|
||||
'0' => [0, 'You have not set a default shipping address.'],
|
||||
'1' => [1, $expected],
|
||||
'5' => [5, 'You have not set a default shipping address.']
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_two_addresses.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_no_address.php
|
||||
* @dataProvider getPrimaryBillingAddressHtmlDataProvider
|
||||
*/
|
||||
public function testGetPrimaryBillingAddressHtml($customerId, $expected)
|
||||
{
|
||||
if (!empty($customerId)) {
|
||||
$this->_customerSession->setCustomerId($customerId);
|
||||
}
|
||||
$html = $this->_block->getPrimaryBillingAddressHtml();
|
||||
$this->assertEquals($expected, $html);
|
||||
}
|
||||
|
||||
public function getPrimaryBillingAddressHtmlDataProvider()
|
||||
{
|
||||
$expected = "John Smith<br />\nCompanyName<br />\nGreen str, 67<br />\n\n\n\nCityM, Alabama, 75477<br />"
|
||||
. "\nUnited States<br />\nT: <a href=\"tel:3468676\">3468676</a>\n\n";
|
||||
return [
|
||||
'0' => [0, 'You have not set a default billing address.'],
|
||||
'1' => [1, $expected],
|
||||
'5' => [5, 'You have not set a default billing address.'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_two_addresses.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_no_address.php
|
||||
* @dataProvider getPrimaryAddressEditUrlDataProvider
|
||||
*/
|
||||
public function testGetPrimaryShippingAddressEditUrl($customerId, $expected)
|
||||
{
|
||||
if (!empty($customerId)) {
|
||||
$this->_customerSession->setCustomerId($customerId);
|
||||
}
|
||||
$url = $this->_block->getPrimaryShippingAddressEditUrl();
|
||||
$this->assertEquals($expected, $url);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_two_addresses.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_no_address.php
|
||||
* @dataProvider getPrimaryAddressEditUrlDataProvider
|
||||
*/
|
||||
public function testGetPrimaryBillingAddressEditUrl($customerId, $expected)
|
||||
{
|
||||
if (!empty($customerId)) {
|
||||
$this->_customerSession->setCustomerId($customerId);
|
||||
}
|
||||
$url = $this->_block->getPrimaryBillingAddressEditUrl();
|
||||
$this->assertEquals($expected, $url);
|
||||
}
|
||||
|
||||
public function getPrimaryAddressEditUrlDataProvider()
|
||||
{
|
||||
return [
|
||||
'1' => [1, 'http://localhost/index.php/customer/address/edit/id/1/'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Customer\Block\Account\Dashboard;
|
||||
|
||||
class InfoTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Customer\Block\Account\Dashboard\Info
|
||||
*/
|
||||
protected $_block;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
)->createBlock(
|
||||
\Magento\Customer\Block\Account\Dashboard\Info::class
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetSubscriptionObject()
|
||||
{
|
||||
$object = $this->_block->getSubscriptionObject();
|
||||
$this->assertInstanceOf(\Magento\Newsletter\Model\Subscriber::class, $object);
|
||||
|
||||
$object2 = $this->_block->getSubscriptionObject();
|
||||
$this->assertSame($object, $object2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Customer\Block\Account;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
class DashboardTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/** @var Dashboard */
|
||||
private $block;
|
||||
|
||||
/** @var \Magento\Customer\Model\Session */
|
||||
private $customerSession;
|
||||
|
||||
/** @var \Magento\Customer\Api\CustomerRepositoryInterface */
|
||||
private $customerRepository;
|
||||
|
||||
/**
|
||||
* Execute per test initialization.
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->customerSession = Bootstrap::getObjectManager()->get(\Magento\Customer\Model\Session::class);
|
||||
$this->customerRepository = Bootstrap::getObjectManager()->get(
|
||||
\Magento\Customer\Api\CustomerRepositoryInterface::class
|
||||
);
|
||||
|
||||
$this->block = Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
)->createBlock(
|
||||
\Magento\Customer\Block\Account\Dashboard::class,
|
||||
'',
|
||||
[
|
||||
'customerSession' => $this->customerSession,
|
||||
'customerRepository' => $this->customerRepository
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute per test cleanup.
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->customerSession->setCustomerId(null);
|
||||
|
||||
/** @var \Magento\Customer\Model\CustomerRegistry $customerRegistry */
|
||||
$customerRegistry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->get(\Magento\Customer\Model\CustomerRegistry::class);
|
||||
//Cleanup customer from registry
|
||||
$customerRegistry->remove(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that the Dashboard::getCustomer() method returns a valid Customer Data.
|
||||
*
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
*/
|
||||
public function testGetCustomer()
|
||||
{
|
||||
$customer = $this->customerRepository->getById(1);
|
||||
$this->customerSession->setCustomerId(1);
|
||||
$object = $this->block->getCustomer();
|
||||
$this->assertEquals($customer, $object);
|
||||
$this->assertInstanceOf(\Magento\Customer\Api\Data\CustomerInterface::class, $object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that the specified customer has neither a default billing no shipping address.
|
||||
*
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_no_address.php
|
||||
*/
|
||||
public function testGetPrimaryAddressesNoAddresses()
|
||||
{
|
||||
$this->customerSession->setCustomerId(5);
|
||||
$this->assertFalse($this->block->getPrimaryAddresses());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that the specified customer has the same default billing and shipping address.
|
||||
*
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_address.php
|
||||
*/
|
||||
public function testGetPrimaryAddressesBillingShippingSame()
|
||||
{
|
||||
$customer = $this->customerRepository->getById(1);
|
||||
$this->customerSession->setCustomerId(1);
|
||||
$addresses = $this->block->getPrimaryAddresses();
|
||||
$this->assertCount(1, $addresses);
|
||||
$address = $addresses[0];
|
||||
$this->assertInstanceOf(\Magento\Customer\Api\Data\AddressInterface::class, $address);
|
||||
$this->assertEquals((int)$customer->getDefaultBilling(), $address->getId());
|
||||
$this->assertEquals((int)$customer->getDefaultShipping(), $address->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that the specified customer has different default billing and shipping addresses.
|
||||
*
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_primary_addresses.php
|
||||
*/
|
||||
public function testGetPrimaryAddressesBillingShippingDifferent()
|
||||
{
|
||||
$this->customerSession->setCustomerId(1);
|
||||
$addresses = $this->block->getPrimaryAddresses();
|
||||
$this->assertCount(2, $addresses);
|
||||
$this->assertNotEquals($addresses[0], $addresses[1]);
|
||||
$this->assertTrue($addresses[0]->isDefaultBilling());
|
||||
$this->assertTrue($addresses[1]->isDefaultShipping());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Customer\Block\Account;
|
||||
|
||||
use Magento\Framework\Math\Random;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\View\LayoutInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Helper\Xpath;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Class checks password reset block output
|
||||
*
|
||||
* @see \Magento\Customer\Block\Account\Resetpassword
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class ResetPasswordTest extends TestCase
|
||||
{
|
||||
private const FORM_XPATH = "//form[contains(@action, '?token=%s')]";
|
||||
private const SET_NEW_PASSWORD_BUTTON_XPATH = "//button/span[contains(text(),'Set a New Password')]";
|
||||
private const NEW_PASSWORD_LABEL_XPATH = "//label[@for='password']/span[contains(text(), 'New Password')]";
|
||||
private const PASSWORD_CONFIRMATION_LABEL_XPATH = "//label[@for='password-confirmation']"
|
||||
. "/span[contains(text(), 'Confirm New Password')]";
|
||||
|
||||
/** @var ObjectManagerInterface */
|
||||
private $objectManager;
|
||||
|
||||
/** @var LayoutInterface */
|
||||
private $layout;
|
||||
|
||||
/** @var Resetpassword */
|
||||
private $block;
|
||||
|
||||
/** @var Random */
|
||||
private $random;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->layout = $this->objectManager->get(LayoutInterface::class);
|
||||
$this->random = $this->objectManager->get(Random::class);
|
||||
$this->block = $this->layout->createBlock(Resetpassword::class);
|
||||
$this->block->setTemplate('Magento_Customer::form/resetforgottenpassword.phtml');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testResetPasswordForm(): void
|
||||
{
|
||||
$token = $this->random->getUniqueHash();
|
||||
$this->block->setResetPasswordLinkToken($token);
|
||||
$output = $this->block->toHtml();
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(sprintf(self::FORM_XPATH, $token), $output),
|
||||
'Form action does not include correct token'
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(self::NEW_PASSWORD_LABEL_XPATH, $output),
|
||||
'New password label was not found on the page'
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(self::PASSWORD_CONFIRMATION_LABEL_XPATH, $output),
|
||||
'Confirm password label was not found on the page'
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(self::SET_NEW_PASSWORD_BUTTON_XPATH, $output),
|
||||
'Set password button was not found on the page'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoConfigFixture current_store customer/password/autocomplete_on_storefront 1
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAutocompletePasswordEnabled(): void
|
||||
{
|
||||
$this->assertFalse($this->block->isAutocompleteDisabled());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoConfigFixture current_store customer/password/autocomplete_on_storefront 0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAutocompletePasswordDisabled(): void
|
||||
{
|
||||
$this->assertTrue($this->block->isAutocompleteDisabled());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user