QuoteValidatorTest.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Quote\Test\Unit\Model;
  7. use Magento\Directory\Model\AllowedCountries;
  8. use Magento\Quote\Model\Quote\Address;
  9. use Magento\Quote\Model\Quote\Payment;
  10. use Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage as OrderAmountValidationMessage;
  11. use Magento\Quote\Model\QuoteValidator;
  12. /**
  13. * Class QuoteValidatorTest
  14. */
  15. class QuoteValidatorTest extends \PHPUnit\Framework\TestCase
  16. {
  17. /**
  18. * @var \Magento\Quote\Model\QuoteValidator
  19. */
  20. protected $quoteValidator;
  21. /**
  22. * @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Quote\Model\Quote
  23. */
  24. protected $quoteMock;
  25. /**
  26. * @var AllowedCountries|\PHPUnit_Framework_MockObject_MockObject
  27. */
  28. private $allowedCountryReader;
  29. /**
  30. * @var OrderAmountValidationMessage|\PHPUnit_Framework_MockObject_MockObject
  31. */
  32. private $orderAmountValidationMessage;
  33. /**
  34. * @return void
  35. */
  36. protected function setUp()
  37. {
  38. $this->allowedCountryReader = $this->getMockBuilder(AllowedCountries::class)
  39. ->disableOriginalConstructor()
  40. ->getMock();
  41. $this->orderAmountValidationMessage = $this->getMockBuilder(OrderAmountValidationMessage::class)
  42. ->disableOriginalConstructor()
  43. ->getMock();
  44. $this->quoteValidator = new \Magento\Quote\Model\QuoteValidator(
  45. $this->allowedCountryReader,
  46. $this->orderAmountValidationMessage
  47. );
  48. $this->quoteMock = $this->createPartialMock(
  49. \Magento\Quote\Model\Quote::class,
  50. [
  51. 'getShippingAddress',
  52. 'getBillingAddress',
  53. 'getPayment',
  54. 'getHasError',
  55. 'setHasError',
  56. 'addMessage',
  57. 'isVirtual',
  58. 'validateMinimumAmount',
  59. 'getIsMultiShipping',
  60. '__wakeup'
  61. ]
  62. );
  63. }
  64. public function testCheckQuoteAmountExistingError()
  65. {
  66. $this->quoteMock->expects($this->once())
  67. ->method('getHasError')
  68. ->will($this->returnValue(true));
  69. $this->quoteMock->expects($this->never())
  70. ->method('setHasError');
  71. $this->quoteMock->expects($this->never())
  72. ->method('addMessage');
  73. $this->assertSame(
  74. $this->quoteValidator,
  75. $this->quoteValidator->validateQuoteAmount($this->quoteMock, QuoteValidator::MAXIMUM_AVAILABLE_NUMBER + 1)
  76. );
  77. }
  78. }