Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DataTest.php
Go to the documentation of this file.
1 <?php
7 
11 class DataTest extends \PHPUnit\Framework\TestCase
12 {
18  protected $helper;
19 
25  protected $scopeConfigMock;
26 
32  protected $quoteMock;
33 
40 
41  protected function setUp()
42  {
43  $this->quoteMock = $this->createMock(\Magento\Quote\Model\Quote::class);
44 
45  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
46  $arguments = $objectManager->getConstructArguments(\Magento\Multishipping\Helper\Data::class);
47  $this->helper = $objectManager->getObject(\Magento\Multishipping\Helper\Data::class, $arguments);
48  $this->checkoutSessionMock = $arguments['checkoutSession'];
50  $context = $arguments['context'];
51  $this->scopeConfigMock = $context->getScopeConfig();
52  }
53 
54  public function testGetMaximumQty()
55  {
56  $maximumQty = 10;
57  $this->scopeConfigMock->expects(
58  $this->once()
59  )->method(
60  'getValue'
61  )->with(
62  \Magento\Multishipping\Helper\Data::XML_PATH_CHECKOUT_MULTIPLE_MAXIMUM_QUANTITY
63  )->will(
64  $this->returnValue($maximumQty)
65  );
66 
67  $this->assertEquals($maximumQty, $this->helper->getMaximumQty());
68  }
69 
82  $result,
83  $quoteHasItems,
84  $isMultiShipping,
85  $hasItemsWithDecimalQty,
86  $validateMinimumAmount,
87  $itemsSummaryQty,
88  $itemVirtualQty,
89  $maximumQty
90  ) {
91  $this->scopeConfigMock->expects(
92  $this->once()
93  )->method(
94  'isSetFlag'
95  )->with(
96  \Magento\Multishipping\Helper\Data::XML_PATH_CHECKOUT_MULTIPLE_AVAILABLE
97  )->will(
98  $this->returnValue($isMultiShipping)
99  );
100  $this->checkoutSessionMock->expects(
101  $this->once()
102  )->method(
103  'getQuote'
104  )->will(
105  $this->returnValue($this->quoteMock)
106  );
107  $this->quoteMock->expects($this->once())->method('hasItems')->will($this->returnValue($quoteHasItems));
108 
109  $this->quoteMock->expects(
110  $this->any()
111  )->method(
112  'hasItemsWithDecimalQty'
113  )->will(
114  $this->returnValue($hasItemsWithDecimalQty)
115  );
116  $this->quoteMock->expects(
117  $this->any()
118  )->method(
119  'validateMinimumAmount'
120  )->with(
121  true
122  )->will(
123  $this->returnValue($validateMinimumAmount)
124  );
125  $this->quoteMock->expects(
126  $this->any()
127  )->method(
128  'getItemsSummaryQty'
129  )->will(
130  $this->returnValue($itemsSummaryQty)
131  );
132  $this->quoteMock->expects(
133  $this->any()
134  )->method(
135  'getItemVirtualQty'
136  )->will(
137  $this->returnValue($itemVirtualQty)
138  );
139  $this->scopeConfigMock->expects(
140  $this->any()
141  )->method(
142  'getValue'
143  )->with(
144  \Magento\Multishipping\Helper\Data::XML_PATH_CHECKOUT_MULTIPLE_MAXIMUM_QUANTITY
145  )->will(
146  $this->returnValue($maximumQty)
147  );
148 
149  $this->assertEquals($result, $this->helper->isMultishippingCheckoutAvailable());
150  }
151 
158  {
159  return [
160  [true, false, true, null, null, null, null, null],
161  [false, false, false, null, null, null, null, null],
162  [false, true, true, true, null, null, null, null],
163  [false, true, true, false, false, null, null, null],
164  [true, true, true, false, true, 2, 1, 3],
165  [false, true, true, false, true, 1, 2, null],
166  [false, true, true, false, true, 2, 1, 1],
167  ];
168  }
169 }
$objectManager
Definition: bootstrap.php:17
testIsMultishippingCheckoutAvailable( $result, $quoteHasItems, $isMultiShipping, $hasItemsWithDecimalQty, $validateMinimumAmount, $itemsSummaryQty, $itemVirtualQty, $maximumQty)
Definition: DataTest.php:81
$arguments