CurrentCustomerAddressTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Test\Unit\Helper\Session;
  7. class CurrentCustomerAddressTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\Customer\Helper\Session\CurrentCustomerAddress
  11. */
  12. protected $currentCustomerAddress;
  13. /**
  14. * @var \Magento\Customer\Helper\Session\CurrentCustomer|\PHPUnit_Framework_MockObject_MockObject
  15. */
  16. protected $currentCustomerMock;
  17. /**
  18. * @var \Magento\Customer\Api\AccountManagementInterface|\PHPUnit_Framework_MockObject_MockObject
  19. */
  20. protected $customerAccountManagementMock;
  21. /**
  22. * @var \Magento\Customer\Api\Data\AddressInterface
  23. */
  24. protected $customerAddressDataMock;
  25. /**
  26. * @var int
  27. */
  28. protected $customerCurrentId = 100;
  29. /**
  30. * Test setup
  31. */
  32. protected function setUp()
  33. {
  34. $this->currentCustomerMock = $this->getMockBuilder(\Magento\Customer\Helper\Session\CurrentCustomer::class)
  35. ->disableOriginalConstructor()
  36. ->getMock();
  37. $this->customerAccountManagementMock = $this->getMockBuilder(
  38. \Magento\Customer\Api\AccountManagementInterface::class
  39. )->disableOriginalConstructor()->getMock();
  40. $this->currentCustomerAddress = new \Magento\Customer\Helper\Session\CurrentCustomerAddress(
  41. $this->currentCustomerMock,
  42. $this->customerAccountManagementMock
  43. );
  44. }
  45. /**
  46. * test getDefaultBillingAddress
  47. */
  48. public function testGetDefaultBillingAddress()
  49. {
  50. $this->currentCustomerMock->expects($this->once())
  51. ->method('getCustomerId')
  52. ->will($this->returnValue($this->customerCurrentId));
  53. $this->customerAccountManagementMock->expects($this->once())
  54. ->method('getDefaultBillingAddress')
  55. ->will($this->returnValue($this->customerAddressDataMock));
  56. $this->assertEquals(
  57. $this->customerAddressDataMock,
  58. $this->currentCustomerAddress->getDefaultBillingAddress()
  59. );
  60. }
  61. /**
  62. * test getDefaultShippingAddress
  63. */
  64. public function testGetDefaultShippingAddress()
  65. {
  66. $this->currentCustomerMock->expects($this->once())
  67. ->method('getCustomerId')
  68. ->will($this->returnValue($this->customerCurrentId));
  69. $this->customerAccountManagementMock->expects($this->once())
  70. ->method('getDefaultShippingAddress')
  71. ->will($this->returnValue($this->customerAddressDataMock));
  72. $this->assertEquals(
  73. $this->customerAddressDataMock,
  74. $this->currentCustomerAddress->getDefaultShippingAddress()
  75. );
  76. }
  77. }