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());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Customer\Block\Address;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
class BookTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Customer\Block\Address\Book
|
||||
*/
|
||||
protected $_block;
|
||||
|
||||
/**
|
||||
* @var \Magento\Customer\Helper\Session\CurrentCustomer
|
||||
*/
|
||||
protected $currentCustomer;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
/** @var \PHPUnit\Framework\MockObject\MockObject $blockMock */
|
||||
$blockMock = $this->getMockBuilder(
|
||||
\Magento\Framework\View\Element\BlockInterface::class
|
||||
)->disableOriginalConstructor()->setMethods(
|
||||
['setTitle', 'toHtml']
|
||||
)->getMock();
|
||||
$blockMock->expects($this->any())->method('setTitle');
|
||||
|
||||
$this->currentCustomer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->get(\Magento\Customer\Helper\Session\CurrentCustomer::class);
|
||||
/** @var \Magento\Framework\View\LayoutInterface $layout */
|
||||
$layout = Bootstrap::getObjectManager()->get(\Magento\Framework\View\LayoutInterface::class);
|
||||
$layout->setBlock('head', $blockMock);
|
||||
$this->_block = $layout
|
||||
->createBlock(
|
||||
\Magento\Customer\Block\Address\Book::class,
|
||||
'',
|
||||
['currentCustomer' => $this->currentCustomer]
|
||||
);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var \Magento\Customer\Model\CustomerRegistry $customerRegistry */
|
||||
$customerRegistry = $objectManager->get(\Magento\Customer\Model\CustomerRegistry::class);
|
||||
// Cleanup customer from registry
|
||||
$customerRegistry->remove(1);
|
||||
}
|
||||
|
||||
public function testGetAddressEditUrl()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'http://localhost/index.php/customer/address/edit/id/1/',
|
||||
$this->_block->getAddressEditUrl(1)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_two_addresses.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_no_address.php
|
||||
* @dataProvider hasPrimaryAddressDataProvider
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testHasPrimaryAddress($customerId, $expected)
|
||||
{
|
||||
if (!empty($customerId)) {
|
||||
$this->currentCustomer->setCustomerId($customerId);
|
||||
}
|
||||
$this->assertEquals($expected, $this->_block->hasPrimaryAddress());
|
||||
}
|
||||
|
||||
public function hasPrimaryAddressDataProvider()
|
||||
{
|
||||
return ['0' => [0, false], '1' => [1, true], '5' => [5, false]];
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_two_addresses.php
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testGetAdditionalAddresses()
|
||||
{
|
||||
$this->currentCustomer->setCustomerId(1);
|
||||
$this->assertNotNull($this->_block->getAdditionalAddresses());
|
||||
$this->assertCount(1, $this->_block->getAdditionalAddresses());
|
||||
$this->assertInstanceOf(
|
||||
\Magento\Customer\Api\Data\AddressInterface::class,
|
||||
$this->_block->getAdditionalAddresses()[0]
|
||||
);
|
||||
$this->assertEquals(2, $this->_block->getAdditionalAddresses()[0]->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_no_address.php
|
||||
* @dataProvider getAdditionalAddressesDataProvider
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testGetAdditionalAddressesNegative($customerId, $expected)
|
||||
{
|
||||
if (!empty($customerId)) {
|
||||
$this->currentCustomer->setCustomerId($customerId);
|
||||
}
|
||||
$this->assertEquals($expected, $this->_block->getAdditionalAddresses());
|
||||
}
|
||||
|
||||
public function getAdditionalAddressesDataProvider()
|
||||
{
|
||||
return ['0' => [0, false], '5' => [5, false]];
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_address.php
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testGetAddressHtml()
|
||||
{
|
||||
$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";
|
||||
$address = Bootstrap::getObjectManager()->get(
|
||||
\Magento\Customer\Api\AddressRepositoryInterface::class
|
||||
)->getById(1);
|
||||
$html = $this->_block->getAddressHtml($address);
|
||||
$this->assertEquals($expected, $html);
|
||||
}
|
||||
|
||||
public function testGetAddressHtmlWithoutAddress()
|
||||
{
|
||||
$this->assertEquals('', $this->_block->getAddressHtml(null));
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testGetCustomer()
|
||||
{
|
||||
/** @var CustomerRepositoryInterface $customerRepository */
|
||||
$customerRepository = Bootstrap::getObjectManager()->get(
|
||||
\Magento\Customer\Api\CustomerRepositoryInterface::class
|
||||
);
|
||||
$customer = $customerRepository->getById(1);
|
||||
|
||||
$this->currentCustomer->setCustomerId(1);
|
||||
$object = $this->_block->getCustomer();
|
||||
$this->assertEquals($customer, $object);
|
||||
}
|
||||
|
||||
public function testGetCustomerMissingCustomer()
|
||||
{
|
||||
$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 getDefaultBillingDataProvider
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testGetDefaultBilling($customerId, $expected)
|
||||
{
|
||||
$this->currentCustomer->setCustomerId($customerId);
|
||||
$this->assertEquals($expected, $this->_block->getDefaultBilling());
|
||||
}
|
||||
|
||||
public function getDefaultBillingDataProvider()
|
||||
{
|
||||
return ['0' => [0, null], '1' => [1, 1], '5' => [5, null]];
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_two_addresses.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_no_address.php
|
||||
* @dataProvider getDefaultShippingDataProvider
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testGetDefaultShipping($customerId, $expected)
|
||||
{
|
||||
if (!empty($customerId)) {
|
||||
$this->currentCustomer->setCustomerId($customerId);
|
||||
}
|
||||
$this->assertEquals($expected, $this->_block->getDefaultShipping());
|
||||
}
|
||||
|
||||
public function getDefaultShippingDataProvider()
|
||||
{
|
||||
return ['0' => [0, null], '1' => [1, 1], '5' => [5, null]];
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_two_addresses.php
|
||||
*/
|
||||
public function testGetAddressById()
|
||||
{
|
||||
$this->assertInstanceOf(\Magento\Customer\Api\Data\AddressInterface::class, $this->_block->getAddressById(1));
|
||||
$this->assertNull($this->_block->getAddressById(5));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,221 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Customer\Block\Address;
|
||||
|
||||
use Magento\Customer\Model\AddressRegistry;
|
||||
use Magento\Customer\Model\CustomerRegistry;
|
||||
use Magento\Customer\Model\Session;
|
||||
use Magento\Framework\App\RequestInterface;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\View\Result\Page;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Helper\Xpath;
|
||||
use Magento\TestFramework\Store\ExecuteInStoreContext;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Tests Address Edit Block
|
||||
*
|
||||
* @see \Magento\Customer\Block\Address\Edit
|
||||
*
|
||||
* @magentoAppArea frontend
|
||||
* @magentoAppIsolation enabled
|
||||
*
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
*/
|
||||
class EditTest extends TestCase
|
||||
{
|
||||
/** @var ObjectManagerInterface */
|
||||
private $objectManager;
|
||||
|
||||
/** @var Edit */
|
||||
private $block;
|
||||
|
||||
/** @var Session */
|
||||
private $customerSession;
|
||||
|
||||
/** @var AddressRegistry */
|
||||
private $addressRegistry;
|
||||
|
||||
/** @var CustomerRegistry */
|
||||
private $customerRegistry;
|
||||
|
||||
/** @var RequestInterface */
|
||||
private $request;
|
||||
|
||||
/** @var ExecuteInStoreContext */
|
||||
private $executeInStoreContext;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->customerSession = $this->objectManager->get(Session::class);
|
||||
$this->customerSession->setCustomerId(1);
|
||||
$this->request = $this->objectManager->get(RequestInterface::class);
|
||||
$this->request->setParam('id', '1');
|
||||
/** @var Page $page */
|
||||
$page = $this->objectManager->get(PageFactory::class)->create();
|
||||
$page->addHandle(['default', 'customer_address_form']);
|
||||
$page->getLayout()->generateXml();
|
||||
$this->block = $page->getLayout()->getBlock('customer_address_edit');
|
||||
$this->addressRegistry = $this->objectManager->get(AddressRegistry::class);
|
||||
$this->customerRegistry = $this->objectManager->get(CustomerRegistry::class);
|
||||
$this->executeInStoreContext = $this->objectManager->get(ExecuteInStoreContext::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
$this->customerSession->setCustomerId(null);
|
||||
$this->request->setParam('id', null);
|
||||
//Cleanup address from registry
|
||||
$this->addressRegistry->remove(1);
|
||||
$this->addressRegistry->remove(2);
|
||||
//Cleanup customer from registry
|
||||
$this->customerRegistry->remove(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @return void
|
||||
*/
|
||||
public function testGetSaveUrl(): void
|
||||
{
|
||||
$this->assertEquals('http://localhost/index.php/customer/address/formPost/', $this->block->getSaveUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_address.php
|
||||
* @return void
|
||||
*/
|
||||
public function testGetRegionId(): void
|
||||
{
|
||||
$this->assertEquals(1, $this->block->getRegionId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_address.php
|
||||
* @return void
|
||||
*/
|
||||
public function testGetCountryId(): void
|
||||
{
|
||||
$this->assertEquals('US', $this->block->getCountryId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_two_addresses.php
|
||||
* @return void
|
||||
*/
|
||||
public function testGetCustomerAddressCount(): void
|
||||
{
|
||||
$this->assertEquals(2, $this->block->getCustomerAddressCount());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @return void
|
||||
*/
|
||||
public function testCanSetAsDefaultShipping(): void
|
||||
{
|
||||
$this->assertEquals(0, $this->block->canSetAsDefaultShipping());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @return void
|
||||
*/
|
||||
public function testIsDefaultBilling(): void
|
||||
{
|
||||
$this->assertFalse($this->block->isDefaultBilling());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_address.php
|
||||
* @return void
|
||||
*/
|
||||
public function testGetStreetLine(): void
|
||||
{
|
||||
$this->assertEquals('Green str, 67', $this->block->getStreetLine(1));
|
||||
$this->assertEquals('', $this->block->getStreetLine(2));
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoConfigFixture current_store customer/create_account/vat_frontend_visibility 1
|
||||
* @return void
|
||||
*/
|
||||
public function testVatIdFieldVisible(): void
|
||||
{
|
||||
$html = $this->block->toHtml();
|
||||
$labelXpath = "//div[contains(@class, 'taxvat')]//label/span[normalize-space(text()) = '%s']";
|
||||
$this->assertEquals(1, Xpath::getElementsCountForXpath(sprintf($labelXpath, __('VAT Number')), $html));
|
||||
$inputXpath = "//div[contains(@class, 'taxvat')]//div/input[contains(@id,'vat_id') and @type='text']";
|
||||
$this->assertEquals(1, Xpath::getElementsCountForXpath($inputXpath, $html));
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoConfigFixture current_store customer/create_account/vat_frontend_visibility 0
|
||||
* @return void
|
||||
*/
|
||||
public function testVatIdFieldNotVisible(): void
|
||||
{
|
||||
$html = $this->block->toHtml();
|
||||
$labelXpath = "//div[contains(@class, 'taxvat')]//label/span[normalize-space(text()) = '%s']";
|
||||
$this->assertEquals(0, Xpath::getElementsCountForXpath(sprintf($labelXpath, __('VAT Number')), $html));
|
||||
$inputXpath = "//div[contains(@class, 'taxvat')]//div/input[contains(@id,'vat_id') and @type='text']";
|
||||
$this->assertEquals(0, Xpath::getElementsCountForXpath($inputXpath, $html));
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Customer/_files/attribute_postcode_store_label_address.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCheckPostCodeLabels(): void
|
||||
{
|
||||
$html = $this->executeInStoreContext->execute('default', [$this->block, 'toHtml']);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(
|
||||
sprintf(
|
||||
"//form[contains(@class, 'form-address-edit')]//label[@for='zip']/span[contains(text(), '%s')]",
|
||||
'default store postcode label'
|
||||
),
|
||||
$html
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that submit button is disabled
|
||||
*
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_address.php
|
||||
* @return void
|
||||
*/
|
||||
public function testSubmitButtonIsDisabled(): void
|
||||
{
|
||||
$html = $this->block->toHtml();
|
||||
$buttonXpath = "//form[contains(@class, 'form-address-edit')]//button[@type='submit' and @disabled='disabled']";
|
||||
$this->assertEquals(1, Xpath::getElementsCountForXpath($buttonXpath, $html));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Customer\Block\Address;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Integration tests for the \Magento\Customer\Block\Address\Grid class
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class GridTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\View\LayoutInterface
|
||||
*/
|
||||
private $layout;
|
||||
|
||||
/**
|
||||
* @var \Magento\Customer\Helper\Session\CurrentCustomer
|
||||
*/
|
||||
protected $currentCustomer;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
/** @var \PHPUnit\Framework\MockObject\MockObject $blockMock */
|
||||
$blockMock = $this->getMockBuilder(
|
||||
\Magento\Framework\View\Element\BlockInterface::class
|
||||
)->disableOriginalConstructor()->setMethods(
|
||||
['setTitle', 'toHtml']
|
||||
)->getMock();
|
||||
$blockMock->expects($this->any())->method('setTitle');
|
||||
|
||||
$this->currentCustomer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->get(\Magento\Customer\Helper\Session\CurrentCustomer::class);
|
||||
$this->layout = Bootstrap::getObjectManager()->get(\Magento\Framework\View\LayoutInterface::class);
|
||||
$this->layout->setBlock('head', $blockMock);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var \Magento\Customer\Model\CustomerRegistry $customerRegistry */
|
||||
$customerRegistry = $objectManager->get(\Magento\Customer\Model\CustomerRegistry::class);
|
||||
// Cleanup customer from registry
|
||||
$customerRegistry->remove(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testGetAddressEditUrl()
|
||||
{
|
||||
$gridBlock = $this->createBlockForCustomer(1);
|
||||
|
||||
$this->assertEquals(
|
||||
'http://localhost/index.php/customer/address/edit/id/1/',
|
||||
$gridBlock->getAddressEditUrl(1)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_two_addresses.php
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testGetAdditionalAddresses()
|
||||
{
|
||||
$gridBlock = $this->createBlockForCustomer(1);
|
||||
$this->assertNotNull($gridBlock->getAdditionalAddresses());
|
||||
$this->assertCount(1, $gridBlock->getAdditionalAddresses());
|
||||
$this->assertInstanceOf(
|
||||
\Magento\Customer\Api\Data\AddressInterface::class,
|
||||
$gridBlock->getAdditionalAddresses()[0]
|
||||
);
|
||||
$this->assertEquals(2, $gridBlock->getAdditionalAddresses()[0]->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_no_address.php
|
||||
* @dataProvider getAdditionalAddressesDataProvider
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testGetAdditionalAddressesNegative($customerId, $expected)
|
||||
{
|
||||
$gridBlock = $this->createBlockForCustomer($customerId);
|
||||
$this->currentCustomer->setCustomerId($customerId);
|
||||
$this->assertEquals($expected, $gridBlock->getAdditionalAddresses());
|
||||
}
|
||||
|
||||
public function getAdditionalAddressesDataProvider()
|
||||
{
|
||||
return ['5' => [5, []]];
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_no_address.php
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testGetAddressHtmlWithoutAddress()
|
||||
{
|
||||
$gridBlock = $this->createBlockForCustomer(5);
|
||||
$this->assertEquals('', $gridBlock->getAddressHtml(null));
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testGetCustomer()
|
||||
{
|
||||
$gridBlock = $this->createBlockForCustomer(1);
|
||||
/** @var CustomerRepositoryInterface $customerRepository */
|
||||
$customerRepository = Bootstrap::getObjectManager()->get(
|
||||
\Magento\Customer\Api\CustomerRepositoryInterface::class
|
||||
);
|
||||
$customer = $customerRepository->getById(1);
|
||||
$object = $gridBlock->getCustomer();
|
||||
$this->assertEquals($customer, $object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create address book block for customer
|
||||
*
|
||||
* @param int $customerId
|
||||
* @return \Magento\Framework\View\Element\BlockInterface
|
||||
*/
|
||||
private function createBlockForCustomer($customerId)
|
||||
{
|
||||
$this->currentCustomer->setCustomerId($customerId);
|
||||
return $this->layout->createBlock(
|
||||
\Magento\Customer\Block\Address\Grid::class,
|
||||
'',
|
||||
['currentCustomer' => $this->currentCustomer]
|
||||
);
|
||||
}
|
||||
}
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Customer\Block\Address\Renderer;
|
||||
|
||||
use Magento\Eav\Model\AttributeDataFactory;
|
||||
|
||||
/**
|
||||
* DefaultRenderer
|
||||
*/
|
||||
class DefaultRendererTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Customer\Model\Address\Config
|
||||
*/
|
||||
protected $_addressConfig;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_addressConfig = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Customer\Model\Address\Config::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider renderArrayDataProvider
|
||||
*/
|
||||
public function testRenderArray($addressAttributes, $format, $expected)
|
||||
{
|
||||
/** @var DefaultRenderer $renderer */
|
||||
$renderer = $this->_addressConfig->getFormatByCode($format)->getRenderer();
|
||||
$actual = $renderer->renderArray($addressAttributes);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function renderArrayDataProvider()
|
||||
{
|
||||
$addressAttributes = [
|
||||
'city' => 'CityM',
|
||||
'country_id' => 'US',
|
||||
'firstname' => 'John',
|
||||
'lastname' => 'Smith',
|
||||
'postcode' => '75477',
|
||||
'region' => 'Alabama',
|
||||
'region_id' => '1',
|
||||
'street' => ['Green str, 67'],
|
||||
'telephone' => '3468676',
|
||||
];
|
||||
|
||||
$htmlResult = "John Smith<br />\n\nGreen str, 67<br />\n\n\n\nCityM, Alabama, " .
|
||||
"75477<br />\nUnited States<br />\nT: <a href=\"tel:3468676\">3468676</a>\n\n";
|
||||
return [
|
||||
[$addressAttributes, AttributeDataFactory::OUTPUT_FORMAT_HTML, $htmlResult],
|
||||
[
|
||||
$addressAttributes,
|
||||
AttributeDataFactory::OUTPUT_FORMAT_PDF,
|
||||
"John Smith|\n\nGreen str, 67|\n\n\n\nCityM, Alabama, 75477|\nUnited States|\nT: 3468676|\n|\n|"
|
||||
],
|
||||
[
|
||||
$addressAttributes,
|
||||
AttributeDataFactory::OUTPUT_FORMAT_ONELINE,
|
||||
"John Smith, Green str, 67, CityM, Alabama 75477, United States"
|
||||
],
|
||||
[
|
||||
$addressAttributes,
|
||||
AttributeDataFactory::OUTPUT_FORMAT_TEXT,
|
||||
"John Smith\n\nGreen str, 67\n\n\n\n\nCityM, Alabama, 75477\nUnited States\nT: 3468676\n\n"
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider renderDataProvider
|
||||
*/
|
||||
public function testRender($address, $format, $expected)
|
||||
{
|
||||
/** @var DefaultRenderer $renderer */
|
||||
$renderer = $this->_addressConfig->getFormatByCode($format)->getRenderer();
|
||||
$actual = $renderer->render($address);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function renderDataProvider()
|
||||
{
|
||||
$data = [
|
||||
'city' => 'CityM',
|
||||
'country_id' => 'US',
|
||||
'firstname' => 'John',
|
||||
'lastname' => 'Smith',
|
||||
'postcode' => '75477',
|
||||
'region' => 'Alabama',
|
||||
'region_id' => '1',
|
||||
'street' => ['Green str, 67'],
|
||||
'telephone' => '3468676',
|
||||
];
|
||||
|
||||
$address = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Customer\Model\Address::class
|
||||
)->setData(
|
||||
$data
|
||||
);
|
||||
|
||||
return [
|
||||
[
|
||||
$address,
|
||||
AttributeDataFactory::OUTPUT_FORMAT_HTML,
|
||||
"John Smith<br />\n\nGreen str, 67<br />\n\n\n\nCityM, Alabama, 75477<br />
|
||||
United States<br />\nT: <a href=\"tel:3468676\">3468676</a>\n\n",
|
||||
],
|
||||
[
|
||||
$address,
|
||||
AttributeDataFactory::OUTPUT_FORMAT_PDF,
|
||||
"John Smith|\n\nGreen str, 67|\n\n\n\nCityM, Alabama, 75477|
|
||||
United States|\nT: 3468676|\n|\n|"
|
||||
],
|
||||
[
|
||||
$address,
|
||||
AttributeDataFactory::OUTPUT_FORMAT_ONELINE,
|
||||
"John Smith, Green str, 67, CityM, Alabama 75477, United States"
|
||||
],
|
||||
[
|
||||
$address,
|
||||
AttributeDataFactory::OUTPUT_FORMAT_TEXT,
|
||||
"John Smith\n\nGreen str, 67\n\n\n\n\nCityM, Alabama, 75477
|
||||
United States\nT: 3468676\n\n"
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Customer\Block\Adminhtml\Edit;
|
||||
|
||||
use Magento\Backend\Model\Search\AuthorizationMock;
|
||||
use Magento\Customer\Controller\RegistryConstants;
|
||||
use Magento\Framework\Authorization;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Class checks Create Order button visibility
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
class OrderButtonTest extends TestCase
|
||||
{
|
||||
/** @var ObjectManagerInterface */
|
||||
private $objectManager;
|
||||
|
||||
/** @var OrderButton */
|
||||
private $button;
|
||||
|
||||
/** @var Registry */
|
||||
private $registry;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->objectManager->addSharedInstance(
|
||||
$this->objectManager->get(AuthorizationMock::class),
|
||||
Authorization::class
|
||||
);
|
||||
$this->button = $this->objectManager->get(OrderButton::class);
|
||||
$this->registry = $this->objectManager->get(Registry::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->registry->unregister(RegistryConstants::CURRENT_CUSTOMER_ID);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testGetButtonDataWithoutCustomer(): void
|
||||
{
|
||||
$this->assertEmpty($this->button->getButtonData());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetButtonDataWithCustomer(): void
|
||||
{
|
||||
$this->registry->unregister(RegistryConstants::CURRENT_CUSTOMER_ID);
|
||||
$this->registry->register(RegistryConstants::CURRENT_CUSTOMER_ID, 1);
|
||||
$data = $this->button->getButtonData();
|
||||
$this->assertNotEmpty($data);
|
||||
$this->assertEquals(__('Create Order'), $data['label']);
|
||||
$this->assertStringContainsString('sales/order_create/start/customer_id/1/', $data['on_click']);
|
||||
}
|
||||
}
|
||||
+148
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Customer\Block\Adminhtml\Edit\Tab;
|
||||
|
||||
use Magento\Customer\Api\CustomerRepositoryInterface;
|
||||
use Magento\Customer\Controller\RegistryConstants;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\Framework\View\LayoutInterface;
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\Quote\Model\Quote;
|
||||
use Magento\Quote\Model\Quote\Item;
|
||||
use Magento\Quote\Model\QuoteFactory;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Base class for testing \Magento\Customer\Block\Adminhtml\Edit\Tab\Cart block
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
abstract class AbstractCartTest extends TestCase
|
||||
{
|
||||
const CUSTOMER_ID_VALUE = 1234;
|
||||
|
||||
/** @var Registry */
|
||||
private $registry;
|
||||
|
||||
/** @var Cart */
|
||||
protected $block;
|
||||
|
||||
/** @var ObjectManagerInterface */
|
||||
protected $objectManager;
|
||||
|
||||
/** @var CartRepositoryInterface */
|
||||
protected $quoteRepository;
|
||||
|
||||
/** @var CustomerRepositoryInterface */
|
||||
private $customerRepository;
|
||||
|
||||
/** @var QuoteFactory */
|
||||
private $quoteFactory;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->registry = $this->objectManager->get(Registry::class);
|
||||
$this->registerCustomerId(self::CUSTOMER_ID_VALUE);
|
||||
$this->block = $this->objectManager->get(LayoutInterface::class)->createBlock(Cart::class);
|
||||
$this->quoteRepository = $this->objectManager->get(CartRepositoryInterface::class);
|
||||
$this->customerRepository = $this->objectManager->get(CustomerRepositoryInterface::class);
|
||||
$this->quoteFactory = $this->objectManager->get(QuoteFactory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function tearDown(): void
|
||||
{
|
||||
$this->registry->unregister(RegistryConstants::CURRENT_CUSTOMER_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the expected items of the shopping cart are in the block
|
||||
*
|
||||
* @param string $customerEmail
|
||||
* @return void
|
||||
*/
|
||||
protected function processCheckQuoteItems(string $customerEmail): void
|
||||
{
|
||||
$customer = $this->customerRepository->get($customerEmail);
|
||||
$this->registerCustomerId((int)$customer->getId());
|
||||
$this->block->toHtml();
|
||||
|
||||
$quoteItemIds = $this->getQuoteItemIds((int)$customer->getId());
|
||||
$this->assertCount(
|
||||
count($quoteItemIds),
|
||||
$this->block->getPreparedCollection(),
|
||||
"Item's count in the customer cart grid block doesn't match expected count."
|
||||
);
|
||||
$this->assertEmpty(
|
||||
array_diff(
|
||||
$this->block->getPreparedCollection()->getAllIds(),
|
||||
$quoteItemIds
|
||||
),
|
||||
"Items in the customer cart grid block doesn't match expected items."
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that customer's shopping cart block is empty
|
||||
*
|
||||
* @param string $customerEmail
|
||||
* @return void
|
||||
*/
|
||||
protected function processCheckWithoutQuoteItems(string $customerEmail): void
|
||||
{
|
||||
$customer = $this->customerRepository->get($customerEmail);
|
||||
$this->registerCustomerId((int)$customer->getId());
|
||||
$this->block->toHtml();
|
||||
|
||||
$this->assertCount(
|
||||
0,
|
||||
$this->block->getPreparedCollection(),
|
||||
"Item's count in the customer cart grid block doesn't match expected count."
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add customer id to registry.
|
||||
*
|
||||
* @param int $customerId
|
||||
* @return void
|
||||
*/
|
||||
private function registerCustomerId(int $customerId): void
|
||||
{
|
||||
$this->registry->unregister(RegistryConstants::CURRENT_CUSTOMER_ID);
|
||||
$this->registry->register(RegistryConstants::CURRENT_CUSTOMER_ID, $customerId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get shopping cart quote item identifiers by customer id.
|
||||
*
|
||||
* @param int $customerId
|
||||
* @return array
|
||||
*/
|
||||
private function getQuoteItemIds(int $customerId): array
|
||||
{
|
||||
$ids = [];
|
||||
/** @var Quote $quote */
|
||||
$quote = $this->quoteRepository->getForCustomer($customerId);
|
||||
/** @var Item $item */
|
||||
foreach ($quote->getItems() as $item) {
|
||||
$ids[] = $item->getId();
|
||||
}
|
||||
|
||||
return $ids;
|
||||
}
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Customer\Block\Adminhtml\Edit\Tab\Cart;
|
||||
|
||||
use Magento\Customer\Block\Adminhtml\Edit\Tab\AbstractCartTest;
|
||||
use Magento\Framework\Module\Manager;
|
||||
use Magento\Quote\Model\Quote;
|
||||
use Magento\Quote\Model\ResourceModel\Quote\CollectionFactory;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Class checks customer's shopping cart block with bundle product.
|
||||
*
|
||||
* @see \Magento\Customer\Block\Adminhtml\Edit\Tab\Cart
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class CartBundleTest extends AbstractCartTest
|
||||
{
|
||||
/** @var CollectionFactory */
|
||||
private $quoteCollectionFactory;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->quoteCollectionFactory = $this->objectManager->get(CollectionFactory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Manager $moduleManager */
|
||||
$moduleManager = $objectManager->get(Manager::class);
|
||||
//This check is needed because Customer independent of Magento_Bundle
|
||||
if (!$moduleManager->isEnabled('Magento_Bundle')) {
|
||||
self::markTestSkipped('Magento_Bundle module disabled.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Bundle/_files/quote_with_bundle_and_options.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @return void
|
||||
*/
|
||||
public function testBundleProductView(): void
|
||||
{
|
||||
$quoteCollection = $this->quoteCollectionFactory->create();
|
||||
$quoteCollection->addFieldToFilter('reserved_order_id', 'test_cart_with_bundle_and_options');
|
||||
/** @var Quote $quote */
|
||||
$quote = $quoteCollection->getFirstItem();
|
||||
$this->assertNotEmpty($quote->getId());
|
||||
$quote->setCustomerId(1);
|
||||
$this->quoteRepository->save($quote);
|
||||
$this->processCheckQuoteItems('customer@example.com');
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Customer\Block\Adminhtml\Edit\Tab\Cart;
|
||||
|
||||
use Magento\Customer\Block\Adminhtml\Edit\Tab\AbstractCartTest;
|
||||
use Magento\Framework\Module\Manager;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Class checks customer's shopping cart block with configurable product.
|
||||
*
|
||||
* @see \Magento\Customer\Block\Adminhtml\Edit\Tab\Cart
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class CartConfigurableTest extends AbstractCartTest
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Manager $moduleManager */
|
||||
$moduleManager = $objectManager->get(Manager::class);
|
||||
//This check is needed because Customer independent of Magento_ConfigurableProduct
|
||||
if (!$moduleManager->isEnabled('Magento_ConfigurableProduct')) {
|
||||
self::markTestSkipped('Magento_ConfigurableProduct module disabled.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/ConfigurableProduct/_files/customer_quote_with_items_configurable_product.php
|
||||
* @return void
|
||||
*/
|
||||
public function testConfigurableProductView(): void
|
||||
{
|
||||
$this->processCheckQuoteItems('customer_uk_address@test.com');
|
||||
}
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Customer\Block\Adminhtml\Edit\Tab\Cart;
|
||||
|
||||
use Magento\Customer\Block\Adminhtml\Edit\Tab\Cart;
|
||||
use Magento\Customer\Controller\RegistryConstants;
|
||||
use Magento\Framework\Data\Collection;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\Framework\View\LayoutInterface;
|
||||
use Magento\Quote\Model\QuoteRepository;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Store\ExecuteInStoreContext;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Class checks that shopping cart grid can be filtered
|
||||
*
|
||||
* @see \Magento\Customer\Block\Adminhtml\Edit\Tab\Cart::_prepareCollection()
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
* @magentoDbIsolation disabled
|
||||
*/
|
||||
class CollectionTest extends TestCase
|
||||
{
|
||||
/** @var ObjectManagerInterface */
|
||||
private $objectManager;
|
||||
|
||||
/** @var ExecuteInStoreContext */
|
||||
private $executeInStoreContext;
|
||||
|
||||
/** @var Registry */
|
||||
private $registry;
|
||||
|
||||
/** @var LayoutInterface */
|
||||
private $layout;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->executeInStoreContext = $this->objectManager->get(ExecuteInStoreContext::class);
|
||||
$this->registry = $this->objectManager->get(Registry::class);
|
||||
$this->layout = $this->objectManager->get(LayoutInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->registry->unregister(RegistryConstants::CURRENT_CUSTOMER_ID);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Checkout/_files/quote_with_address_saved.php
|
||||
* @magentoDataFixture Magento/Checkout/_files/customer_quote_on_second_website.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCollectionOnDifferentStores(): void
|
||||
{
|
||||
$this->registry->unregister(RegistryConstants::CURRENT_CUSTOMER_ID);
|
||||
$this->registry->register(RegistryConstants::CURRENT_CUSTOMER_ID, 1);
|
||||
$collectionFirstWebsite = $this->executeInStoreContext->execute(
|
||||
'default',
|
||||
[$this->layout->createBlock(Cart::class), 'getPreparedCollection']
|
||||
);
|
||||
$this->assertCollection($collectionFirstWebsite, 'Simple Product');
|
||||
$this->objectManager->removeSharedInstance(QuoteRepository::class);
|
||||
$collectionSecondWebsite = $this->executeInStoreContext->execute(
|
||||
'fixture_second_store',
|
||||
[$this->layout->createBlock(Cart::class), 'getPreparedCollection']
|
||||
);
|
||||
$this->assertCollection($collectionSecondWebsite, 'Simple Product on second website');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check is collection match expected value
|
||||
*
|
||||
* @param Collection $collection
|
||||
* @param string $itemName
|
||||
* @return void
|
||||
*/
|
||||
private function assertCollection(Collection $collection, string $itemName): void
|
||||
{
|
||||
$this->assertCount(1, $collection, 'Collection size does not match expected value');
|
||||
$this->assertEquals($itemName, $collection->getFirstItem()->getName());
|
||||
}
|
||||
}
|
||||
+146
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Customer\Block\Adminhtml\Edit\Tab\Cart;
|
||||
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\View\Result\Page;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Helper\Xpath;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Class checks store switcher appearance in the customer shopping cart block.
|
||||
*
|
||||
* @see \Magento\Customer\Block\Adminhtml\Edit\Tab\Cart
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
class StoreSwitcherTest extends TestCase
|
||||
{
|
||||
private const WEBSITE_FILTER_XPATH = "//select[@name='website_id' and @id='website_filter']";
|
||||
|
||||
private const WEBSITE_FILTER_OPTION_XPATH = "//select[@name='website_id' and @id='website_filter']/option";
|
||||
|
||||
/** @var ObjectManagerInterface */
|
||||
private $objectManager;
|
||||
|
||||
/** @var PageFactory */
|
||||
private $pageFactory;
|
||||
|
||||
/** @var StoreManagerInterface */
|
||||
private $storeManager;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->pageFactory = $this->objectManager->get(PageFactory::class);
|
||||
$this->storeManager = $this->objectManager->get(StoreManagerInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testStoreSwitcherDisplayed(): void
|
||||
{
|
||||
$html = $this->getBlockHtml('admin.customer.view.edit.cart');
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(self::WEBSITE_FILTER_XPATH, $html),
|
||||
'Website Filter was not found on the page'
|
||||
);
|
||||
$this->checkFilterOptions($html, [$this->storeManager->getWebsite('base')->getName()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoConfigFixture current_store general/single_store_mode/enabled 1
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testStoreSwitcherIsNotDisplayed(): void
|
||||
{
|
||||
$html = $this->getBlockHtml('admin.customer.view.edit.cart');
|
||||
$this->assertEmpty(Xpath::getElementsCountForXpath(self::WEBSITE_FILTER_XPATH, $html));
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Store/_files/second_website_with_two_stores.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testStoreSwitcherMultiWebsite(): void
|
||||
{
|
||||
$expectedWebsites = [
|
||||
$this->storeManager->getWebsite('base')->getName(),
|
||||
$this->storeManager->getWebsite('test')->getName(),
|
||||
];
|
||||
$html = $this->getBlockHtml('admin.customer.view.edit.cart');
|
||||
$this->assertEquals(1, Xpath::getElementsCountForXpath(self::WEBSITE_FILTER_XPATH, $html));
|
||||
$this->checkFilterOptions($html, $expectedWebsites);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check store switcher appearance
|
||||
*
|
||||
* @param string $html
|
||||
* @param array $expectedOptions
|
||||
* @return void
|
||||
*/
|
||||
private function checkFilterOptions(string $html, array $expectedOptions): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
count($expectedOptions),
|
||||
Xpath::getElementsCountForXpath(self::WEBSITE_FILTER_OPTION_XPATH, $html),
|
||||
'Website filter options count does not match expected value'
|
||||
);
|
||||
$optionPath = self::WEBSITE_FILTER_OPTION_XPATH . "[contains(text(), '%s')]";
|
||||
foreach ($expectedOptions as $option) {
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(sprintf($optionPath, $option), $html),
|
||||
sprintf('Option for %s website was not found in filter options list', $option)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get block html
|
||||
*
|
||||
* @param string $alias
|
||||
* @return string
|
||||
*/
|
||||
private function getBlockHtml(string $alias): string
|
||||
{
|
||||
$page = $this->preparePage();
|
||||
$block = $page->getLayout()->getBlock($alias);
|
||||
$this->assertNotFalse($block);
|
||||
|
||||
return $block->toHtml();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare page layout
|
||||
*
|
||||
* @return Page
|
||||
*/
|
||||
private function preparePage(): Page
|
||||
{
|
||||
$page = $this->pageFactory->create();
|
||||
$page->addHandle(['default', 'customer_index_cart']);
|
||||
$page->getLayout()->generateXml();
|
||||
|
||||
return $page;
|
||||
}
|
||||
}
|
||||
+163
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Customer\Block\Adminhtml\Edit\Tab;
|
||||
|
||||
use Magento\Backend\Model\Session\Quote as SessionQuote;
|
||||
use Magento\Quote\Model\Quote;
|
||||
|
||||
/**
|
||||
* Class checks customer's shopping cart block with simple product and simple product with options.
|
||||
*
|
||||
* @see \Magento\Customer\Block\Adminhtml\Edit\Tab\Cart
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class CartTest extends AbstractCartTest
|
||||
{
|
||||
/**
|
||||
* @magentoDataFixture Magento/Checkout/_files/customer_quote_with_items_simple_product_options.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testProductOptionsView(): void
|
||||
{
|
||||
$this->processCheckQuoteItems('customer_uk_address@test.com');
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Checkout/_files/quote_with_address_saved.php
|
||||
* @magentoDataFixture Magento/Customer/_files/two_customers.php
|
||||
* @return void
|
||||
*/
|
||||
public function testCustomerWithoutQuoteView(): void
|
||||
{
|
||||
$this->processCheckWithoutQuoteItems('customer_two@example.com');
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify Grid with quote items
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/quote_with_two_products_and_customer.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @dataProvider getQuoteDataProvider
|
||||
*
|
||||
* @param int $customerId
|
||||
* @param bool $guest
|
||||
* @param bool $contains
|
||||
* @return void
|
||||
*/
|
||||
public function testVerifyCollectionWithQuote(int $customerId, bool $guest, bool $contains): void
|
||||
{
|
||||
$session = $this->objectManager->create(SessionQuote::class);
|
||||
$session->setCustomerId($customerId);
|
||||
$quoteFixture = $this->objectManager->create(Quote::class);
|
||||
$quoteFixture->load('test01', 'reserved_order_id');
|
||||
$quoteFixture->setCustomerIsGuest($guest)
|
||||
->setCustomerId($customerId)
|
||||
->save();
|
||||
$this->block->toHtml();
|
||||
if ($contains) {
|
||||
$this->assertStringContainsString(
|
||||
"We couldn't find any records",
|
||||
$this->block->getGridParentHtml()
|
||||
);
|
||||
} else {
|
||||
$this->assertStringNotContainsString(
|
||||
"We couldn't find any records",
|
||||
$this->block->getGridParentHtml()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for withQuoteTest
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getQuoteDataProvider(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
6,
|
||||
false,
|
||||
true
|
||||
],
|
||||
[
|
||||
self::CUSTOMER_ID_VALUE,
|
||||
true,
|
||||
false
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify Customer id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetCustomerId(): void
|
||||
{
|
||||
$this->assertEquals(self::CUSTOMER_ID_VALUE, $this->block->getCustomerId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify get grid url
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetGridUrl(): void
|
||||
{
|
||||
$this->assertStringContainsString('/backend/customer/index/cart', $this->block->getGridUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify grid parent html
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetGridParentHtml(): void
|
||||
{
|
||||
$mockCollection = $this->getMockBuilder(\Magento\Framework\Data\Collection::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->block->setCollection($mockCollection);
|
||||
$this->assertStringContainsString(
|
||||
"<div class=\"admin__data-grid-header admin__data-grid-toolbar\"",
|
||||
$this->block->getGridParentHtml()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify row url
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetRowUrl(): void
|
||||
{
|
||||
$row = new \Magento\Framework\DataObject();
|
||||
$row->setProductId(1);
|
||||
$this->assertStringContainsString('/backend/catalog/product/edit/id/1', $this->block->getRowUrl($row));
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify get html
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetHtml(): void
|
||||
{
|
||||
$html = $this->block->toHtml();
|
||||
$this->assertStringContainsString("<div id=\"customer_cart_grid\"", $html);
|
||||
$this->assertStringContainsString("<div class=\"admin__data-grid-header admin__data-grid-toolbar\"", $html);
|
||||
$this->assertStringContainsString("customer_cart_gridJsObject = new varienGrid(\"customer_cart_grid\",", $html);
|
||||
$this->assertStringContainsString(
|
||||
'backend\u002Fcustomer\u002Fcart_product_composite_cart\u002Fconfigure\u002Fcustomer_id\u002F'
|
||||
. self::CUSTOMER_ID_VALUE,
|
||||
$html
|
||||
);
|
||||
}
|
||||
}
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Customer\Block\Adminhtml\Edit\Tab;
|
||||
|
||||
/**
|
||||
* Magento\Customer\Block\Adminhtml\Edit\Tab\Carts
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class CartsTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/** @var Carts */
|
||||
private $_block;
|
||||
|
||||
/** @var \Magento\Customer\Api\CustomerRepositoryInterface */
|
||||
private $_customerRepository;
|
||||
|
||||
/** @var \Magento\Backend\Block\Template\Context */
|
||||
private $_context;
|
||||
|
||||
/** @var \Magento\Framework\ObjectManagerInterface */
|
||||
private $_objectManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->_customerRepository = $this->_objectManager->get(
|
||||
\Magento\Customer\Api\CustomerRepositoryInterface::class
|
||||
);
|
||||
$storeManager = $this->_objectManager->get(\Magento\Store\Model\StoreManager::class);
|
||||
$this->_context = $this->_objectManager->create(
|
||||
\Magento\Backend\Block\Template\Context::class,
|
||||
['storeManager' => $storeManager]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
*/
|
||||
public function testGetHtml()
|
||||
{
|
||||
$customer = $this->_customerRepository->getById(1);
|
||||
$data = ['account' => $customer->__toArray()];
|
||||
$this->_context->getBackendSession()->setCustomerData($data);
|
||||
|
||||
$this->_block = $this->_objectManager->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
)->createBlock(
|
||||
\Magento\Customer\Block\Adminhtml\Edit\Tab\Carts::class,
|
||||
'',
|
||||
['context' => $this->_context]
|
||||
);
|
||||
|
||||
$html = $this->_block->toHtml();
|
||||
$this->assertStringContainsString("<div id=\"customer_cart_grid\"", $html);
|
||||
$this->assertMatchesRegularExpression(
|
||||
'/<div class=".*admin__data-grid-toolbar"/',
|
||||
$html
|
||||
);
|
||||
$this->assertStringContainsString("customer_cart_gridJsObject = new varienGrid(\"customer_cart_grid\",", $html);
|
||||
$this->assertStringContainsString(
|
||||
'backend\u002Fcustomer\u002Fcart_product_composite_cart\u002Fconfigure\u002Fwebsite_id\u002F1',
|
||||
$html
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetHtmlNoCustomer()
|
||||
{
|
||||
$data = ['account' => []];
|
||||
$this->_context->getBackendSession()->setCustomerData($data);
|
||||
|
||||
$this->_block = $this->_objectManager->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
)->createBlock(
|
||||
\Magento\Customer\Block\Adminhtml\Edit\Tab\Carts::class,
|
||||
'',
|
||||
['context' => $this->_context]
|
||||
);
|
||||
|
||||
$html = $this->_block->toHtml();
|
||||
$this->assertStringContainsString("<div id=\"customer_cart_grid\"", $html);
|
||||
$this->assertMatchesRegularExpression(
|
||||
'/<div class=".*admin__data-grid-toolbar"/',
|
||||
$html
|
||||
);
|
||||
$this->assertStringContainsString("customer_cart_gridJsObject = new varienGrid(\"customer_cart_grid\",", $html);
|
||||
$this->assertStringContainsString(
|
||||
'backend\u002Fcustomer\u002Fcart_product_composite_cart\u002Fupdate\u002Fkey',
|
||||
$html
|
||||
);
|
||||
}
|
||||
}
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Customer\Block\Adminhtml\Edit\Tab;
|
||||
|
||||
use Magento\Customer\Controller\RegistryConstants;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Test Customer account form block functionality
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class NewsletterTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
/**
|
||||
* @var Newsletter
|
||||
*/
|
||||
private $block;
|
||||
|
||||
/**
|
||||
* Core registry
|
||||
*
|
||||
* @var \Magento\Framework\Registry
|
||||
*/
|
||||
private $coreRegistry;
|
||||
|
||||
/**
|
||||
* Execute per test initialization.
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$objectManager->get(\Magento\Framework\App\State::class)->setAreaCode('adminhtml');
|
||||
|
||||
$this->coreRegistry = $objectManager->get(\Magento\Framework\Registry::class);
|
||||
$this->block = $objectManager->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
)->createBlock(
|
||||
\Magento\Customer\Block\Adminhtml\Edit\Tab\Newsletter::class,
|
||||
'',
|
||||
['registry' => $this->coreRegistry]
|
||||
)->setTemplate(
|
||||
'tab/newsletter.phtml'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute post test cleanup
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->coreRegistry->unregister(RegistryConstants::CURRENT_CUSTOMER_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_sample.php
|
||||
*/
|
||||
public function testRenderingNewsletterBlock()
|
||||
{
|
||||
$websiteId = 1;
|
||||
$this->getRequest()->setParam('id', 1);
|
||||
$this->dispatch('backend/customer/index/edit');
|
||||
$body = $this->getResponse()->getBody();
|
||||
|
||||
$this->assertStringContainsString('\u003Cspan\u003ENewsletter Information\u003C\/span\u003E', $body);
|
||||
$this->assertStringContainsString(
|
||||
'\u003Cinput id=\"_newslettersubscription_status_' . $websiteId . '\"',
|
||||
$body
|
||||
);
|
||||
$this->assertStringNotContainsString('checked="checked"', $body);
|
||||
$this->assertStringContainsString('\u003Cspan\u003ESubscribed to Newsletter\u003C\/span\u003E', $body);
|
||||
$this->assertStringContainsString('\u003ENo Newsletter Found\u003C', $body);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_sample.php
|
||||
* @magentoDataFixture Magento/Newsletter/_files/newsletter_sample.php
|
||||
* @magentoDataFixture Magento/Newsletter/_files/queue.php
|
||||
*/
|
||||
public function testRenderingNewsletterBlockWithQueue()
|
||||
{
|
||||
$this->getRequest()->setParam('id', 1);
|
||||
$this->dispatch('backend/customer/index/edit');
|
||||
$body = $this->getResponse()->getBody();
|
||||
|
||||
$this->assertMatchesRegularExpression(
|
||||
'~.+\/newsletter\\\/template\\\/preview\\\/id\\\/\d+\\\/subscriber\\\/\d+\\\/.+~',
|
||||
$body
|
||||
);
|
||||
}
|
||||
}
|
||||
+433
@@ -0,0 +1,433 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Customer\Block\Adminhtml\Edit\Tab\Orders;
|
||||
|
||||
use Magento\Customer\Block\Adminhtml\Edit\Tab\Orders;
|
||||
use Magento\Customer\Controller\RegistryConstants;
|
||||
use Magento\Directory\Model\Currency;
|
||||
use Magento\Framework\App\Config\ScopeConfigInterface;
|
||||
use Magento\Framework\Locale\CurrencyInterface;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
|
||||
use Magento\Framework\View\Element\UiComponent\DataProvider\Document;
|
||||
use Magento\Framework\View\LayoutInterface;
|
||||
use Magento\Sales\Api\Data\OrderInterface;
|
||||
use Magento\Store\Model\System\Store;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Helper\Xpath;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test cases related to check that orders tab with customer orders
|
||||
* grid correctly renders and contains all necessary data.
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
* @magentoAppArea adminhtml
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
class RenderOrdersTabTest extends TestCase
|
||||
{
|
||||
private const PATHS_TO_TABLE_BODY = [
|
||||
"//div[contains(@data-grid-id, 'customer_orders_grid')]",
|
||||
"//table[contains(@class, 'data-grid')]",
|
||||
"//tbody",
|
||||
];
|
||||
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var Store
|
||||
*/
|
||||
private $store;
|
||||
|
||||
/**
|
||||
* @var LayoutInterface
|
||||
*/
|
||||
private $layout;
|
||||
|
||||
/**
|
||||
* @var CurrencyInterface
|
||||
*/
|
||||
private $currency;
|
||||
|
||||
/**
|
||||
* @var TimezoneInterface
|
||||
*/
|
||||
private $timezone;
|
||||
|
||||
/**
|
||||
* @var Registry
|
||||
*/
|
||||
private $registry;
|
||||
|
||||
/**
|
||||
* @var ScopeConfigInterface
|
||||
*/
|
||||
private $scopeConfig;
|
||||
|
||||
/**
|
||||
* @var Orders
|
||||
*/
|
||||
private $ordersGridBlock;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->store = $this->objectManager->get(Store::class);
|
||||
$this->layout = $this->objectManager->get(LayoutInterface::class);
|
||||
$this->currency = $this->objectManager->get(CurrencyInterface::class);
|
||||
$this->timezone = $this->objectManager->get(TimezoneInterface::class);
|
||||
$this->registry = $this->objectManager->get(Registry::class);
|
||||
$this->scopeConfig = $this->objectManager->get(ScopeConfigInterface::class);
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->registry->unregister(RegistryConstants::CURRENT_CUSTOMER_ID);
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that customer orders tab renders with message "We couldn't find any records."
|
||||
* when customer doesn't have any orders.
|
||||
*
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testRenderBlockWithoutOrders(): void
|
||||
{
|
||||
$this->processCheckOrdersGridByCustomerId(1, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that customer orders tab renders without message "We couldn't find any records."
|
||||
* and contains rendered order item when customer has one order.
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/order_with_customer.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testRenderBlockWithOneOrder(): void
|
||||
{
|
||||
$this->processCheckOrdersGridByCustomerId(1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that customer orders tab renders without message "We couldn't find any records."
|
||||
* and contains rendered orders items when customer has few orders.
|
||||
*
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Sales/_files/orders_with_customer.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testRenderBlockWithFewOrders(): void
|
||||
{
|
||||
$this->processCheckOrdersGridByCustomerId(1, 5);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render orders grid and assert that all data rendered as expected.
|
||||
*
|
||||
* @param int $customerId
|
||||
* @param int $expectedOrderCount
|
||||
* @return void
|
||||
*/
|
||||
private function processCheckOrdersGridByCustomerId(int $customerId, int $expectedOrderCount): void
|
||||
{
|
||||
$this->registerCustomerId($customerId);
|
||||
$ordersGridHtml = $this->getOrdersGridHtml();
|
||||
$orderItemsData = $this->getOrderGridItemsData();
|
||||
$this->assertOrdersCount($expectedOrderCount, $ordersGridHtml);
|
||||
$this->assertIsEmptyGridMessageArrears($ordersGridHtml, $expectedOrderCount === 0);
|
||||
$this->checkOrderItemsFields($orderItemsData, $ordersGridHtml);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add customer id to registry.
|
||||
*
|
||||
* @param int $customerId
|
||||
* @return void
|
||||
*/
|
||||
private function registerCustomerId(int $customerId): void
|
||||
{
|
||||
$this->registry->unregister(RegistryConstants::CURRENT_CUSTOMER_ID);
|
||||
$this->registry->register(RegistryConstants::CURRENT_CUSTOMER_ID, $customerId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render customer orders tab.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getOrdersGridHtml(): string
|
||||
{
|
||||
$this->ordersGridBlock = $this->layout->createBlock(Orders::class);
|
||||
|
||||
return $this->ordersGridBlock->toHtml();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that rendered html contains all provided order items.
|
||||
*
|
||||
* @param array $orderItemsData
|
||||
* @param string $html
|
||||
* @return void
|
||||
*/
|
||||
private function checkOrderItemsFields(array $orderItemsData, string $html): void
|
||||
{
|
||||
foreach ($orderItemsData as $itemOrder => $orderItemData) {
|
||||
$this->assertViewOrderUrl($itemOrder, $orderItemData['order_id'], $html);
|
||||
$this->assertReorderUrl($itemOrder, $orderItemData['order_id'], $html);
|
||||
$this->assertStoreViewLabels($itemOrder, $orderItemData['store_view_labels'], $html);
|
||||
unset($orderItemData['order_id'], $orderItemData['store_view_labels']);
|
||||
$this->assertColumnsValues($itemOrder, $orderItemData, $html);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that field store_id contains all provided store codes.
|
||||
*
|
||||
* @param int $itemOrder
|
||||
* @param array $storeViewLabels
|
||||
* @param string $html
|
||||
* @return void
|
||||
*/
|
||||
private function assertStoreViewLabels(int $itemOrder, array $storeViewLabels, string $html): void
|
||||
{
|
||||
if (empty($storeViewLabels)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$elementPaths = array_merge(self::PATHS_TO_TABLE_BODY, [
|
||||
"//tr[{$itemOrder}]",
|
||||
"//td[contains(@class, 'store_id') and %s]",
|
||||
]);
|
||||
$storeLabelsPaths = [];
|
||||
foreach ($storeViewLabels as $labelIndex => $storeViewLabel) {
|
||||
$storeLabelsPaths[] = "contains(text()[{$labelIndex}], '{$storeViewLabel}')";
|
||||
}
|
||||
$checkStoreViewsXPath = sprintf(implode('', $elementPaths), implode(' and ', $storeLabelsPaths));
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath($checkStoreViewsXPath, $html),
|
||||
sprintf("Some store view label not found. Labels: %s. Html: %s", implode(', ', $storeViewLabels), $html)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that columns values as expected.
|
||||
*
|
||||
* @param int $itemOrder
|
||||
* @param array $columnsData
|
||||
* @param string $html
|
||||
* @return void
|
||||
*/
|
||||
private function assertColumnsValues(int $itemOrder, array $columnsData, string $html): void
|
||||
{
|
||||
$elementPaths = array_merge(self::PATHS_TO_TABLE_BODY, [
|
||||
"//tr[{$itemOrder}]",
|
||||
"//td[contains(@class, '%s') and contains(text(), '%s')]",
|
||||
]);
|
||||
$elementXPathTemplate = implode('', $elementPaths);
|
||||
foreach ($columnsData as $columnName => $columnValue) {
|
||||
$preparedXPath = sprintf($elementXPathTemplate, $columnName, $columnValue);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath($preparedXPath, $html),
|
||||
sprintf("Column %s doesn't have value %s. Html: %s", $columnName, $columnValue, $html)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that rendered html contains URL to reorder by order id.
|
||||
*
|
||||
* @param int $itemOrder
|
||||
* @param int $orderId
|
||||
* @param string $html
|
||||
* @return void
|
||||
*/
|
||||
private function assertReorderUrl(int $itemOrder, int $orderId, string $html): void
|
||||
{
|
||||
$urlLabel = (string)__('Reorder');
|
||||
$elementPaths = array_merge(self::PATHS_TO_TABLE_BODY, [
|
||||
"//tr[{$itemOrder}]",
|
||||
"//td[contains(@class, 'action')]",
|
||||
"//a[contains(@href, 'sales/order_create/reorder/order_id/$orderId') and contains(text(), '{$urlLabel}')]",
|
||||
]);
|
||||
$reorderUrlXPath = implode('', $elementPaths);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath($reorderUrlXPath, $html),
|
||||
sprintf('Reorder URL is not as expected. Html: %s', $html)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that rendered html contains URL to order view by order id.
|
||||
*
|
||||
* @param int $itemOrder
|
||||
* @param int $orderId
|
||||
* @param string $html
|
||||
* @return void
|
||||
*/
|
||||
private function assertViewOrderUrl(int $itemOrder, int $orderId, string $html): void
|
||||
{
|
||||
$elementPaths = array_merge(self::PATHS_TO_TABLE_BODY, [
|
||||
"//tr[{$itemOrder}][contains(@title, 'sales/order/view/order_id/{$orderId}')]",
|
||||
]);
|
||||
$viewOrderUrlXPath = implode('', $elementPaths);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath($viewOrderUrlXPath, $html),
|
||||
sprintf('URL to view order is not as expected. Html: %s', $html)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that provided orders count and count in html are equals.
|
||||
*
|
||||
* @param int $expectedOrdersCount
|
||||
* @param string $html
|
||||
* @return void
|
||||
*/
|
||||
private function assertOrdersCount(int $expectedOrdersCount, string $html): void
|
||||
{
|
||||
$elementPaths = [
|
||||
"//div[contains(@data-grid-id, 'customer_orders_grid')]",
|
||||
"//div[contains(@class, 'grid-header-row')]",
|
||||
"//div[contains(@class, 'control-support-text')]",
|
||||
sprintf("//span[contains(@id, 'grid-total-count') and contains(text(), '%s')]", $expectedOrdersCount),
|
||||
];
|
||||
$ordersCountXPath = implode('', $elementPaths);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath($ordersCountXPath, $html),
|
||||
sprintf('Provided count and count in html are not equals. Html: %s', $html)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that grid contains or not contains message "We couldn't find any records.".
|
||||
*
|
||||
* @param string $html
|
||||
* @param bool $isMessageAppears
|
||||
* @return void
|
||||
*/
|
||||
private function assertIsEmptyGridMessageArrears(string $html, bool $isMessageAppears = false): void
|
||||
{
|
||||
$gridText = (string)__("We couldn't find any records.");
|
||||
$elementPaths = array_merge(self::PATHS_TO_TABLE_BODY, [
|
||||
"//tr[contains(@class, 'tr-no-data')]",
|
||||
"//td[contains(@class, 'empty-text') and contains(text(), \"{$gridText}\")]",
|
||||
]);
|
||||
$emptyTextXPath = implode('', $elementPaths);
|
||||
$this->assertEquals(
|
||||
$isMessageAppears ? 1 : 0,
|
||||
Xpath::getElementsCountForXpath($emptyTextXPath, $html),
|
||||
sprintf('Message "We couldn\'t find any records." not found in html. Html: %s', $html)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build array with rendered orders for check that all contained data appears.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getOrderGridItemsData(): array
|
||||
{
|
||||
$orders = [];
|
||||
$orderNumber = 1;
|
||||
/** @var Document $order */
|
||||
foreach ($this->ordersGridBlock->getCollection() as $order) {
|
||||
$orderGrandTotal = $this->prepareGrandTotal(
|
||||
$order->getData('grand_total'),
|
||||
$order->getData('order_currency_code')
|
||||
);
|
||||
$orders[$orderNumber] = [
|
||||
'order_id' => (int)$order->getData(OrderInterface::ENTITY_ID),
|
||||
'increment_id' => $order->getData(OrderInterface::INCREMENT_ID),
|
||||
'created_at' => $this->prepareCreatedAtDate($order->getData(OrderInterface::CREATED_AT)),
|
||||
'billing_name' => $order->getData('billing_name'),
|
||||
'shipping_name' => $order->getData('shipping_name'),
|
||||
'grand_total' => $orderGrandTotal,
|
||||
'store_view_labels' => $this->prepareStoreViewLabels([$order->getData(OrderInterface::STORE_ID)]),
|
||||
];
|
||||
$orderNumber++;
|
||||
}
|
||||
|
||||
return $orders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize created at date.
|
||||
*
|
||||
* @param string $createdAt
|
||||
* @return string
|
||||
*/
|
||||
private function prepareCreatedAtDate(string $createdAt): string
|
||||
{
|
||||
$date = new \DateTime($createdAt);
|
||||
|
||||
return $this->timezone->formatDateTime($date, \IntlDateFormatter::MEDIUM, \IntlDateFormatter::MEDIUM);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize grand total.
|
||||
*
|
||||
* @param string $grandTotal
|
||||
* @param string|null $orderCurrencyCode
|
||||
* @return string
|
||||
*/
|
||||
private function prepareGrandTotal(string $grandTotal, ?string $orderCurrencyCode = null): string
|
||||
{
|
||||
$resultGrandTotal = sprintf("%f", (float)$grandTotal * 1.0);
|
||||
$orderCurrencyCode = $orderCurrencyCode ?:
|
||||
$this->scopeConfig->getValue(Currency::XML_PATH_CURRENCY_BASE, 'default');
|
||||
|
||||
return $this->currency->getCurrency($orderCurrencyCode)->toCurrency($resultGrandTotal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize store ids.
|
||||
*
|
||||
* @param array $orderStoreIds
|
||||
* @return array
|
||||
*/
|
||||
private function prepareStoreViewLabels(array $orderStoreIds): array
|
||||
{
|
||||
$result = [];
|
||||
$storeStructure = $this->store->getStoresStructure(false, $orderStoreIds);
|
||||
$textIndex = 0;
|
||||
foreach ($storeStructure as $website) {
|
||||
$textIndex++;
|
||||
foreach ($website['children'] as $group) {
|
||||
$textIndex++;
|
||||
foreach ($group['children'] as $store) {
|
||||
$textIndex++;
|
||||
$result[$textIndex] = $store['label'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Customer\Block\Adminhtml\Edit\Tab;
|
||||
|
||||
use Magento\Customer\Controller\RegistryConstants;
|
||||
use Magento\Framework\Escaper;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Test for \Magento\Customer\Block\Adminhtml\Edit\Tab\Orders
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class OrdersTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* The orders block under test.
|
||||
*
|
||||
* @var Orders
|
||||
*/
|
||||
private $block;
|
||||
|
||||
/**
|
||||
* Core registry.
|
||||
*
|
||||
* @var \Magento\Framework\Registry
|
||||
*/
|
||||
private $coreRegistry;
|
||||
|
||||
/**
|
||||
* @var Escaper
|
||||
*/
|
||||
private $escaper;
|
||||
|
||||
/**
|
||||
* Execute per test initialization.
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$objectManager->get(\Magento\Framework\App\State::class)->setAreaCode('adminhtml');
|
||||
|
||||
$this->coreRegistry = $objectManager->get(\Magento\Framework\Registry::class);
|
||||
$this->coreRegistry->register(RegistryConstants::CURRENT_CUSTOMER_ID, 1);
|
||||
|
||||
$this->block = $objectManager->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
)->createBlock(
|
||||
\Magento\Customer\Block\Adminhtml\Edit\Tab\Orders::class,
|
||||
'',
|
||||
['coreRegistry' => $this->coreRegistry]
|
||||
);
|
||||
$this->block->getPreparedCollection();
|
||||
$this->escaper = $objectManager->get(Escaper::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute post test cleanup.
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->coreRegistry->unregister(RegistryConstants::CURRENT_CUSTOMER_ID);
|
||||
$this->block->setCollection(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that a valid Url is returned for a given sales order row.
|
||||
*/
|
||||
public function testGetRowUrl()
|
||||
{
|
||||
$row = new \Magento\Framework\DataObject(['id' => 1]);
|
||||
$this->assertStringContainsString('sales/order/view/order_id/1', $this->block->getRowUrl($row));
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that a valid grid Url is returned.
|
||||
*/
|
||||
public function testGetGridUrl()
|
||||
{
|
||||
$this->assertStringContainsString('customer/index/orders', $this->block->getGridUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that the sales order grid Html is valid and contains no records.
|
||||
*/
|
||||
public function testToHtml()
|
||||
{
|
||||
$this->assertStringContainsString(
|
||||
$this->escaper->escapeHtml("We couldn't find any records."),
|
||||
$this->block->toHtml()
|
||||
);
|
||||
}
|
||||
}
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Customer\Block\Adminhtml\Edit\Tab\View;
|
||||
|
||||
use Magento\Customer\Controller\RegistryConstants;
|
||||
use Magento\Framework\Escaper;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Test for \Magento\Customer\Block\Adminhtml\Edit\Tab\View\Cart
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class CartTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* Shopping cart.
|
||||
*
|
||||
* @var Cart
|
||||
*/
|
||||
private $block;
|
||||
|
||||
/**
|
||||
* Core registry.
|
||||
*
|
||||
* @var \Magento\Framework\Registry
|
||||
*/
|
||||
private $coreRegistry;
|
||||
|
||||
/**
|
||||
* @var Escaper
|
||||
*/
|
||||
private $escaper;
|
||||
|
||||
/**
|
||||
* Execute per test initialization.
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$objectManager->get(\Magento\Framework\App\State::class)->setAreaCode('adminhtml');
|
||||
|
||||
$this->coreRegistry = $objectManager->get(\Magento\Framework\Registry::class);
|
||||
$this->coreRegistry->register(RegistryConstants::CURRENT_CUSTOMER_ID, 1);
|
||||
|
||||
$this->block = $objectManager->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
)->createBlock(
|
||||
\Magento\Customer\Block\Adminhtml\Edit\Tab\View\Cart::class,
|
||||
'',
|
||||
['coreRegistry' => $this->coreRegistry, 'data' => ['website_id' => 1]]
|
||||
);
|
||||
$this->block->getPreparedCollection();
|
||||
$this->escaper = $objectManager->get(Escaper::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute per test cleanup.
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->coreRegistry->unregister(RegistryConstants::CURRENT_CUSTOMER_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that the Url for a product row in the cart grid is correct.
|
||||
*/
|
||||
public function testGetRowUrl()
|
||||
{
|
||||
$row = new \Magento\Framework\DataObject(['product_id' => 1]);
|
||||
$this->assertStringContainsString('catalog/product/edit/id/1', $this->block->getRowUrl($row));
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that the headers in the cart grid are visible.
|
||||
*/
|
||||
public function testGetHeadersVisibility()
|
||||
{
|
||||
$this->assertTrue($this->block->getHeadersVisibility());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify the basic content of an empty cart.
|
||||
*
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
*/
|
||||
public function testToHtmlEmptyCart()
|
||||
{
|
||||
$this->assertEquals(0, $this->block->getCollection()->getSize());
|
||||
$this->assertStringContainsString(
|
||||
$this->escaper->escapeHtml('There are no items in customer\'s shopping cart.'),
|
||||
$this->block->toHtml()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify the Html content for a single item in the customer's cart.
|
||||
*
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Customer/_files/quote.php
|
||||
*/
|
||||
public function testToHtmlCartItem()
|
||||
{
|
||||
$html = $this->block->toHtml();
|
||||
$this->assertStringContainsString('Simple Product', $html);
|
||||
$this->assertStringContainsString('simple', $html);
|
||||
$this->assertStringContainsString('$10.00', $html);
|
||||
$this->assertStringContainsString($this->escaper->escapeHtmlAttr('catalog/product/edit/id/1'), $html);
|
||||
}
|
||||
}
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Customer\Block\Adminhtml\Edit\Tab\View\Grid\Renderer;
|
||||
|
||||
use Magento\Catalog\Api\Data\ProductCustomOptionInterface;
|
||||
use Magento\Catalog\Helper\Product\Configuration;
|
||||
use Magento\Customer\Block\Adminhtml\Edit\Tab\View\Grid\Renderer\Item as RendererItem;
|
||||
use Magento\Framework\View\LayoutInterface;
|
||||
use Magento\Quote\Model\Quote\Item;
|
||||
use Magento\Quote\Model\ResourceModel\Quote\Item\CollectionFactory;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Helper\Xpath;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Base class for testing \Magento\Customer\Block\Adminhtml\Edit\Tab\View\Grid\Renderer\Item block
|
||||
*/
|
||||
abstract class AbstractItemTest extends TestCase
|
||||
{
|
||||
/** @var ObjectManager */
|
||||
protected $objectManager;
|
||||
|
||||
/** @var RendererItem */
|
||||
private $blockRendererItem;
|
||||
|
||||
/** @var CollectionFactory */
|
||||
private $quoteItemCollectionFactory;
|
||||
|
||||
/** @var Configuration */
|
||||
private $productConfiguration;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->blockRendererItem = $this->objectManager->get(LayoutInterface::class)->createBlock(RendererItem::class);
|
||||
$this->quoteItemCollectionFactory = $this->objectManager->get(CollectionFactory::class);
|
||||
$this->productConfiguration = $this->objectManager->get(Configuration::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check item block rendering
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function processRender(): void
|
||||
{
|
||||
$itemsCollection = $this->quoteItemCollectionFactory->create();
|
||||
/** @var Item $quoteItem */
|
||||
$quoteItem = $itemsCollection->getFirstItem();
|
||||
$this->assertNotEmpty($quoteItem->getId());
|
||||
$this->blockRendererItem->setProductHelpers([]);
|
||||
$html = $this->blockRendererItem->render($quoteItem);
|
||||
|
||||
$this->assertRendererItemValue($quoteItem, $html);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the product name and options are in the block.
|
||||
*
|
||||
* @param Item $quoteItem
|
||||
* @param string $html
|
||||
* @return void
|
||||
*/
|
||||
private function assertRendererItemValue(Item $quoteItem, string $html): void
|
||||
{
|
||||
$optionsXPath = $this->getOptionsValueXPath($quoteItem);
|
||||
$productName = $quoteItem->getProduct()->getName();
|
||||
|
||||
$productNameXPath = count($optionsXPath) === 0 ? "/descendant::*[contains(text(), '$productName')]"
|
||||
: "//div[contains(@class, 'product-title') and contains(text(), '$productName')]";
|
||||
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath($productNameXPath, $html),
|
||||
'The block\'s rendered value does not contain expected product name.'
|
||||
);
|
||||
foreach ($optionsXPath as $option) {
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath($option['xpath'], $html),
|
||||
sprintf('The block\'s rendered value does not contain expected option. Option: %s', $option['label'])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get item options and their xpath expression
|
||||
*
|
||||
* @param Item $quoteItem
|
||||
* @return array
|
||||
*/
|
||||
private function getOptionsValueXPath(Item $quoteItem): array
|
||||
{
|
||||
$options = $this->productConfiguration->getOptions($quoteItem);
|
||||
foreach ($options as $key => $option) {
|
||||
$options[$key]['xpath'] = "//dl[contains(@class, 'item-options')]"
|
||||
. "/dt[contains(text(), '{$option['label']}')]"
|
||||
. "/following-sibling::dd[1]";
|
||||
|
||||
if (isset($option['option_type'])
|
||||
&& $option['option_type'] == ProductCustomOptionInterface::OPTION_GROUP_FILE) {
|
||||
$value = explode(" ", $option['print_value']);
|
||||
$options[$key]['xpath'] .= "[contains(text(), '{$value[0]}')]";
|
||||
} else {
|
||||
$options[$key]['xpath'] .= "[contains(text(), '{$option['value']}')]";
|
||||
}
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Customer\Block\Adminhtml\Edit\Tab\View\Grid\Renderer\Item;
|
||||
|
||||
use Magento\Customer\Block\Adminhtml\Edit\Tab\View\Grid\Renderer\AbstractItemTest;
|
||||
use Magento\Framework\Module\Manager;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Class checks item block rendering with configurable product.
|
||||
*
|
||||
* @see \Magento\Customer\Block\Adminhtml\Edit\Tab\View\Grid\Renderer\Item
|
||||
*/
|
||||
class ItemConfigurableTest extends AbstractItemTest
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Manager $moduleManager */
|
||||
$moduleManager = $objectManager->get(Manager::class);
|
||||
//This check is needed because Customer independent of Magento_ConfigurableProduct
|
||||
if (!$moduleManager->isEnabled('Magento_ConfigurableProduct')) {
|
||||
self::markTestSkipped('Magento_ConfigurableProduct module disabled.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/ConfigurableProduct/_files/customer_quote_with_items_configurable_product.php
|
||||
* @return void
|
||||
*/
|
||||
public function testRenderConfigurableProduct(): void
|
||||
{
|
||||
$this->processRender();
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Customer\Block\Adminhtml\Edit\Tab\View\Grid\Renderer;
|
||||
|
||||
/**
|
||||
* Class checks item block rendering with simple product and simple product with options.
|
||||
*
|
||||
* @see \Magento\Customer\Block\Adminhtml\Edit\Tab\View\Grid\Renderer\Item
|
||||
*/
|
||||
class ItemTest extends AbstractItemTest
|
||||
{
|
||||
/**
|
||||
* @magentoDataFixture Magento/Checkout/_files/customer_quote_with_items_simple_product_options.php
|
||||
* @return void
|
||||
*/
|
||||
public function testRenderProductOptions(): void
|
||||
{
|
||||
$this->processRender();
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Checkout/_files/quote_with_address_saved.php
|
||||
* @return void
|
||||
*/
|
||||
public function testRenderSimpleProduct(): void
|
||||
{
|
||||
$this->processRender();
|
||||
}
|
||||
}
|
||||
+287
@@ -0,0 +1,287 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Customer\Block\Adminhtml\Edit\Tab\View;
|
||||
|
||||
use Magento\Customer\Api\Data\CustomerInterfaceFactory;
|
||||
use Magento\Customer\Controller\RegistryConstants;
|
||||
|
||||
/**
|
||||
* Magento\Customer\Block\Adminhtml\Edit\Tab\View
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class PersonalInfoTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/** @var \Magento\Backend\Block\Template\Context */
|
||||
private $_context;
|
||||
|
||||
/** @var \Magento\Framework\Registry */
|
||||
private $_coreRegistry;
|
||||
|
||||
/** @var CustomerInterfaceFactory */
|
||||
private $_customerFactory;
|
||||
|
||||
/** @var \Magento\Customer\Api\CustomerRepositoryInterface */
|
||||
private $_customerRepository;
|
||||
|
||||
/** @var \Magento\Customer\Api\GroupRepositoryInterface */
|
||||
private $_groupRepository;
|
||||
|
||||
/** @var \Magento\Store\Model\StoreManagerInterface */
|
||||
private $_storeManager;
|
||||
|
||||
/** @var \Magento\Framework\ObjectManagerInterface */
|
||||
private $_objectManager;
|
||||
|
||||
/** @var \Magento\Framework\Reflection\DataObjectProcessor */
|
||||
private $_dataObjectProcessor;
|
||||
|
||||
/** @var PersonalInfo */
|
||||
private $_block;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Stdlib\DateTime
|
||||
*/
|
||||
protected $dateTime;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
$this->_storeManager = $this->_objectManager->get(\Magento\Store\Model\StoreManagerInterface::class);
|
||||
$this->_context = $this->_objectManager->get(
|
||||
\Magento\Backend\Block\Template\Context::class,
|
||||
['storeManager' => $this->_storeManager]
|
||||
);
|
||||
|
||||
$this->_customerFactory = $this->_objectManager->get(
|
||||
\Magento\Customer\Api\Data\CustomerInterfaceFactory::class
|
||||
);
|
||||
$this->_coreRegistry = $this->_objectManager->get(\Magento\Framework\Registry::class);
|
||||
$this->_customerRepository = $this->_objectManager->get(
|
||||
\Magento\Customer\Api\CustomerRepositoryInterface::class
|
||||
);
|
||||
$this->_dataObjectProcessor = $this->_objectManager->get(
|
||||
\Magento\Framework\Reflection\DataObjectProcessor::class
|
||||
);
|
||||
|
||||
$this->_groupRepository = $this->_objectManager->get(\Magento\Customer\Api\GroupRepositoryInterface::class);
|
||||
$this->dateTime = $this->_objectManager->get(\Magento\Framework\Stdlib\DateTime::class);
|
||||
|
||||
$this->_block = $this->_objectManager->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
)->createBlock(
|
||||
\Magento\Customer\Block\Adminhtml\Edit\Tab\View\PersonalInfo::class,
|
||||
'',
|
||||
[
|
||||
'context' => $this->_context,
|
||||
'groupService' => $this->_groupRepository,
|
||||
'registry' => $this->_coreRegistry
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->_coreRegistry->unregister(RegistryConstants::CURRENT_CUSTOMER_ID);
|
||||
/** @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()
|
||||
{
|
||||
$expectedCustomer = $this->_loadCustomer();
|
||||
$expectedCustomerData = $this->_dataObjectProcessor->buildOutputDataArray(
|
||||
$expectedCustomer,
|
||||
\Magento\Customer\Api\Data\CustomerInterface::class
|
||||
);
|
||||
$actualCustomer = $this->_block->getCustomer();
|
||||
$actualCustomerData = $this->_dataObjectProcessor->buildOutputDataArray(
|
||||
$actualCustomer,
|
||||
\Magento\Customer\Api\Data\CustomerInterface::class
|
||||
);
|
||||
foreach ($expectedCustomerData as $property => $value) {
|
||||
$expectedValue = is_numeric($value) ? (int)$value : $value;
|
||||
$actualValue = isset($actualCustomerData[$property]) ? $actualCustomerData[$property] : null;
|
||||
$actualValue = is_numeric($actualValue) ? (int)$actualValue : $actualValue;
|
||||
$this->assertEquals($expectedValue, $actualValue);
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetCustomerEmpty()
|
||||
{
|
||||
$expectedCustomer = $this->createCustomerAndAddToBackendSession();
|
||||
$actualCustomer = $this->_block->getCustomer();
|
||||
$this->assertEquals($expectedCustomer->getExtensionAttributes(), $actualCustomer->getExtensionAttributes());
|
||||
$this->assertEquals($expectedCustomer, $actualCustomer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
*/
|
||||
public function testGetGroupName()
|
||||
{
|
||||
$groupName = $this->_groupRepository->getById($this->_loadCustomer()->getGroupId())->getCode();
|
||||
$this->assertEquals($groupName, $this->_block->getGroupName());
|
||||
}
|
||||
|
||||
public function testGetGroupNameNull()
|
||||
{
|
||||
$this->createCustomerAndAddToBackendSession();
|
||||
$this->assertNull($this->_block->getGroupName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
*/
|
||||
public function testGetCreateDate()
|
||||
{
|
||||
$createdAt = $this->_block->formatDate(
|
||||
$this->_loadCustomer()->getCreatedAt(),
|
||||
\IntlDateFormatter::MEDIUM,
|
||||
true
|
||||
);
|
||||
$this->assertEquals($createdAt, $this->_block->getCreateDate());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
*/
|
||||
public function testGetStoreCreateDate()
|
||||
{
|
||||
$customer = $this->_loadCustomer();
|
||||
$localeDate = $this->_context->getLocaleDate();
|
||||
$timezone = $localeDate->getConfigTimezone(
|
||||
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
|
||||
$customer->getStoreId()
|
||||
);
|
||||
$storeCreateDate = $this->_block->formatDate(
|
||||
$customer->getCreatedAt(),
|
||||
\IntlDateFormatter::MEDIUM,
|
||||
true,
|
||||
null,
|
||||
$timezone
|
||||
);
|
||||
$this->assertEquals($storeCreateDate, $this->_block->getStoreCreateDate());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
*/
|
||||
public function testGetStoreCreateDateTimezone()
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface $defaultTimeZonePath
|
||||
*/
|
||||
$defaultTimeZonePath = $this->_objectManager->get(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::class)
|
||||
->getDefaultTimezonePath();
|
||||
$timezone = $this->_context->getScopeConfig()->getValue(
|
||||
$defaultTimeZonePath,
|
||||
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
|
||||
$this->_loadCustomer()->getStoreId()
|
||||
);
|
||||
$this->assertEquals($timezone, $this->_block->getStoreCreateDateTimezone());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
*/
|
||||
public function testIsConfirmedStatusConfirmed()
|
||||
{
|
||||
$this->_loadCustomer();
|
||||
$this->assertEquals(__('Confirmation Not Required'), $this->_block->getIsConfirmedStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testIsConfirmedStatusConfirmationIsNotRequired()
|
||||
{
|
||||
$password = 'password';
|
||||
/** @var \Magento\Customer\Api\Data\CustomerInterface $customer */
|
||||
$customer = $this->_customerFactory->create()->setConfirmation(
|
||||
true
|
||||
)->setFirstname(
|
||||
'firstname'
|
||||
)->setLastname(
|
||||
'lastname'
|
||||
)->setEmail(
|
||||
'email@email.com'
|
||||
);
|
||||
$customer = $this->_customerRepository->save($customer, $password);
|
||||
$this->_coreRegistry->register(RegistryConstants::CURRENT_CUSTOMER_ID, $customer->getId());
|
||||
$this->assertEquals('Confirmation Not Required', $this->_block->getIsConfirmedStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
*/
|
||||
public function testGetCreatedInStore()
|
||||
{
|
||||
$storeName = $this->_storeManager->getStore($this->_loadCustomer()->getStoreId())->getName();
|
||||
$this->assertEquals($storeName, $this->_block->getCreatedInStore());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_address.php
|
||||
*/
|
||||
public function testGetBillingAddressHtml()
|
||||
{
|
||||
$this->_loadCustomer();
|
||||
$html = $this->_block->getBillingAddressHtml();
|
||||
$this->assertStringContainsString('John Smith<br />', $html);
|
||||
$this->assertStringContainsString('Green str, 67<br />', $html);
|
||||
$this->assertStringContainsString('CityM, Alabama, 75477<br />', $html);
|
||||
}
|
||||
|
||||
public function testGetBillingAddressHtmlNoDefaultAddress()
|
||||
{
|
||||
$this->createCustomerAndAddToBackendSession();
|
||||
$this->assertEquals(
|
||||
__('The customer does not have default billing address.'),
|
||||
$this->_block->getBillingAddressHtml()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Magento\Customer\Api\Data\CustomerInterface
|
||||
*/
|
||||
private function createCustomerAndAddToBackendSession()
|
||||
{
|
||||
/** @var \Magento\Customer\Api\Data\CustomerInterface $customer */
|
||||
$customer = $this->_customerFactory->create()->setFirstname(
|
||||
'firstname'
|
||||
)->setLastname(
|
||||
'lastname'
|
||||
)->setEmail(
|
||||
'email@email.com'
|
||||
);
|
||||
$data = ['account' => $this->_dataObjectProcessor
|
||||
->buildOutputDataArray($customer, \Magento\Customer\Api\Data\CustomerInterface::class), ];
|
||||
$this->_context->getBackendSession()->setCustomerData($data);
|
||||
return $customer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Magento\Customer\Api\Data\CustomerInterface
|
||||
*/
|
||||
private function _loadCustomer()
|
||||
{
|
||||
$customer = $this->_customerRepository->getById(1);
|
||||
$data = ['account' => $this->_dataObjectProcessor
|
||||
->buildOutputDataArray($customer, \Magento\Customer\Api\Data\CustomerInterface::class), ];
|
||||
$this->_context->getBackendSession()->setCustomerData($data);
|
||||
$this->_coreRegistry->register(RegistryConstants::CURRENT_CUSTOMER_ID, $customer->getId());
|
||||
return $customer;
|
||||
}
|
||||
}
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Customer\Block\Adminhtml\Edit\Tab\View;
|
||||
|
||||
use Magento\Customer\Controller\RegistryConstants;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Test for \Magento\Customer\Block\Adminhtml\Edit\Tab\View\Sales
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class SalesTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
const MAIN_WEBSITE = 1;
|
||||
|
||||
/**
|
||||
* Sales block under test.
|
||||
*
|
||||
* @var Sales
|
||||
*/
|
||||
private $block;
|
||||
|
||||
/**
|
||||
* Core registry.
|
||||
*
|
||||
* @var \Magento\Framework\Registry
|
||||
*/
|
||||
private $coreRegistry;
|
||||
|
||||
/**
|
||||
* Sales order view Html.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $html;
|
||||
|
||||
/**
|
||||
* Execute per test initialization.
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$objectManager->get(\Magento\Framework\App\State::class)->setAreaCode('adminhtml');
|
||||
|
||||
$this->coreRegistry = $objectManager->get(\Magento\Framework\Registry::class);
|
||||
$this->coreRegistry->register(RegistryConstants::CURRENT_CUSTOMER_ID, 1);
|
||||
|
||||
$this->block = $objectManager->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
)->createBlock(
|
||||
\Magento\Customer\Block\Adminhtml\Edit\Tab\View\Sales::class,
|
||||
'sales_' . random_int(0, PHP_INT_MAX),
|
||||
['coreRegistry' => $this->coreRegistry]
|
||||
)->setTemplate(
|
||||
'tab/view/sales.phtml'
|
||||
);
|
||||
$this->html = $this->block->toHtml();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute post test cleanup.
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->coreRegistry->unregister(RegistryConstants::CURRENT_CUSTOMER_ID);
|
||||
$this->html = '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Test basic currency formatting on the Main Website.
|
||||
*/
|
||||
public function testFormatCurrency()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<span class="price">$10.00</span>',
|
||||
$this->block->formatCurrency(10.00, self::MAIN_WEBSITE)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that the website is not in single store mode.
|
||||
*/
|
||||
public function testIsSingleStoreMode()
|
||||
{
|
||||
$this->assertFalse($this->block->isSingleStoreMode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify sales totals. No sales so there are no totals.
|
||||
*/
|
||||
public function testGetTotals()
|
||||
{
|
||||
$this->assertEquals(
|
||||
['lifetime' => 0, 'base_lifetime' => 0, 'base_avgsale' => 0, 'num_orders' => 0],
|
||||
$this->block->getTotals()->getData()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that there are no rows in the sales order grid.
|
||||
*/
|
||||
public function testGetRows()
|
||||
{
|
||||
$this->assertEmpty($this->block->getRows());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that the Main Website has no websites.
|
||||
*/
|
||||
public function testGetWebsiteCount()
|
||||
{
|
||||
$this->assertEquals(0, $this->block->getWebsiteCount(self::MAIN_WEBSITE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify basic content of the sales view Html.
|
||||
*/
|
||||
public function testToHtml()
|
||||
{
|
||||
$this->assertStringContainsString('<span class="title">Sales Statistics</span>', $this->html);
|
||||
$this->assertStringContainsString('<strong>All Store Views</strong>', $this->html);
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Customer\Block\Adminhtml\Edit\Tab\View;
|
||||
|
||||
use Magento\Customer\Controller\RegistryConstants;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\Framework\View\LayoutInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Tests for customer wish list tab.
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
* @magentoDbIsolation disabled
|
||||
*/
|
||||
class WishlistTest extends TestCase
|
||||
{
|
||||
/** @var ObjectManagerInterface */
|
||||
private $objectManager;
|
||||
|
||||
/** @var Registry */
|
||||
private $registry;
|
||||
|
||||
/** @var Wishlist */
|
||||
private $block;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->registry = $this->objectManager->get(Registry::class);
|
||||
$this->block = $this->objectManager->get(LayoutInterface::class)->createBlock(Wishlist::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->registry->unregister(RegistryConstants::CURRENT_CUSTOMER_ID);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Wishlist/_files/wishlist.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testWishListGrid(): void
|
||||
{
|
||||
$this->registerCustomerId(1);
|
||||
$this->assertCount(1, $this->block->getPreparedCollection());
|
||||
}
|
||||
|
||||
/**
|
||||
* Add customer id to registry.
|
||||
*
|
||||
* @param int $customerId
|
||||
* @return void
|
||||
*/
|
||||
private function registerCustomerId(int $customerId): void
|
||||
{
|
||||
$this->registry->unregister(RegistryConstants::CURRENT_CUSTOMER_ID);
|
||||
$this->registry->register(RegistryConstants::CURRENT_CUSTOMER_ID, $customerId);
|
||||
}
|
||||
}
|
||||
+159
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Customer\Block\Adminhtml\Edit\Tab;
|
||||
|
||||
use Magento\Customer\Api\CustomerRepositoryInterface;
|
||||
use Magento\Customer\Api\Data\CustomerInterfaceFactory;
|
||||
use Magento\Customer\Controller\RegistryConstants;
|
||||
|
||||
/**
|
||||
* Magento\Customer\Block\Adminhtml\Edit\Tab\View
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class ViewTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/** @var \Magento\Backend\Block\Template\Context */
|
||||
private $_context;
|
||||
|
||||
/** @var \Magento\Framework\Registry */
|
||||
private $_coreRegistry;
|
||||
|
||||
/** @var CustomerDataBuilder */
|
||||
private $_customerFactory;
|
||||
|
||||
/** @var CustomerRepositoryInterface */
|
||||
private $_customerRepository;
|
||||
|
||||
/** @var \Magento\Store\Model\StoreManagerInterface */
|
||||
private $_storeManager;
|
||||
|
||||
/** @var \Magento\Framework\ObjectManagerInterface */
|
||||
private $_objectManager;
|
||||
|
||||
/** @var \Magento\Framework\Reflection\DataObjectProcessor */
|
||||
private $_dataObjectProcessor;
|
||||
|
||||
/** @var View */
|
||||
private $_block;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
$this->_storeManager = $this->_objectManager->get(\Magento\Store\Model\StoreManager::class);
|
||||
$this->_context = $this->_objectManager->get(
|
||||
\Magento\Backend\Block\Template\Context::class,
|
||||
['storeManager' => $this->_storeManager]
|
||||
);
|
||||
|
||||
$this->_customerFactory = $this->_objectManager->get(
|
||||
\Magento\Customer\Api\Data\CustomerInterfaceFactory::class
|
||||
);
|
||||
$this->_coreRegistry = $this->_objectManager->get(\Magento\Framework\Registry::class);
|
||||
$this->_customerRepository = $this->_objectManager->get(
|
||||
\Magento\Customer\Api\CustomerRepositoryInterface::class
|
||||
);
|
||||
$this->_dataObjectProcessor = $this->_objectManager->get(
|
||||
\Magento\Framework\Reflection\DataObjectProcessor::class
|
||||
);
|
||||
|
||||
$this->_block = $this->_objectManager->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
)->createBlock(
|
||||
\Magento\Customer\Block\Adminhtml\Edit\Tab\View::class,
|
||||
'',
|
||||
[
|
||||
'context' => $this->_context,
|
||||
'registry' => $this->_coreRegistry
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->_coreRegistry->unregister(RegistryConstants::CURRENT_CUSTOMER_ID);
|
||||
}
|
||||
|
||||
public function testGetTabLabel()
|
||||
{
|
||||
$this->assertEquals(__('Customer View'), $this->_block->getTabLabel());
|
||||
}
|
||||
|
||||
public function testGetTabTitle()
|
||||
{
|
||||
$this->assertEquals(__('Customer View'), $this->_block->getTabTitle());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
*/
|
||||
public function testCanShowTab()
|
||||
{
|
||||
$this->_loadCustomer();
|
||||
$this->assertTrue($this->_block->canShowTab());
|
||||
}
|
||||
|
||||
public function testCanShowTabNot()
|
||||
{
|
||||
$this->_createCustomer();
|
||||
$this->assertFalse($this->_block->canShowTab());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
*/
|
||||
public function testIsHiddenNot()
|
||||
{
|
||||
$this->_loadCustomer();
|
||||
$this->assertFalse($this->_block->isHidden());
|
||||
}
|
||||
|
||||
public function testIsHidden()
|
||||
{
|
||||
$this->_createCustomer();
|
||||
$this->assertTrue($this->_block->isHidden());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Magento\Customer\Api\Data\CustomerInterface
|
||||
*/
|
||||
private function _createCustomer()
|
||||
{
|
||||
/** @var \Magento\Customer\Api\Data\CustomerInterface $customer */
|
||||
$customer = $this->_customerFactory->create()->setFirstname(
|
||||
'firstname'
|
||||
)->setLastname(
|
||||
'lastname'
|
||||
)->setEmail(
|
||||
'email@email.com'
|
||||
);
|
||||
$data = ['account' => $this->_dataObjectProcessor
|
||||
->buildOutputDataArray($customer, \Magento\Customer\Api\Data\CustomerInterface::class), ];
|
||||
$this->_context->getBackendSession()->setCustomerData($data);
|
||||
return $customer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Magento\Customer\Api\Data\CustomerInterface
|
||||
*/
|
||||
private function _loadCustomer()
|
||||
{
|
||||
/** @var \Magento\Customer\Api\Data\CustomerInterface $customer */
|
||||
$customer = $this->_customerRepository->getById(1);
|
||||
$data = ['account' => $this->_dataObjectProcessor
|
||||
->buildOutputDataArray($customer, \Magento\Customer\Api\Data\CustomerInterface::class), ];
|
||||
$this->_context->getBackendSession()->setCustomerData($data);
|
||||
$this->_coreRegistry->register(RegistryConstants::CURRENT_CUSTOMER_ID, $customer->getId());
|
||||
return $customer;
|
||||
}
|
||||
|
||||
protected function dataToString($data)
|
||||
{
|
||||
return parent::dataToString($data); // TODO: Change the autogenerated stub
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Customer\Block\Adminhtml;
|
||||
|
||||
use Magento\Customer\Controller\RegistryConstants;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Test for \Magento\Customer\Block\Adminhtml\Edit
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
*/
|
||||
class EditTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* The edit block under test.
|
||||
*
|
||||
* @var Edit
|
||||
*/
|
||||
private $block;
|
||||
|
||||
/**
|
||||
* Core Registry.
|
||||
*
|
||||
* @var \Magento\Framework\Registry
|
||||
*/
|
||||
private $coreRegistry;
|
||||
|
||||
/**
|
||||
* The customer Id.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private static $customerId = 1;
|
||||
|
||||
/**
|
||||
* Execute per test initialization.
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$objectManager->get(\Magento\Framework\App\State::class)->setAreaCode('adminhtml');
|
||||
|
||||
$this->coreRegistry = $objectManager->get(\Magento\Framework\Registry::class);
|
||||
$this->coreRegistry->register(RegistryConstants::CURRENT_CUSTOMER_ID, self::$customerId);
|
||||
|
||||
$this->block = $objectManager->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
)->createBlock(
|
||||
\Magento\Customer\Block\Adminhtml\Edit::class,
|
||||
'',
|
||||
['coreRegistry' => $this->coreRegistry]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute post class cleanup after all tests have executed.
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->coreRegistry->unregister(RegistryConstants::CURRENT_CUSTOMER_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that the customer Id is the one that was set in the registry.
|
||||
*/
|
||||
public function testGetCustomerId()
|
||||
{
|
||||
$this->assertEquals(self::$customerId, $this->block->getCustomerId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that the correct order create Url is generated.
|
||||
*/
|
||||
public function testGetCreateOrderUrl()
|
||||
{
|
||||
$this->assertStringContainsString(
|
||||
'sales/order_create/start/customer_id/' . self::$customerId,
|
||||
$this->block->getCreateOrderUrl()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that the header text is correct for a new customer.
|
||||
*/
|
||||
public function testGetHeaderTextNewCustomer()
|
||||
{
|
||||
$this->coreRegistry->unregister(RegistryConstants::CURRENT_CUSTOMER_ID);
|
||||
$this->assertEquals('New Customer', $this->block->getHeaderText());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that the header text is correct for an existing customer.
|
||||
*/
|
||||
public function testGetHeaderTextExistingCustomer()
|
||||
{
|
||||
$this->assertEquals('John Smith', $this->block->getHeaderText());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that the correct customer validation Url is generated.
|
||||
*/
|
||||
public function testGetValidationUrl()
|
||||
{
|
||||
$this->assertStringContainsString('customer/index/validate', $this->block->getValidationUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify the basic content of the block's form Html.
|
||||
*/
|
||||
public function testGetFormHtml()
|
||||
{
|
||||
$html = $this->block->getFormHtml();
|
||||
$this->assertStringContainsString('<div class="entry-edit form-inline">', $html);
|
||||
$this->assertStringMatchesFormat('%a name="customer_id" %s value="' . self::$customerId . '" %a', $html);
|
||||
$this->assertStringContainsString('id="product_composite_configure_form"', $html);
|
||||
}
|
||||
}
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Customer\Block\Adminhtml\Grid\Renderer;
|
||||
|
||||
use Magento\Backend\Block\Widget\Grid\Column\Extended;
|
||||
use Magento\Framework\View\LayoutInterface;
|
||||
use Magento\Quote\Model\Quote\Item;
|
||||
use Magento\Quote\Model\ResourceModel\Quote\Item\CollectionFactory;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Helper\Xpath;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Base class for testing \Magento\Customer\Block\Adminhtml\Grid\Renderer\Multiaction block
|
||||
*/
|
||||
abstract class AbstractMultiactionTest extends TestCase
|
||||
{
|
||||
/** @var ObjectManager */
|
||||
protected $objectManager;
|
||||
|
||||
/** @var Extended */
|
||||
protected $blockColumn;
|
||||
|
||||
/** @var Multiaction */
|
||||
protected $blockMultiaction;
|
||||
|
||||
/** @var LayoutInterface */
|
||||
private $layout;
|
||||
|
||||
/** @var CollectionFactory */
|
||||
private $quoteItemCollectionFactory;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->layout = $this->objectManager->get(LayoutInterface::class);
|
||||
$this->blockColumn = $this->layout->createBlock(Extended::class);
|
||||
$this->blockColumn->setData([
|
||||
'header' => 'Action',
|
||||
'index' => 'item_id',
|
||||
'renderer' => Multiaction::class,
|
||||
'filter' => false,
|
||||
'sortable' => false,
|
||||
]);
|
||||
$this->blockMultiaction = $this->layout->createBlock(Multiaction::class);
|
||||
$this->quoteItemCollectionFactory = $this->objectManager->get(CollectionFactory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check multiaction block rendering
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function processRender(): void
|
||||
{
|
||||
$itemsCollection = $this->quoteItemCollectionFactory->create();
|
||||
/** @var Item $quoteItem */
|
||||
$quoteItem = $itemsCollection->getFirstItem();
|
||||
$this->assertNotEmpty($quoteItem->getId());
|
||||
$actions = [
|
||||
[
|
||||
'caption' => 'configure',
|
||||
'url' => 'url_configureItem',
|
||||
'process' => 'configurable',
|
||||
'control_object' => 'cartControl',
|
||||
],
|
||||
[
|
||||
'caption' => 'delete',
|
||||
'url' => 'url_removeItem',
|
||||
'onclick' => 'return cartControl.removeItem($item_id);'
|
||||
],
|
||||
];
|
||||
$this->blockColumn->addData(['actions' => $actions]);
|
||||
$this->blockMultiaction->setColumn($this->blockColumn);
|
||||
$html = $this->blockMultiaction->render($quoteItem);
|
||||
|
||||
foreach ($actions as $action) {
|
||||
$this->assertUrl((int)$quoteItem->getId(), $action, $html);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the link in the block is correct
|
||||
*
|
||||
* @param int $quoteItemId
|
||||
* @param array $action
|
||||
* @param string $html
|
||||
* @return void
|
||||
*/
|
||||
private function assertUrl(int $quoteItemId, array $action, string $html): void
|
||||
{
|
||||
$jsFunction = str_replace('url_', '', $action['url']);
|
||||
$configureXPath = "//a[text()='{$action['caption']}' and @href='{$action['url']}']";
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath($configureXPath, $html),
|
||||
sprintf('Expected %s link is incorrect or missing', $action['caption'])
|
||||
);
|
||||
$this->assertStringContainsString("return cartControl.$jsFunction($quoteItemId)", $html);
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Customer\Block\Adminhtml\Grid\Renderer\Multiaction;
|
||||
|
||||
use Magento\Customer\Block\Adminhtml\Grid\Renderer\AbstractMultiactionTest;
|
||||
use Magento\Framework\Module\Manager;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Class checks multiaction block rendering with bundle product.
|
||||
*
|
||||
* @see \Magento\Customer\Block\Adminhtml\Grid\Renderer\Multiaction
|
||||
*/
|
||||
class MultiactionBundleTest extends AbstractMultiactionTest
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Manager $moduleManager */
|
||||
$moduleManager = $objectManager->get(Manager::class);
|
||||
//This check is needed because Customer independent of Magento_Bundle
|
||||
if (!$moduleManager->isEnabled('Magento_Bundle')) {
|
||||
self::markTestSkipped('Magento_Bundle module disabled.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Bundle/_files/quote_with_bundle_and_options.php
|
||||
* @return void
|
||||
*/
|
||||
public function testRenderConfigurableProduct(): void
|
||||
{
|
||||
$this->processRender();
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Customer\Block\Adminhtml\Grid\Renderer\Multiaction;
|
||||
|
||||
use Magento\Customer\Block\Adminhtml\Grid\Renderer\AbstractMultiactionTest;
|
||||
use Magento\Framework\Module\Manager;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Class checks multiaction block rendering with configurable product.
|
||||
*
|
||||
* @see \Magento\Customer\Block\Adminhtml\Grid\Renderer\Multiaction
|
||||
*/
|
||||
class MultiactionConfigurableTest extends AbstractMultiactionTest
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Manager $moduleManager */
|
||||
$moduleManager = $objectManager->get(Manager::class);
|
||||
//This check is needed because Customer independent of Magento_ConfigurableProduct
|
||||
if (!$moduleManager->isEnabled('Magento_ConfigurableProduct')) {
|
||||
self::markTestSkipped('Magento_ConfigurableProduct module disabled.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/ConfigurableProduct/_files/customer_quote_with_items_configurable_product.php
|
||||
* @return void
|
||||
*/
|
||||
public function testRenderConfigurableProduct(): void
|
||||
{
|
||||
$this->processRender();
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Customer\Block\Adminhtml\Grid\Renderer;
|
||||
|
||||
use Magento\Framework\DataObject;
|
||||
|
||||
/**
|
||||
* Class checks multiaction block rendering with simple product and simple product with options.
|
||||
*
|
||||
* @see \Magento\Customer\Block\Adminhtml\Grid\Renderer\Multiaction
|
||||
*/
|
||||
class MultiactionTest extends AbstractMultiactionTest
|
||||
{
|
||||
/**
|
||||
* @dataProvider renderEmptyProvider
|
||||
* @param array $columnData
|
||||
* @return void
|
||||
*/
|
||||
public function testRenderEmpty(array $columnData): void
|
||||
{
|
||||
/** @var DataObject $row */
|
||||
$row = $this->objectManager->create(DataObject::class);
|
||||
$this->blockColumn->addData($columnData);
|
||||
$this->blockMultiaction->setColumn($this->blockColumn);
|
||||
$this->assertEquals(
|
||||
' ',
|
||||
$this->blockMultiaction->render($row)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testRenderEmpty
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function renderEmptyProvider(): array
|
||||
{
|
||||
return [
|
||||
'empty_actions' => [
|
||||
'column_data' => ['actions' => []],
|
||||
],
|
||||
'not_array_actions' => [
|
||||
'column_data' => ['actions' => 'actions'],
|
||||
],
|
||||
'empty_actions_element' => [
|
||||
'column_data' => [
|
||||
'actions' => [
|
||||
'action_1' => 'actions',
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Checkout/_files/customer_quote_with_items_simple_product_options.php
|
||||
* @return void
|
||||
*/
|
||||
public function testRenderProductOptions(): void
|
||||
{
|
||||
$this->processRender();
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Checkout/_files/quote_with_address_saved.php
|
||||
* @return void
|
||||
*/
|
||||
public function testRenderSimpleProduct(): void
|
||||
{
|
||||
$this->markTestSkipped('Test is blocked by issue MC-34612');
|
||||
$this->processRender();
|
||||
}
|
||||
}
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Customer\Block\Adminhtml\Group\Edit;
|
||||
|
||||
use Magento\Customer\Api\Data\GroupInterface;
|
||||
use Magento\Customer\Controller\RegistryConstants;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Magento\Customer\Block\Adminhtml\Group\Edit\Form
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class FormTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\View\LayoutInterface
|
||||
*/
|
||||
private $layout;
|
||||
|
||||
/**
|
||||
* @var \Magento\Customer\Api\GroupRepositoryInterface
|
||||
*/
|
||||
private $groupRepository;
|
||||
|
||||
/**
|
||||
* @var \Magento\Customer\Api\GroupManagementInterface
|
||||
*/
|
||||
private $groupManagement;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Registry
|
||||
*/
|
||||
private $registry;
|
||||
|
||||
/**
|
||||
* Execute per test initialization.
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->layout = Bootstrap::getObjectManager()->create(\Magento\Framework\View\Layout::class);
|
||||
$this->groupRepository = Bootstrap::getObjectManager()
|
||||
->get(\Magento\Customer\Api\GroupRepositoryInterface::class);
|
||||
$this->groupManagement = Bootstrap::getObjectManager()
|
||||
->get(\Magento\Customer\Api\GroupManagementInterface::class);
|
||||
$this->registry = Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute per test cleanup.
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->registry->unregister(RegistryConstants::CURRENT_GROUP_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test retrieving a valid group form.
|
||||
*/
|
||||
public function testGetForm()
|
||||
{
|
||||
$this->registry
|
||||
->register(RegistryConstants::CURRENT_GROUP_ID, $this->groupManagement->getDefaultGroup(0)->getId());
|
||||
|
||||
/** @var $block Form */
|
||||
$block = $this->layout->createBlock(\Magento\Customer\Block\Adminhtml\Group\Edit\Form::class, 'block');
|
||||
$form = $block->getForm();
|
||||
|
||||
$this->assertEquals('edit_form', $form->getId());
|
||||
$this->assertEquals('post', $form->getMethod());
|
||||
$baseFieldSet = $form->getElement('base_fieldset');
|
||||
$this->assertNotNull($baseFieldSet);
|
||||
$groupCodeElement = $form->getElement('customer_group_code');
|
||||
$this->assertNotNull($groupCodeElement);
|
||||
$taxClassIdElement = $form->getElement('tax_class_id');
|
||||
$this->assertNotNull($taxClassIdElement);
|
||||
$idElement = $form->getElement('id');
|
||||
$this->assertNotNull($idElement);
|
||||
$this->assertEquals('1', $idElement->getValue());
|
||||
$this->assertEquals('3', $taxClassIdElement->getValue());
|
||||
/** @var \Magento\Tax\Model\TaxClass\Source\Customer $taxClassCustomer */
|
||||
$taxClassCustomer = Bootstrap::getObjectManager()->get(\Magento\Tax\Model\TaxClass\Source\Customer::class);
|
||||
$this->assertEquals($taxClassCustomer->toOptionArray(false), $taxClassIdElement->getData('values'));
|
||||
$this->assertEquals('General', $groupCodeElement->getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_group.php
|
||||
*/
|
||||
public function testGetFormExistInCustomGroup()
|
||||
{
|
||||
$builder = Bootstrap::getObjectManager()->create(\Magento\Framework\Api\FilterBuilder::class);
|
||||
/** @var \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteria */
|
||||
$searchCriteria = Bootstrap::getObjectManager()
|
||||
->create(\Magento\Framework\Api\SearchCriteriaBuilder::class)
|
||||
->addFilters([$builder->setField('code')->setValue('custom_group')->create()]);
|
||||
/** @var GroupInterface $customerGroup */
|
||||
$customerGroup = $this->groupRepository->getList($searchCriteria->create())->getItems()[0];
|
||||
$this->registry->register(RegistryConstants::CURRENT_GROUP_ID, $customerGroup->getId());
|
||||
|
||||
/** @var $block Form */
|
||||
$block = $this->layout->createBlock(\Magento\Customer\Block\Adminhtml\Group\Edit\Form::class, 'block');
|
||||
$form = $block->getForm();
|
||||
|
||||
$this->assertEquals('edit_form', $form->getId());
|
||||
$this->assertEquals('post', $form->getMethod());
|
||||
$baseFieldSet = $form->getElement('base_fieldset');
|
||||
$this->assertNotNull($baseFieldSet);
|
||||
$groupCodeElement = $form->getElement('customer_group_code');
|
||||
$this->assertNotNull($groupCodeElement);
|
||||
$taxClassIdElement = $form->getElement('tax_class_id');
|
||||
$this->assertNotNull($taxClassIdElement);
|
||||
$idElement = $form->getElement('id');
|
||||
$this->assertNotNull($idElement);
|
||||
$this->assertEquals($customerGroup->getId(), $idElement->getValue());
|
||||
$this->assertEquals($customerGroup->getTaxClassId(), $taxClassIdElement->getValue());
|
||||
/** @var \Magento\Tax\Model\TaxClass\Source\Customer $taxClassCustomer */
|
||||
$taxClassCustomer = Bootstrap::getObjectManager()->get(\Magento\Tax\Model\TaxClass\Source\Customer::class);
|
||||
$this->assertEquals($taxClassCustomer->toOptionArray(false), $taxClassIdElement->getData('values'));
|
||||
$this->assertEquals($customerGroup->getCode(), $groupCodeElement->getValue());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Customer\Block\Adminhtml\Group;
|
||||
|
||||
use Magento\Customer\Api\GroupManagementInterface;
|
||||
use Magento\Customer\Api\GroupRepositoryInterface;
|
||||
use Magento\Customer\Controller\RegistryConstants;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\TestCase\AbstractController;
|
||||
|
||||
/**
|
||||
* Magento\Customer\Block\Adminhtml\Group\Edit
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class EditTest extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\View\LayoutInterface
|
||||
*/
|
||||
private $layout;
|
||||
|
||||
/**
|
||||
* @var GroupRepositoryInterface
|
||||
*/
|
||||
private $groupRepository;
|
||||
|
||||
/**
|
||||
* @var GroupManagementInterface
|
||||
*/
|
||||
private $groupManagement;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Registry
|
||||
*/
|
||||
private $registry;
|
||||
|
||||
/**
|
||||
* Execute per test initialization.
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->layout = Bootstrap::getObjectManager()->get(\Magento\Framework\View\LayoutInterface::class);
|
||||
$this->groupRepository = Bootstrap::getObjectManager()->create(
|
||||
\Magento\Customer\Api\GroupRepositoryInterface::class
|
||||
);
|
||||
$this->groupManagement = Bootstrap::getObjectManager()->create(
|
||||
\Magento\Customer\Api\GroupManagementInterface::class
|
||||
);
|
||||
$this->registry = Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute per test cleanup.
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->registry->unregister(RegistryConstants::CURRENT_GROUP_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that the Delete button does not exist for the default group.
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testDeleteButtonNotExistInDefaultGroup()
|
||||
{
|
||||
$groupId = $this->groupManagement->getDefaultGroup(0)->getId();
|
||||
$this->registry->register(RegistryConstants::CURRENT_GROUP_ID, $groupId);
|
||||
$this->getRequest()->setParam('id', $groupId);
|
||||
|
||||
/** @var $block Edit */
|
||||
$block = $this->layout->createBlock(\Magento\Customer\Block\Adminhtml\Group\Edit::class, 'block');
|
||||
$buttonsHtml = $block->getButtonsHtml();
|
||||
|
||||
$this->assertStringNotContainsString('delete', $buttonsHtml);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_group.php
|
||||
*/
|
||||
public function testDeleteButtonExistInCustomGroup()
|
||||
{
|
||||
$builder = Bootstrap::getObjectManager()->create(\Magento\Framework\Api\FilterBuilder::class);
|
||||
/** @var \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteria */
|
||||
$searchCriteria = Bootstrap::getObjectManager()
|
||||
->create(\Magento\Framework\Api\SearchCriteriaBuilder::class)
|
||||
->addFilters([$builder->setField('code')->setValue('custom_group')->create()])->create();
|
||||
$customerGroup = $this->groupRepository->getList($searchCriteria)->getItems()[0];
|
||||
$this->getRequest()->setParam('id', $customerGroup->getId());
|
||||
$this->registry->register(RegistryConstants::CURRENT_GROUP_ID, $customerGroup->getId());
|
||||
|
||||
/** @var $block Edit */
|
||||
$block = $this->layout->createBlock(\Magento\Customer\Block\Adminhtml\Group\Edit::class, 'block');
|
||||
$buttonsHtml = $block->getButtonsHtml();
|
||||
|
||||
$this->assertStringContainsString('delete', $buttonsHtml);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Customer\Block\Form;
|
||||
|
||||
use Magento\Customer\Model\Session;
|
||||
use Magento\Framework\View\LayoutInterface;
|
||||
use Magento\Framework\View\Element\ButtonLockManager;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Helper\Xpath;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @magentoAppArea frontend
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
*/
|
||||
class EditTest extends TestCase
|
||||
{
|
||||
private const SAVE_BUTTON_XPATH = '//*[@id="form-validate"]//*[@type="submit"]';
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var LayoutInterface
|
||||
*/
|
||||
private $layout;
|
||||
|
||||
/**
|
||||
* @var Edit
|
||||
*/
|
||||
private $block;
|
||||
|
||||
/** @var Session */
|
||||
private $customerSession;
|
||||
|
||||
/**
|
||||
* @inheirtDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->layout = $this->objectManager->get(LayoutInterface::class);
|
||||
$this->customerSession = $this->objectManager->get(Session::class);
|
||||
$this->block = $this->layout->createBlock(Edit::class);
|
||||
$this->block->setTemplate('Magento_Customer::form/edit.phtml');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testCustomerEditButton(): void
|
||||
{
|
||||
$code = 'customer_edit';
|
||||
$buttonLock = $this->getMockBuilder(\Magento\ReCaptchaUi\Model\ButtonLock::class)
|
||||
->disableOriginalConstructor()
|
||||
->disableAutoload()
|
||||
->setMethods(['isDisabled', 'getCode'])
|
||||
->getMock();
|
||||
$buttonLock->expects($this->atLeastOnce())->method('getCode')->willReturn($code);
|
||||
$buttonLock->expects($this->atLeastOnce())->method('isDisabled')->willReturn(false);
|
||||
$buttonLockManager = $this->objectManager->create(
|
||||
ButtonLockManager::class,
|
||||
['buttonLockPool' => ['customer_edit_form_submit' => $buttonLock]]
|
||||
);
|
||||
$this->block->setButtonLockManager($buttonLockManager);
|
||||
|
||||
$this->customerSession->loginById(1);
|
||||
$result = $this->block->toHtml();
|
||||
$this->assertFalse($buttonLockManager->isDisabled($code));
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(self::SAVE_BUTTON_XPATH, $result),
|
||||
'Customer Edit Button wasn\'t found in the page'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Customer\Block\Form;
|
||||
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\View\LayoutInterface;
|
||||
use Magento\Framework\View\Element\ButtonLockManager;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Helper\Xpath;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Class checks login form view
|
||||
*
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class LoginTest extends TestCase
|
||||
{
|
||||
private const EMAIL_LABEL_XPATH = "//label[@for='email']/span[contains(text(), 'Email')]";
|
||||
private const PASSWORD_LABEL_XPATH = "//label[@for='pass' ]/span[contains(text(), 'Password')]";
|
||||
private const EMAIL_INPUT_XPATH = "//input[@name ='login[username]' and contains(@data-validate,'required:true')"
|
||||
. "and contains(@data-validate, \"'validate-email':true\")]";
|
||||
private const PASSWORD_INPUT_XPATH = "//input[@name='login[password]'"
|
||||
. "and contains(@data-validate,'required:true')]";
|
||||
private const SIGN_IN_BUTTON_XPATH = "//button[@type='submit']/span[contains(text(), 'Sign In')]";
|
||||
private const FORGOT_PASSWORD_LINK_PATH = "//a[contains(@href, 'customer/account/forgotpassword')]"
|
||||
. "/span[contains(text(), 'Forgot Your Password?')] ";
|
||||
|
||||
/** @var ObjectManagerInterface */
|
||||
private $objectManager;
|
||||
|
||||
/** @var LayoutInterface */
|
||||
private $layout;
|
||||
|
||||
/** @var Login */
|
||||
private $block;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->layout = $this->objectManager->get(LayoutInterface::class);
|
||||
|
||||
$code = 'customer_login_form_submit';
|
||||
$buttonLock = $this->getMockBuilder(\Magento\ReCaptchaUi\Model\ButtonLock::class)
|
||||
->disableOriginalConstructor()
|
||||
->disableAutoload()
|
||||
->setMethods(['isDisabled', 'getCode'])
|
||||
->getMock();
|
||||
$buttonLock->expects($this->any())->method('getCode')->willReturn($code);
|
||||
$buttonLock->expects($this->any())->method('isDisabled')->willReturn(false);
|
||||
$buttonLockManager = $this->objectManager->create(
|
||||
ButtonLockManager::class,
|
||||
['buttonLockPool' => [$code => $buttonLock]]
|
||||
);
|
||||
|
||||
$this->block = $this->layout->createBlock(Login::class);
|
||||
$this->block->setTemplate('Magento_Customer::form/login.phtml');
|
||||
$this->block->setButtonLockManager($buttonLockManager);
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testLoginForm(): void
|
||||
{
|
||||
$result = $this->block->toHtml();
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(self::EMAIL_LABEL_XPATH, $result),
|
||||
'Email label does not exist on the page'
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(self::PASSWORD_LABEL_XPATH, $result),
|
||||
'Password label does not exist on the page'
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(self::EMAIL_INPUT_XPATH, $result),
|
||||
'Email input does not exist on the page'
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(self::PASSWORD_INPUT_XPATH, $result),
|
||||
'Password input does not exist on the page'
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(self::SIGN_IN_BUTTON_XPATH, $result),
|
||||
'Sign in button does not exist on the page'
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(self::FORGOT_PASSWORD_LINK_PATH, $result),
|
||||
'Forgot password link does not exist 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());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Customer\Block\Form;
|
||||
|
||||
use Magento\Customer\Block\DataProviders\AddressAttributeData;
|
||||
use Magento\Customer\ViewModel\Address\RegionProvider;
|
||||
use Magento\Framework\View\Element\Template;
|
||||
use Magento\Framework\View\Element\ButtonLockManager;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Test class for \Magento\Customer\Block\Form\Register
|
||||
*
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class RegisterTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
* @return void
|
||||
*/
|
||||
public function testCompanyDefault(): void
|
||||
{
|
||||
/** @var \Magento\Customer\Block\Widget\Company $block */
|
||||
$block = Bootstrap::getObjectManager()->create(Register::class)
|
||||
->setTemplate('Magento_Customer::form/register.phtml')
|
||||
->setShowAddressFields(true);
|
||||
$this->setAttributeDataProvider($block);
|
||||
$this->setRegionProvider($block);
|
||||
$this->setButtonLockManager($block);
|
||||
|
||||
$this->assertStringContainsString('title="Company"', $block->toHtml());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
* @return void
|
||||
*/
|
||||
public function testTelephoneDefault(): void
|
||||
{
|
||||
/** @var \Magento\Customer\Block\Widget\Company $block */
|
||||
$block = Bootstrap::getObjectManager()->create(Register::class)
|
||||
->setTemplate('Magento_Customer::form/register.phtml')
|
||||
->setShowAddressFields(true);
|
||||
$this->setAttributeDataProvider($block);
|
||||
$this->setRegionProvider($block);
|
||||
$this->setButtonLockManager($block);
|
||||
|
||||
$this->assertStringContainsString('title="Phone Number"', $block->toHtml());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
* @return void
|
||||
*/
|
||||
public function testFaxDefault(): void
|
||||
{
|
||||
/** @var \Magento\Customer\Block\Widget\Company $block */
|
||||
$block = Bootstrap::getObjectManager()->create(Register::class)
|
||||
->setTemplate('Magento_Customer::form/register.phtml')
|
||||
->setShowAddressFields(true);
|
||||
$this->setAttributeDataProvider($block);
|
||||
$this->setRegionProvider($block);
|
||||
$this->setButtonLockManager($block);
|
||||
|
||||
$this->assertStringNotContainsString('title="Fax"', $block->toHtml());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
* @return void
|
||||
*/
|
||||
public function testCompanyDisabled(): void
|
||||
{
|
||||
/** @var \Magento\Customer\Model\Attribute $model */
|
||||
$model = Bootstrap::getObjectManager()->create(
|
||||
\Magento\Customer\Model\Attribute::class
|
||||
);
|
||||
$model->loadByCode('customer_address', 'company')->setIsVisible('0');
|
||||
$model->save();
|
||||
|
||||
/** @var \Magento\Customer\Block\Widget\Company $block */
|
||||
$block = Bootstrap::getObjectManager()->create(Register::class)
|
||||
->setTemplate('Magento_Customer::form/register.phtml')
|
||||
->setShowAddressFields(true);
|
||||
$this->setAttributeDataProvider($block);
|
||||
$this->setRegionProvider($block);
|
||||
$this->setButtonLockManager($block);
|
||||
|
||||
$this->assertStringNotContainsString('title="Company"', $block->toHtml());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
* @return void
|
||||
*/
|
||||
public function testTelephoneDisabled(): void
|
||||
{
|
||||
/** @var \Magento\Customer\Model\Attribute $model */
|
||||
$model = Bootstrap::getObjectManager()->create(
|
||||
\Magento\Customer\Model\Attribute::class
|
||||
);
|
||||
$model->loadByCode('customer_address', 'telephone')->setIsVisible('0');
|
||||
$model->save();
|
||||
|
||||
/** @var \Magento\Customer\Block\Widget\Company $block */
|
||||
$block = Bootstrap::getObjectManager()->create(Register::class)
|
||||
->setTemplate('Magento_Customer::form/register.phtml')
|
||||
->setShowAddressFields(true);
|
||||
$this->setAttributeDataProvider($block);
|
||||
$this->setRegionProvider($block);
|
||||
$this->setButtonLockManager($block);
|
||||
|
||||
$this->assertStringNotContainsString('title="Phone Number"', $block->toHtml());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
* @return void
|
||||
*/
|
||||
public function testFaxEnabled(): void
|
||||
{
|
||||
/** @var \Magento\Customer\Model\Attribute $model */
|
||||
$model = Bootstrap::getObjectManager()->create(
|
||||
\Magento\Customer\Model\Attribute::class
|
||||
);
|
||||
$model->loadByCode('customer_address', 'fax')->setIsVisible('1');
|
||||
$model->save();
|
||||
|
||||
/** @var \Magento\Customer\Block\Widget\Company $block */
|
||||
$block = Bootstrap::getObjectManager()->create(Register::class)
|
||||
->setTemplate('Magento_Customer::form/register.phtml')
|
||||
->setShowAddressFields(true);
|
||||
$this->setAttributeDataProvider($block);
|
||||
$this->setRegionProvider($block);
|
||||
$this->setButtonLockManager($block);
|
||||
|
||||
$this->assertStringContainsString('title="Fax"', $block->toHtml());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/attribute_city_store_label_address.php
|
||||
*/
|
||||
public function testCityWithStoreLabel(): void
|
||||
{
|
||||
/** @var \Magento\Customer\Block\Form\Register $block */
|
||||
$block = Bootstrap::getObjectManager()->create(Register::class)
|
||||
->setTemplate('Magento_Customer::form/register.phtml')
|
||||
->setShowAddressFields(true);
|
||||
$this->setAttributeDataProvider($block);
|
||||
$this->setRegionProvider($block);
|
||||
$this->setButtonLockManager($block);
|
||||
|
||||
$this->assertStringNotContainsString('title="City"', $block->toHtml());
|
||||
$this->assertStringContainsString('title="Suburb"', $block->toHtml());
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
/** @var \Magento\Eav\Model\Config $eavConfig */
|
||||
$eavConfig = Bootstrap::getObjectManager()->get(\Magento\Eav\Model\Config::class);
|
||||
$eavConfig->clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set attribute data provider.
|
||||
*
|
||||
* @param Template $block
|
||||
* @return void
|
||||
*/
|
||||
private function setAttributeDataProvider(Template $block): void
|
||||
{
|
||||
$attributeData = Bootstrap::getObjectManager()->get(AddressAttributeData::class);
|
||||
$block->setAttributeData($attributeData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Region Provider View Model.
|
||||
*
|
||||
* @param Template $block
|
||||
* @return void
|
||||
*/
|
||||
private function setRegionProvider(Template $block): void
|
||||
{
|
||||
$regionProvider = Bootstrap::getObjectManager()->create(RegionProvider::class);
|
||||
$block->setRegionProvider($regionProvider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Button Lock Manager View Model
|
||||
*
|
||||
* @param Template $block
|
||||
* @return void
|
||||
*/
|
||||
private function setButtonLockManager(Template $block): void
|
||||
{
|
||||
$code = 'customer_create_form_submit';
|
||||
$buttonLock = $this->getMockBuilder(\Magento\ReCaptchaUi\Model\ButtonLock::class)
|
||||
->disableOriginalConstructor()
|
||||
->disableAutoload()
|
||||
->setMethods(['isDisabled', 'getCode'])
|
||||
->getMock();
|
||||
$buttonLock->expects($this->any())->method('getCode')->willReturn($code);
|
||||
$buttonLock->expects($this->any())->method('isDisabled')->willReturn(false);
|
||||
$buttonLockManager = Bootstrap::getObjectManager()->create(
|
||||
ButtonLockManager::class,
|
||||
['buttonLockPool' => [$code => $buttonLock]]
|
||||
);
|
||||
$block->setButtonLockManager($buttonLockManager);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Customer\Block;
|
||||
|
||||
use Magento\Customer\Model\Session;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\View\LayoutInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Helper\Xpath;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Class check newsletter subscription block behavior
|
||||
*
|
||||
* @see \Magento\Customer\Block\Newsletter
|
||||
* @magentoAppArea frontend
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
*/
|
||||
class NewsletterTest extends TestCase
|
||||
{
|
||||
private const LABEL_XPATH = "//form[contains(@class, 'form-newsletter-manage')]"
|
||||
. "//span[contains(text(), 'Subscription option')]";
|
||||
private const CHECKBOX_XPATH = "//form[contains(@class, 'form-newsletter-manage')]"
|
||||
. "//input[@type='checkbox' and @name='is_subscribed']";
|
||||
private const CHECKBOX_TITLE_XPATH = "//form[contains(@class, 'form-newsletter-manage')]"
|
||||
. "//label/span[contains(text(), 'General Subscription')]";
|
||||
private const SAVE_BUTTON_XPATH = "//form[contains(@class, 'form-newsletter-manage')]"
|
||||
. "//button[@type='submit']/span[contains(text(), 'Save')]";
|
||||
|
||||
/** @var ObjectManagerInterface */
|
||||
private $objectManager;
|
||||
|
||||
/** @var LayoutInterface */
|
||||
private $layout;
|
||||
|
||||
/** @var Newsletter */
|
||||
private $block;
|
||||
|
||||
/** @var Session */
|
||||
private $customerSession;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->layout = $this->objectManager->get(LayoutInterface::class);
|
||||
$this->block = $this->layout->createBlock(Newsletter::class);
|
||||
$this->customerSession = $this->objectManager->get(Session::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testSubscriptionCheckbox(): void
|
||||
{
|
||||
$this->customerSession->loginById(1);
|
||||
$html = $this->block->toHtml();
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(self::LABEL_XPATH, $html),
|
||||
'Subscription label is not present on the page'
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(self::CHECKBOX_XPATH, $html),
|
||||
'Subscription checkbox is not present on the page'
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(self::CHECKBOX_TITLE_XPATH, $html),
|
||||
'Subscription checkbox label is not present on the page'
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(self::SAVE_BUTTON_XPATH, $html),
|
||||
'Subscription save button is not present on the page'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Customer\Block\Widget;
|
||||
|
||||
/**
|
||||
* Test class for \Magento\Customer\Block\Widget\Taxvat
|
||||
*
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class CompanyTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testToHtml()
|
||||
{
|
||||
/** @var \Magento\Customer\Block\Widget\Company $block */
|
||||
$block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Customer\Block\Widget\Company::class
|
||||
);
|
||||
|
||||
$this->assertStringContainsString('title="Company"', $block->toHtml());
|
||||
$this->assertStringNotContainsString('required', $block->toHtml());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testToHtmlRequired()
|
||||
{
|
||||
/** @var \Magento\Customer\Model\Attribute $model */
|
||||
$model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Customer\Model\Attribute::class
|
||||
);
|
||||
$model->loadByCode('customer_address', 'company')->setIsRequired(true);
|
||||
$model->save();
|
||||
|
||||
/** @var \Magento\Customer\Block\Widget\Company $block */
|
||||
$block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Customer\Block\Widget\Company::class
|
||||
);
|
||||
|
||||
$this->assertStringContainsString('title="Company"', $block->toHtml());
|
||||
$this->assertStringContainsString('required', $block->toHtml());
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
/** @var \Magento\Eav\Model\Config $eavConfig */
|
||||
$eavConfig = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Eav\Model\Config::class);
|
||||
$eavConfig->clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test class for \Magento\Customer\Block\Widget\Dob
|
||||
*/
|
||||
namespace Magento\Customer\Block\Widget;
|
||||
|
||||
class DobTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testGetDateFormat()
|
||||
{
|
||||
$block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Customer\Block\Widget\Dob::class
|
||||
);
|
||||
$this->assertNotEmpty($block->getDateFormat());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Customer\Block\Widget;
|
||||
|
||||
/**
|
||||
* Test class for \Magento\Customer\Block\Widget\Taxvat
|
||||
*
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class FaxTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testToHtml()
|
||||
{
|
||||
/** @var \Magento\Customer\Block\Widget\Fax $block */
|
||||
$block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Customer\Block\Widget\Fax::class
|
||||
);
|
||||
|
||||
$this->assertStringContainsString('title="Fax"', $block->toHtml());
|
||||
$this->assertStringNotContainsString('required', $block->toHtml());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testToHtmlRequired()
|
||||
{
|
||||
/** @var \Magento\Customer\Model\Attribute $model */
|
||||
$model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Customer\Model\Attribute::class
|
||||
);
|
||||
$model->loadByCode('customer_address', 'fax')->setIsRequired(true);
|
||||
$model->save();
|
||||
|
||||
/** @var \Magento\Customer\Block\Widget\Fax $block */
|
||||
$block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Customer\Block\Widget\Fax::class
|
||||
);
|
||||
|
||||
$this->assertStringContainsString('title="Fax"', $block->toHtml());
|
||||
$this->assertStringContainsString('required', $block->toHtml());
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
/** @var \Magento\Eav\Model\Config $eavConfig */
|
||||
$eavConfig = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Eav\Model\Config::class);
|
||||
$eavConfig->clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Customer\Block\Widget;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class GenderTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/** @var Gender */
|
||||
protected $_block;
|
||||
|
||||
/** @var \Magento\Customer\Model\Attribute */
|
||||
private $_model;
|
||||
|
||||
/**
|
||||
* Test initialization and set up. Create the Gender block.
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$objectManager->get(\Magento\Framework\App\State::class)->setAreaCode('frontend');
|
||||
$this->_block = $objectManager->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
)->createBlock(
|
||||
\Magento\Customer\Block\Widget\Gender::class
|
||||
);
|
||||
$this->_model = $objectManager->create(\Magento\Customer\Model\Attribute::class);
|
||||
$this->_model->loadByCode('customer', 'gender');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the Gender::getGenderOptions() method.
|
||||
* @return void
|
||||
*/
|
||||
public function testGetGenderOptions()
|
||||
{
|
||||
$options = $this->_block->getGenderOptions();
|
||||
$this->assertIsArray($options);
|
||||
$this->assertNotEmpty($options);
|
||||
$this->assertContainsOnlyInstancesOf(\Magento\Customer\Model\Data\Option::class, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the Gender::toHtml() method.
|
||||
* @return void
|
||||
*/
|
||||
public function testToHtml()
|
||||
{
|
||||
$html = $this->_block->toHtml();
|
||||
$attributeLabel = $this->_model->getStoreLabel();
|
||||
$this->assertStringContainsString('<span>' . $attributeLabel . '</span>', $html);
|
||||
$this->assertStringContainsString('<option value="1">Male</option>', $html);
|
||||
$this->assertStringContainsString('<option value="2">Female</option>', $html);
|
||||
$this->assertStringContainsString('<option value="3">Not Specified</option>', $html);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Customer\Block\Widget;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Test \Magento\Customer\Block\Widget\Name
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class NameTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/** @var Name */
|
||||
protected $_block;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$objectManager->get(\Magento\Framework\App\State::class)->setAreaCode('frontend');
|
||||
$this->_block = $objectManager->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
)->createBlock(
|
||||
\Magento\Customer\Block\Widget\Name::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testToHtmlSimpleName()
|
||||
{
|
||||
/** @var \Magento\Customer\Api\Data\CustomerInterfaceFactory $customerFactory */
|
||||
$customerFactory = Bootstrap::getObjectManager()->get(
|
||||
\Magento\Customer\Api\Data\CustomerInterfaceFactory::class
|
||||
);
|
||||
$customerDataObject = $customerFactory->create();
|
||||
$customerDataObject->setFirstname('Jane');
|
||||
$customerDataObject->setLastname('Doe');
|
||||
$this->_block->setObject($customerDataObject);
|
||||
|
||||
$html = $this->_block->toHtml();
|
||||
|
||||
$this->assertStringContainsString('title="First Name"', $html);
|
||||
$this->assertStringContainsString('value="Jane"', $html);
|
||||
$this->assertStringContainsString('title="Last Name"', $html);
|
||||
$this->assertStringContainsString('value="Doe"', $html);
|
||||
$this->assertStringNotContainsString('title="Middle Name/Initial"', $html);
|
||||
$this->assertStringNotContainsString('title="Name Prefix"', $html);
|
||||
$this->assertStringNotContainsString('title="Name Suffix"', $html);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDataFixture Magento/Customer/_files/attribute_user_fullname.php
|
||||
*/
|
||||
public function testToHtmlFancyName()
|
||||
{
|
||||
/** @var \Magento\Customer\Api\Data\CustomerInterfaceFactory $customerFactory */
|
||||
$customerFactory = Bootstrap::getObjectManager()->get(
|
||||
\Magento\Customer\Api\Data\CustomerInterfaceFactory::class
|
||||
);
|
||||
$customerDataObject = $customerFactory->create();
|
||||
$customerDataObject->setPrefix(
|
||||
'Dr.'
|
||||
)->setFirstname(
|
||||
'Jane'
|
||||
)->setMiddlename(
|
||||
'Roe'
|
||||
)->setLastname(
|
||||
'Doe'
|
||||
)->setSuffix(
|
||||
'Ph.D.'
|
||||
);
|
||||
$this->_block->setObject($customerDataObject);
|
||||
|
||||
$html = $this->_block->toHtml();
|
||||
|
||||
$this->assertStringContainsString('title="First Name"', $html);
|
||||
$this->assertStringContainsString('value="Jane"', $html);
|
||||
$this->assertStringContainsString('title="Last Name"', $html);
|
||||
$this->assertStringContainsString('value="Doe"', $html);
|
||||
$this->assertStringContainsString('title="Middle Name/Initial"', $html);
|
||||
$this->assertStringContainsString('value="Roe"', $html);
|
||||
$this->assertStringContainsString('title="Name Prefix"', $html);
|
||||
$this->assertStringContainsString('value="Dr."', $html);
|
||||
$this->assertStringContainsString('title="Name Suffix"', $html);
|
||||
$this->assertStringContainsString('value="Ph.D."', $html);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Customer\Block\Widget;
|
||||
|
||||
/**
|
||||
* Test class for \Magento\Customer\Block\Widget\Taxvat
|
||||
*
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class TaxvatTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testToHtml()
|
||||
{
|
||||
/** @var \Magento\Customer\Block\Widget\Taxvat $block */
|
||||
$block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Customer\Block\Widget\Taxvat::class
|
||||
);
|
||||
|
||||
$model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Customer\Model\Attribute::class
|
||||
);
|
||||
$model->loadByCode('customer', 'taxvat');
|
||||
$attributeLabel = $model->getStoreLabel();
|
||||
|
||||
$this->assertStringContainsString('title="' . $block->escapeHtmlAttr($attributeLabel) . '"', $block->toHtml());
|
||||
$this->assertStringNotContainsString('required', $block->toHtml());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testToHtmlRequired()
|
||||
{
|
||||
/** @var \Magento\Customer\Model\Attribute $model */
|
||||
$model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Customer\Model\Attribute::class
|
||||
);
|
||||
$model->loadByCode('customer', 'taxvat')->setIsRequired(true);
|
||||
$model->save();
|
||||
$attributeLabel = $model->getStoreLabel();
|
||||
|
||||
/** @var \Magento\Customer\Block\Widget\Taxvat $block */
|
||||
$block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Customer\Block\Widget\Taxvat::class
|
||||
);
|
||||
|
||||
$this->assertStringContainsString('title="' . $block->escapeHtmlAttr($attributeLabel) . '"', $block->toHtml());
|
||||
$this->assertStringContainsString('required', $block->toHtml());
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
/** @var \Magento\Eav\Model\Config $eavConfig */
|
||||
$eavConfig = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Eav\Model\Config::class);
|
||||
$eavConfig->clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Customer\Block\Widget;
|
||||
|
||||
/**
|
||||
* Test class for \Magento\Customer\Block\Widget\Taxvat
|
||||
*
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class TelephoneTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testToHtml()
|
||||
{
|
||||
/** @var \Magento\Customer\Block\Widget\Telephone $block */
|
||||
$block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Customer\Block\Widget\Telephone::class
|
||||
);
|
||||
|
||||
$this->assertStringContainsString('title="Phone Number"', $block->toHtml());
|
||||
$this->assertStringContainsString('required', $block->toHtml());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testToHtmlRequired()
|
||||
{
|
||||
/** @var \Magento\Customer\Model\Attribute $model */
|
||||
$model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Customer\Model\Attribute::class
|
||||
);
|
||||
$model->loadByCode('customer_address', 'telephone')->setIsRequired(false);
|
||||
$model->save();
|
||||
|
||||
/** @var \Magento\Customer\Block\Widget\Telephone $block */
|
||||
$block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Customer\Block\Widget\Telephone::class
|
||||
);
|
||||
|
||||
$this->assertStringContainsString('title="Phone Number"', $block->toHtml());
|
||||
$this->assertStringNotContainsString('required', $block->toHtml());
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
/** @var \Magento\Eav\Model\Config $eavConfig */
|
||||
$eavConfig = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Eav\Model\Config::class);
|
||||
$eavConfig->clear();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user