123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- <?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()
- {
- /** @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()
- {
- $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));
- }
- }
|