|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com) |
| 4 | + */ |
| 5 | +namespace Magento\Quote\Helper; |
| 6 | + |
| 7 | +/** |
| 8 | + * Tests For Quote Data checker |
| 9 | + */ |
| 10 | +class DataTest extends \PHPUnit_Framework_TestCase |
| 11 | +{ |
| 12 | + /** |
| 13 | + * @var \Magento\Quote\Helper\Data |
| 14 | + */ |
| 15 | + protected $helper; |
| 16 | + |
| 17 | + /** |
| 18 | + * @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Quote\Model\Quote |
| 19 | + */ |
| 20 | + protected $quoteMock; |
| 21 | + |
| 22 | + /** |
| 23 | + * @return void |
| 24 | + */ |
| 25 | + protected function setUp() |
| 26 | + { |
| 27 | + $this->helper = new \Magento\Quote\Helper\Data(); |
| 28 | + |
| 29 | + $this->quoteMock = $this->getMockBuilder('Magento\Quote\Model\Quote') |
| 30 | + ->setMethods(['getHasError', 'setHasError', 'addMessage', '__wakeup']) |
| 31 | + ->disableOriginalConstructor() |
| 32 | + ->getMock(); |
| 33 | + } |
| 34 | + |
| 35 | + public function testCheckQuoteAmountExistingError() |
| 36 | + { |
| 37 | + $this->quoteMock->expects($this->once()) |
| 38 | + ->method('getHasError') |
| 39 | + ->will($this->returnValue(true)); |
| 40 | + |
| 41 | + $this->quoteMock->expects($this->never()) |
| 42 | + ->method('setHasError'); |
| 43 | + |
| 44 | + $this->quoteMock->expects($this->never()) |
| 45 | + ->method('addMessage'); |
| 46 | + |
| 47 | + $this->assertSame( |
| 48 | + $this->helper, |
| 49 | + $this->helper->checkQuoteAmount($this->quoteMock, Data::MAXIMUM_AVAILABLE_NUMBER + 1) |
| 50 | + ); |
| 51 | + } |
| 52 | + |
| 53 | + public function testCheckQuoteAmountAmountLessThanAvailable() |
| 54 | + { |
| 55 | + $this->quoteMock->expects($this->once()) |
| 56 | + ->method('getHasError') |
| 57 | + ->will($this->returnValue(false)); |
| 58 | + |
| 59 | + $this->quoteMock->expects($this->never()) |
| 60 | + ->method('setHasError'); |
| 61 | + |
| 62 | + $this->quoteMock->expects($this->never()) |
| 63 | + ->method('addMessage'); |
| 64 | + |
| 65 | + $this->assertSame( |
| 66 | + $this->helper, |
| 67 | + $this->helper->checkQuoteAmount($this->quoteMock, Data::MAXIMUM_AVAILABLE_NUMBER - 1) |
| 68 | + ); |
| 69 | + } |
| 70 | + |
| 71 | + public function testCheckQuoteAmountAmountGreaterThanAvailable() |
| 72 | + { |
| 73 | + $this->quoteMock->expects($this->once()) |
| 74 | + ->method('getHasError') |
| 75 | + ->will($this->returnValue(false)); |
| 76 | + |
| 77 | + $this->quoteMock->expects($this->once()) |
| 78 | + ->method('setHasError') |
| 79 | + ->with(true); |
| 80 | + |
| 81 | + $this->quoteMock->expects($this->once()) |
| 82 | + ->method('addMessage') |
| 83 | + ->with(__('This item price or quantity is not valid for checkout.')); |
| 84 | + |
| 85 | + $this->assertSame( |
| 86 | + $this->helper, |
| 87 | + $this->helper->checkQuoteAmount($this->quoteMock, Data::MAXIMUM_AVAILABLE_NUMBER + 1) |
| 88 | + ); |
| 89 | + } |
| 90 | +} |
0 commit comments