|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2015 Magento. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +/** |
| 8 | + * Test class for \Magento\Weee\Model\Observer |
| 9 | + */ |
| 10 | +namespace Magento\Tax\Test\Unit\Model; |
| 11 | + |
| 12 | +use \Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
| 13 | + |
| 14 | +class ObserverTest extends \PHPUnit_Framework_TestCase |
| 15 | +{ |
| 16 | + /** |
| 17 | + * Tests the methods that rely on the ScopeConfigInterface object to provide their return values |
| 18 | + * @param array $expected |
| 19 | + * @param bool $displayBothPrices |
| 20 | + * @param bool $priceIncludesTax |
| 21 | + * @param bool $displayPriceExcludingTax |
| 22 | + * @dataProvider dataProviderUpdateProductOptions |
| 23 | + */ |
| 24 | + public function testUpdateProductOptions( |
| 25 | + $expected, |
| 26 | + $displayBothPrices, |
| 27 | + $priceIncludesTax, |
| 28 | + $displayPriceExcludingTax |
| 29 | + ) { |
| 30 | + |
| 31 | + $frameworkObject= new \Magento\Framework\Object(); |
| 32 | + $frameworkObject->setAdditionalOptions([]); |
| 33 | + |
| 34 | + $product=$this->getMock('Magento\Catalog\Model\Product', [], [], '', false); |
| 35 | + |
| 36 | + $registry=$this->getMock('Magento\Framework\Registry', [], [], '', false); |
| 37 | + $registry->expects($this->any()) |
| 38 | + ->method('registry') |
| 39 | + ->with('current_product') |
| 40 | + ->will($this->returnValue($product)); |
| 41 | + |
| 42 | + $taxData=$this->getMock('Magento\Tax\Helper\Data', [], [], '', false); |
| 43 | + $taxData->expects($this->any()) |
| 44 | + ->method('getCalculationAlgorithm') |
| 45 | + ->will($this->returnValue('TOTAL_BASE_CALCULATION')); |
| 46 | + |
| 47 | + $taxData->expects($this->any()) |
| 48 | + ->method('displayBothPrices') |
| 49 | + ->will($this->returnValue($displayBothPrices)); |
| 50 | + |
| 51 | + $taxData->expects($this->any()) |
| 52 | + ->method('priceIncludesTax') |
| 53 | + ->will($this->returnValue($priceIncludesTax)); |
| 54 | + |
| 55 | + $taxData->expects($this->any()) |
| 56 | + ->method('displayPriceExcludingTax') |
| 57 | + ->will($this->returnValue($displayPriceExcludingTax)); |
| 58 | + |
| 59 | + $eventObject=$this->getMock('Magento\Framework\Event', ['getResponseObject'], [], '', false); |
| 60 | + $eventObject->expects($this->any()) |
| 61 | + ->method('getResponseObject') |
| 62 | + ->will($this->returnValue($frameworkObject)); |
| 63 | + |
| 64 | + $observerObject=$this->getMock('Magento\Framework\Event\Observer', [], [], '', false); |
| 65 | + |
| 66 | + $observerObject->expects($this->any()) |
| 67 | + ->method('getEvent') |
| 68 | + ->will($this->returnValue($eventObject)); |
| 69 | + |
| 70 | + $objectManager = new ObjectManager($this); |
| 71 | + $taxObserverObject = $objectManager->getObject( |
| 72 | + 'Magento\Tax\Model\Observer', |
| 73 | + [ |
| 74 | + 'taxData' => $taxData, |
| 75 | + 'registry' => $registry, |
| 76 | + ] |
| 77 | + ); |
| 78 | + |
| 79 | + $taxObserverObject->updateProductOptions($observerObject); |
| 80 | + |
| 81 | + $this->assertEquals($expected, $frameworkObject->getAdditionalOptions()); |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * @return array |
| 86 | + */ |
| 87 | + public function dataProviderUpdateProductOptions() |
| 88 | + { |
| 89 | + return [ |
| 90 | + [ |
| 91 | + 'expected' => [ |
| 92 | + 'calculationAlgorithm' => 'TOTAL_BASE_CALCULATION', |
| 93 | + 'optionTemplate' => '<%= data.label %><% if (data.finalPrice.value) '. |
| 94 | + '{ %> +<%= data.finalPrice.formatted %> (Excl. tax: <%= data.basePrice.formatted %>)<% } %>', |
| 95 | + ], |
| 96 | + 'displayBothPrices' => true, |
| 97 | + 'priceIncludesTax' => false, |
| 98 | + 'displayPriceExcludingTax' => false, |
| 99 | + ], |
| 100 | + [ |
| 101 | + 'expected' => [ |
| 102 | + 'calculationAlgorithm' => 'TOTAL_BASE_CALCULATION', |
| 103 | + 'optionTemplate' => '<%= data.label %><% if (data.basePrice.value) '. |
| 104 | + '{ %> +<%= data.basePrice.formatted %><% } %>', |
| 105 | + ], |
| 106 | + 'displayBothPrices' => false, |
| 107 | + 'priceIncludesTax' => true, |
| 108 | + 'displayPriceExcludingTax' => true, |
| 109 | + ], |
| 110 | + [ |
| 111 | + 'expected' => [ |
| 112 | + 'calculationAlgorithm' => 'TOTAL_BASE_CALCULATION', |
| 113 | + ], |
| 114 | + 'displayBothPrices' => false, |
| 115 | + 'priceIncludesTax' => false, |
| 116 | + 'displayPriceExcludingTax' => false, |
| 117 | + ], |
| 118 | + ]; |
| 119 | + } |
| 120 | +} |
0 commit comments