SuccessValidatorTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Checkout\Test\Unit\Model\Session;
  7. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
  8. class SuccessValidatorTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /** @var ObjectManagerHelper */
  11. protected $objectManagerHelper;
  12. protected function setUp()
  13. {
  14. $this->objectManagerHelper = new ObjectManagerHelper($this);
  15. }
  16. public function testIsValid()
  17. {
  18. $checkoutSession = $this->getMockBuilder(
  19. \Magento\Checkout\Model\Session::class
  20. )->disableOriginalConstructor()->getMock();
  21. $this->assertFalse($this->createSuccessValidator($checkoutSession)->isValid($checkoutSession));
  22. }
  23. public function testIsValidWithNotEmptyGetLastSuccessQuoteId()
  24. {
  25. $checkoutSession = $this->getMockBuilder(
  26. \Magento\Checkout\Model\Session::class
  27. )->disableOriginalConstructor()->getMock();
  28. $checkoutSession->expects(
  29. $this->at(0)
  30. )->method(
  31. '__call'
  32. )->with(
  33. 'getLastSuccessQuoteId'
  34. )->will(
  35. $this->returnValue(1)
  36. );
  37. $checkoutSession->expects($this->at(1))->method('__call')->with('getLastQuoteId')->will($this->returnValue(0));
  38. $this->assertFalse($this->createSuccessValidator($checkoutSession)->isValid($checkoutSession));
  39. }
  40. public function testIsValidWithEmptyQuoteAndOrder()
  41. {
  42. $checkoutSession = $this->getMockBuilder(
  43. \Magento\Checkout\Model\Session::class
  44. )->disableOriginalConstructor()->getMock();
  45. $checkoutSession->expects(
  46. $this->at(0)
  47. )->method(
  48. '__call'
  49. )->with(
  50. 'getLastSuccessQuoteId'
  51. )->will(
  52. $this->returnValue(1)
  53. );
  54. $checkoutSession->expects($this->at(1))->method('__call')->with('getLastQuoteId')->will($this->returnValue(1));
  55. $checkoutSession->expects($this->at(2))->method('__call')->with('getLastOrderId')->will($this->returnValue(0));
  56. $this->assertFalse($this->createSuccessValidator($checkoutSession)->isValid($checkoutSession));
  57. }
  58. public function testIsValidTrue()
  59. {
  60. $checkoutSession = $this->getMockBuilder(
  61. \Magento\Checkout\Model\Session::class
  62. )->disableOriginalConstructor()->getMock();
  63. $checkoutSession->expects(
  64. $this->at(0)
  65. )->method(
  66. '__call'
  67. )->with(
  68. 'getLastSuccessQuoteId'
  69. )->will(
  70. $this->returnValue(1)
  71. );
  72. $checkoutSession->expects($this->at(1))->method('__call')->with('getLastQuoteId')->will($this->returnValue(1));
  73. $checkoutSession->expects($this->at(2))->method('__call')->with('getLastOrderId')->will($this->returnValue(1));
  74. $this->assertTrue($this->createSuccessValidator($checkoutSession)->isValid($checkoutSession));
  75. }
  76. /**
  77. * @param \PHPUnit_Framework_MockObject_MockObject $checkoutSession
  78. * @return object
  79. */
  80. protected function createSuccessValidator(\PHPUnit_Framework_MockObject_MockObject $checkoutSession)
  81. {
  82. return $this->objectManagerHelper->getObject(
  83. \Magento\Checkout\Model\Session\SuccessValidator::class,
  84. ['checkoutSession' => $checkoutSession]
  85. );
  86. }
  87. }