EditTest.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Block\Address;
  7. /**
  8. * Tests Address Edit Block
  9. */
  10. class EditTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /** @var Edit */
  13. protected $_block;
  14. /** @var \Magento\Customer\Model\Session */
  15. protected $_customerSession;
  16. /** @var \Magento\Backend\Block\Template\Context */
  17. protected $_context;
  18. /** @var string */
  19. protected $_requestId;
  20. protected function setUp()
  21. {
  22. $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
  23. $this->_customerSession = $objectManager->get(\Magento\Customer\Model\Session::class);
  24. $this->_customerSession->setCustomerId(1);
  25. $this->_context = $objectManager->get(\Magento\Backend\Block\Template\Context::class);
  26. $this->_requestId = $this->_context->getRequest()->getParam('id');
  27. $this->_context->getRequest()->setParam('id', '1');
  28. $objectManager->get(\Magento\Framework\App\State::class)->setAreaCode('frontend');
  29. /** @var $layout \Magento\Framework\View\Layout */
  30. $layout = $objectManager->get(\Magento\Framework\View\LayoutInterface::class);
  31. $currentCustomer = $objectManager->create(
  32. \Magento\Customer\Helper\Session\CurrentCustomer::class,
  33. ['customerSession' => $this->_customerSession]
  34. );
  35. $this->_block = $layout->createBlock(
  36. \Magento\Customer\Block\Address\Edit::class,
  37. '',
  38. ['customerSession' => $this->_customerSession, 'currentCustomer' => $currentCustomer]
  39. );
  40. }
  41. protected function tearDown()
  42. {
  43. $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
  44. $this->_customerSession->setCustomerId(null);
  45. $this->_context->getRequest()->setParam('id', $this->_requestId);
  46. /** @var \Magento\Customer\Model\AddressRegistry $addressRegistry */
  47. $addressRegistry = $objectManager->get(\Magento\Customer\Model\AddressRegistry::class);
  48. //Cleanup address from registry
  49. $addressRegistry->remove(1);
  50. $addressRegistry->remove(2);
  51. /** @var \Magento\Customer\Model\CustomerRegistry $customerRegistry */
  52. $customerRegistry = $objectManager->get(\Magento\Customer\Model\CustomerRegistry::class);
  53. //Cleanup customer from registry
  54. $customerRegistry->remove(1);
  55. }
  56. /**
  57. * @magentoDataFixture Magento/Customer/_files/customer.php
  58. */
  59. public function testGetSaveUrl()
  60. {
  61. $this->assertEquals('http://localhost/index.php/customer/address/formPost/', $this->_block->getSaveUrl());
  62. }
  63. /**
  64. * @magentoDataFixture Magento/Customer/_files/customer.php
  65. * @magentoDataFixture Magento/Customer/_files/customer_address.php
  66. */
  67. public function testGetRegionId()
  68. {
  69. $this->assertEquals(1, $this->_block->getRegionId());
  70. }
  71. /**
  72. * @magentoDataFixture Magento/Customer/_files/customer.php
  73. * @magentoDataFixture Magento/Customer/_files/customer_address.php
  74. */
  75. public function testGetCountryId()
  76. {
  77. $this->assertEquals('US', $this->_block->getCountryId());
  78. }
  79. /**
  80. * @magentoDataFixture Magento/Customer/_files/customer.php
  81. * @magentoDataFixture Magento/Customer/_files/customer_two_addresses.php
  82. */
  83. public function testGetCustomerAddressCount()
  84. {
  85. $this->assertEquals(2, $this->_block->getCustomerAddressCount());
  86. }
  87. /**
  88. * @magentoDataFixture Magento/Customer/_files/customer.php
  89. */
  90. public function testCanSetAsDefaultShipping()
  91. {
  92. $this->assertEquals(0, $this->_block->canSetAsDefaultShipping());
  93. }
  94. /**
  95. * @magentoDataFixture Magento/Customer/_files/customer.php
  96. */
  97. public function testIsDefaultBilling()
  98. {
  99. $this->assertFalse($this->_block->isDefaultBilling());
  100. }
  101. /**
  102. * @magentoDataFixture Magento/Customer/_files/customer.php
  103. * @magentoDataFixture Magento/Customer/_files/customer_address.php
  104. */
  105. public function testGetStreetLine()
  106. {
  107. $this->assertEquals('Green str, 67', $this->_block->getStreetLine(1));
  108. $this->assertEquals('', $this->_block->getStreetLine(2));
  109. }
  110. }