AddressesTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Multishipping\Block\Checkout;
  7. use Magento\TestFramework\Helper\Bootstrap;
  8. /**
  9. * @magentoAppArea frontend
  10. */
  11. class AddressesTest extends \PHPUnit\Framework\TestCase
  12. {
  13. const FIXTURE_CUSTOMER_ID = 1;
  14. /**
  15. * @var \Magento\Multishipping\Block\Checkout\Addresses
  16. */
  17. protected $_addresses;
  18. /**
  19. * @var \Magento\Framework\ObjectManagerInterface
  20. */
  21. protected $_objectManager;
  22. protected function setUp()
  23. {
  24. $this->_objectManager = Bootstrap::getObjectManager();
  25. /** @var \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository */
  26. $customerRepository = Bootstrap::getObjectManager()->create(
  27. \Magento\Customer\Api\CustomerRepositoryInterface::class
  28. );
  29. $customerData = $customerRepository->getById(self::FIXTURE_CUSTOMER_ID);
  30. /** @var \Magento\Customer\Model\Session $customerSession */
  31. $customerSession = $this->_objectManager->get(\Magento\Customer\Model\Session::class);
  32. $customerSession->setCustomerData($customerData);
  33. /** @var \Magento\Quote\Model\ResourceModel\Quote\Collection $quoteCollection */
  34. $quoteCollection = $this->_objectManager->get(\Magento\Quote\Model\ResourceModel\Quote\Collection::class);
  35. /** @var $quote \Magento\Quote\Model\Quote */
  36. $quote = $quoteCollection->getLastItem();
  37. /** @var $checkoutSession \Magento\Checkout\Model\Session */
  38. $checkoutSession = $this->_objectManager->get(\Magento\Checkout\Model\Session::class);
  39. $checkoutSession->setQuoteId($quote->getId());
  40. $checkoutSession->setLoadInactive(true);
  41. $this->_addresses = $this->_objectManager->create(
  42. \Magento\Multishipping\Block\Checkout\Addresses::class
  43. );
  44. }
  45. /**
  46. * @magentoDataFixture Magento/Customer/_files/customer.php
  47. * @magentoDataFixture Magento/Customer/_files/customer_address.php
  48. * @magentoDataFixture Magento/Checkout/_files/quote_with_product_and_payment.php
  49. */
  50. public function testGetAddressOptions()
  51. {
  52. $expectedResult = [
  53. [
  54. 'value' => '1',
  55. 'label' => 'John Smith, Green str, 67, CityM, Alabama 75477, United States',
  56. ],
  57. ];
  58. $addressAsHtml = $this->_addresses->getAddressOptions();
  59. $this->assertEquals($expectedResult, $addressAsHtml);
  60. }
  61. }