TotalsTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Test\Unit\Block\Order\Create;
  7. /**
  8. * Class TotalsTest
  9. */
  10. class TotalsTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @var \PHPUnit_Framework_MockObject_MockObject
  14. */
  15. protected $shippingAddressMock;
  16. /**
  17. * @var \PHPUnit_Framework_MockObject_MockObject
  18. */
  19. protected $billingAddressMock;
  20. /**
  21. * @var \Magento\Sales\Block\Adminhtml\Order\Create\Totals
  22. */
  23. protected $totals;
  24. /**
  25. * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
  26. */
  27. protected $helperManager;
  28. /**
  29. * @var \Magento\Backend\Model\Session\Quote|\PHPUnit_Framework_MockObject_MockObject
  30. */
  31. protected $sessionQuoteMock;
  32. /**
  33. * @var \Magento\Quote\Model\Quote|\PHPUnit_Framework_MockObject_MockObject
  34. */
  35. protected $quoteMock;
  36. /**
  37. * Init
  38. */
  39. protected function setUp()
  40. {
  41. $this->helperManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  42. $this->sessionQuoteMock = $this->getMockBuilder(\Magento\Backend\Model\Session\Quote::class)
  43. ->disableOriginalConstructor()
  44. ->getMock();
  45. $this->quoteMock = $this->getMockBuilder(\Magento\Quote\Model\Quote::class)
  46. ->disableOriginalConstructor()
  47. ->setMethods([
  48. 'setTotalsCollectedFlag',
  49. 'collectTotals',
  50. 'getTotals',
  51. 'isVirtual',
  52. 'getBillingAddress',
  53. 'getShippingAddress'
  54. ])
  55. ->getMock();
  56. $this->shippingAddressMock = $this->getMockBuilder(\Magento\Quote\Model\Quote\Address::class)
  57. ->disableOriginalConstructor()
  58. ->getMock();
  59. $this->billingAddressMock = $this->getMockBuilder(\Magento\Quote\Model\Quote\Address::class)
  60. ->disableOriginalConstructor()
  61. ->getMock();
  62. $this->quoteMock->expects($this->any())
  63. ->method('getBillingAddress')
  64. ->willReturn($this->billingAddressMock);
  65. $this->quoteMock->expects($this->any())
  66. ->method('getShippingAddress')
  67. ->willReturn($this->shippingAddressMock);
  68. $this->sessionQuoteMock->expects($this->any())->method('getQuote')->willReturn($this->quoteMock);
  69. $this->totals = $this->helperManager->getObject(
  70. \Magento\Sales\Block\Adminhtml\Order\Create\Totals::class,
  71. ['sessionQuote' => $this->sessionQuoteMock]
  72. );
  73. }
  74. /**
  75. * @dataProvider totalsDataProvider
  76. */
  77. public function testGetTotals($isVirtual)
  78. {
  79. $expected = 'expected';
  80. $this->quoteMock->expects($this->at(1))->method('collectTotals');
  81. $this->quoteMock->expects($this->once())->method('isVirtual')->willReturn($isVirtual);
  82. if ($isVirtual) {
  83. $this->billingAddressMock->expects($this->once())->method('getTotals')->willReturn($expected);
  84. } else {
  85. $this->shippingAddressMock->expects($this->once())->method('getTotals')->willReturn($expected);
  86. }
  87. $this->assertEquals($expected, $this->totals->getTotals());
  88. }
  89. /**
  90. * @return array
  91. */
  92. public function totalsDataProvider()
  93. {
  94. return [
  95. [true],
  96. [false]
  97. ];
  98. }
  99. }