ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -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"
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user