CheckoutTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Test class for \Magento\Paypal\Helper\Checkout
  8. */
  9. namespace Magento\Paypal\Test\Unit\Helper;
  10. use Magento\Checkout\Model\Session;
  11. use Magento\Paypal\Helper\Checkout;
  12. use Magento\Sales\Model\Order;
  13. class CheckoutTest extends \PHPUnit\Framework\TestCase
  14. {
  15. /**
  16. * @var Session|\PHPUnit_Framework_MockObject_MockObject
  17. */
  18. private $session;
  19. /**
  20. * @var Checkout
  21. */
  22. private $checkout;
  23. protected function setUp()
  24. {
  25. $this->session = $this->getMockBuilder(Session::class)
  26. ->disableOriginalConstructor()
  27. ->getMock();
  28. $this->checkout = new Checkout($this->session);
  29. }
  30. public function testCancelCurrentOrder()
  31. {
  32. $id = 1;
  33. $state = Order::STATE_PENDING_PAYMENT;
  34. $comment = 'Bla Bla';
  35. $order = $this->getMockBuilder(Order::class)
  36. ->disableOriginalConstructor()
  37. ->getMock();
  38. $this->session->expects(static::once())
  39. ->method('getLastRealOrder')
  40. ->willReturn($order);
  41. $order->expects(static::once())
  42. ->method('getId')
  43. ->willReturn($id);
  44. $order->expects(static::once())
  45. ->method('getState')
  46. ->willReturn($state);
  47. $order->expects(static::once())
  48. ->method('registerCancellation')
  49. ->with($comment)
  50. ->willReturnSelf();
  51. $order->expects(static::once())
  52. ->method('save');
  53. static::assertTrue($this->checkout->cancelCurrentOrder($comment));
  54. }
  55. public function testCancelCurrentOrderWhichIsCancelled()
  56. {
  57. $id = 1;
  58. $state = Order::STATE_CANCELED;
  59. $comment = 'Bla Bla';
  60. $order = $this->getMockBuilder(Order::class)
  61. ->disableOriginalConstructor()
  62. ->getMock();
  63. $this->session->expects(static::once())
  64. ->method('getLastRealOrder')
  65. ->willReturn($order);
  66. $order->expects(static::once())
  67. ->method('getId')
  68. ->willReturn($id);
  69. $order->expects(static::once())
  70. ->method('getState')
  71. ->willReturn($state);
  72. $order->expects(static::never())
  73. ->method('registerCancellation')
  74. ->with($comment)
  75. ->willReturnSelf();
  76. $order->expects(static::never())
  77. ->method('save');
  78. static::assertFalse($this->checkout->cancelCurrentOrder($comment));
  79. }
  80. public function testRestoreQuote()
  81. {
  82. $this->session->expects(static::once())
  83. ->method('restoreQuote')
  84. ->willReturn(true);
  85. static::assertTrue($this->checkout->restoreQuote());
  86. }
  87. }