16 class DataTest extends \PHPUnit\Framework\TestCase
21 private $priceCurrency;
31 private $transportBuilder;
41 private $checkoutSession;
51 private $eventManager;
56 protected function setUp()
58 $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
59 $className = \Magento\Checkout\Helper\Data::class;
63 $this->translator =
$arguments[
'inlineTranslation'];
64 $this->eventManager = $context->getEventManager();
65 $this->scopeConfig = $context->getScopeConfig();
66 $this->scopeConfig->expects($this->any())
71 'checkout/payment_failed/template',
74 'fixture_email_template_payment_failed',
77 'checkout/payment_failed/receiver',
83 'trans_email/ident_sysadmin/email',
89 'trans_email/ident_sysadmin/name',
92 'System Administrator',
95 'checkout/payment_failed/identity',
101 'carriers/ground/title',
107 'payment/fixture-payment-method/title',
113 'checkout/options/onepage_checkout_enabled',
121 $this->checkoutSession =
$arguments[
'checkoutSession'];
122 $arguments[
'localeDate']->expects($this->any())
123 ->method(
'formatDateTime')
124 ->willReturn(
'Oct 02, 2013');
126 $this->transportBuilder =
$arguments[
'transportBuilder'];
128 $this->priceCurrency =
$arguments[
'priceCurrency'];
138 $quoteMock = $this->getMockBuilder(\
Magento\
Quote\Model\Quote::class)
139 ->setMethods([
'getId'])
140 ->disableOriginalConstructor()
142 $quoteMock->expects($this->any())->method(
'getId')->willReturn(1);
144 $this->assertSame($this->helper, $this->helper->sendPaymentFailedEmail($quoteMock,
'test message'));
152 $this->assertEquals($this->checkoutSession, $this->helper->getCheckout());
157 $quoteMock = $this->createMock(\
Magento\
Quote\Model\Quote::class);
158 $this->checkoutSession->expects($this->once())->method(
'getQuote')->will($this->returnValue($quoteMock));
159 $this->assertEquals($quoteMock, $this->helper->getQuote());
165 $quoteMock = $this->createMock(\
Magento\
Quote\Model\Quote::class);
166 $storeMock = $this->createPartialMock(\
Magento\
Store\Model\Store::class, [
'formatPrice',
'__wakeup']);
167 $this->checkoutSession->expects($this->once())->method(
'getQuote')->will($this->returnValue($quoteMock));
168 $quoteMock->expects($this->once())->method(
'getStore')->will($this->returnValue($storeMock));
169 $this->priceCurrency->expects($this->once())->method(
'format')->will($this->returnValue(
'5.5'));
170 $this->assertEquals(
'5.5', $this->helper->formatPrice(
$price));
176 $this->priceCurrency->expects($this->once())->method(
'convertAndFormat')->willReturn(
$price);
177 $this->assertEquals(5.5, $this->helper->convertPrice(
$price));
182 $this->scopeConfig->expects($this->once())->method(
'getValue')->with(
183 'checkout/options/onepage_checkout_enabled',
185 )->will($this->returnValue(
true));
186 $this->assertTrue($this->helper->canOnepageCheckout());
191 $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
192 $context = $objectManagerHelper->getObject(
195 $helper = $objectManagerHelper->getObject(
196 \
Magento\Checkout\Helper\Data::class,
197 [
'context' => $context]
199 $context->getRequest()->expects($this->once())->method(
'getParam')->with(
'context')->will(
200 $this->returnValue(
'checkout')
202 $this->assertTrue($helper->isContextCheckout());
207 $this->scopeConfig->expects($this->once())->method(
'isSetFlag')->with(
208 'checkout/options/customer_must_be_logged',
210 )->will($this->returnValue(
true));
211 $this->assertTrue($this->helper->isCustomerMustBeLogged());
216 $itemMock = $this->createPartialMock(\
Magento\Framework\DataObject::class, [
'getPriceInclTax']);
217 $itemMock->expects($this->exactly(2))->method(
'getPriceInclTax')->will($this->returnValue(5.5));
218 $this->assertEquals(5.5, $this->helper->getPriceInclTax($itemMock));
225 $discountTaxCompensation = 1;
231 $helper = $objectManagerHelper->getObject(
232 \
Magento\Checkout\Helper\Data::class,
235 'priceCurrency' => $this->priceCurrency,
238 $itemMock = $this->createPartialMock(
239 \
Magento\Framework\DataObject::class,
240 [
'getPriceInclTax',
'getQty',
'getTaxAmount',
'getDiscountTaxCompensation',
'getRowTotal',
'getQtyOrdered']
242 $itemMock->expects($this->once())->method(
'getPriceInclTax')->will($this->returnValue(
false));
243 $itemMock->expects($this->exactly(2))->method(
'getQty')->will($this->returnValue($qty));
244 $itemMock->expects($this->never())->method(
'getQtyOrdered');
245 $itemMock->expects($this->once())->method(
'getTaxAmount')->will($this->returnValue(
$taxAmount));
246 $itemMock->expects($this->once())
247 ->method(
'getDiscountTaxCompensation')->will($this->returnValue($discountTaxCompensation));
248 $itemMock->expects($this->once())->method(
'getRowTotal')->will($this->returnValue($rowTotal));
249 $this->priceCurrency->expects($this->once())->method(
'round')->with($roundPrice)->willReturn($roundPrice);
250 $this->assertEquals($expected, $helper->getPriceInclTax($itemMock));
255 $rowTotalInclTax = 5.5;
257 $itemMock = $this->createPartialMock(\
Magento\Framework\DataObject::class, [
'getRowTotalInclTax']);
258 $itemMock->expects($this->exactly(2))->method(
'getRowTotalInclTax')->will($this->returnValue($rowTotalInclTax));
259 $this->assertEquals($expected, $this->helper->getSubtotalInclTax($itemMock));
265 $discountTaxCompensation = 1;
268 $itemMock = $this->createPartialMock(
269 \
Magento\Framework\DataObject::class,
270 [
'getRowTotalInclTax',
'getTaxAmount',
'getDiscountTaxCompensation',
'getRowTotal']
272 $itemMock->expects($this->once())->method(
'getRowTotalInclTax')->will($this->returnValue(
false));
273 $itemMock->expects($this->once())->method(
'getTaxAmount')->will($this->returnValue(
$taxAmount));
274 $itemMock->expects($this->once())
275 ->method(
'getDiscountTaxCompensation')->will($this->returnValue($discountTaxCompensation));
276 $itemMock->expects($this->once())->method(
'getRowTotal')->will($this->returnValue($rowTotal));
277 $this->assertEquals($expected, $this->helper->getSubtotalInclTax($itemMock));
284 $helper = $objectManagerHelper->getObject(
285 \
Magento\Checkout\Helper\Data::class,
288 'priceCurrency' => $this->priceCurrency,
291 $itemMock = $this->createPartialMock(\
Magento\Framework\DataObject::class, [
'getQty']);
292 $itemMock->expects($this->once())->method(
'getQty');
293 $this->priceCurrency->expects($this->once())->method(
'round');
294 $helper->getPriceInclTax($itemMock);
300 $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
301 $helper = $objectManagerHelper->getObject(
302 \
Magento\Checkout\Helper\Data::class,
305 'priceCurrency' => $this->priceCurrency,
308 $itemMock = $this->createPartialMock(\
Magento\Framework\DataObject::class, [
'getQty',
'getQtyOrdered']);
309 $itemMock->expects($this->once())->method(
'getQty')->will($this->returnValue(
false));
310 $itemMock->expects($this->exactly(2))->method(
'getQtyOrdered')->will($this->returnValue(5.5));
311 $this->priceCurrency->expects($this->once())->method(
'round');
312 $helper->getBasePriceInclTax($itemMock);
317 $itemMock = $this->createPartialMock(
318 \
Magento\Framework\DataObject::class,
319 [
'getBaseTaxAmount',
'getBaseDiscountTaxCompensation',
'getBaseRowTotal']
321 $itemMock->expects($this->once())->method(
'getBaseTaxAmount');
322 $itemMock->expects($this->once())->method(
'getBaseDiscountTaxCompensation');
323 $itemMock->expects($this->once())->method(
'getBaseRowTotal');
324 $this->helper->getBaseSubtotalInclTax($itemMock);
329 $quoteMock = $this->createMock(\
Magento\
Quote\Model\Quote::class);
331 $quoteMock->expects($this->once())->method(
'getStoreId')->will($this->returnValue(1));
332 $this->scopeConfig->expects($this->once())
333 ->method(
'isSetFlag')
334 ->will($this->returnValue(
true));
335 $this->assertTrue($this->helper->isAllowedGuestCheckout($quoteMock,
$store));
testGetBaseSubtotalInclTax()
testIsAllowedGuestCheckoutWithoutStore()
testGetPriceInclTaxWithoutTax()
testSendPaymentFailedEmail()
testIsCustomerMustBeLogged()
testGetBasePriceInclTaxWithoutQty()
testGetBasePriceInclTax()
testGetSubtotalInclTaxNegative()