|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2013-2017 Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\Tax\Test\Unit\Model\System\Message\Notification; |
| 7 | + |
| 8 | +use Magento\Tax\Model\Config as TaxConfig; |
| 9 | +use Magento\Tax\Model\System\Message\Notification\RoundingErrors as RoundingErrorsNotification; |
| 10 | +use Magento\Store\Model\StoreManagerInterface; |
| 11 | +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
| 12 | +use Magento\Framework\UrlInterface; |
| 13 | +use Magento\Store\Api\Data\StoreInterface; |
| 14 | +use Magento\Store\Api\Data\WebsiteInterface; |
| 15 | + |
| 16 | +/** |
| 17 | + * Test class for @see \Magento\Tax\Model\System\Message\Notification\RoundingErrors |
| 18 | + */ |
| 19 | +class RoundingErrorsTest extends \PHPUnit_Framework_TestCase |
| 20 | +{ |
| 21 | + /** |
| 22 | + * @var RoundingErrorsNotification |
| 23 | + */ |
| 24 | + private $roundingErrorsNotification; |
| 25 | + |
| 26 | + /** |
| 27 | + * @var StoreManagerInterface | \PHPUnit_Framework_MockObject_MockObject |
| 28 | + */ |
| 29 | + private $storeManagerMock; |
| 30 | + |
| 31 | + /** |
| 32 | + * @var UrlInterface | \PHPUnit_Framework_MockObject_MockObject |
| 33 | + */ |
| 34 | + private $urlBuilderMock; |
| 35 | + |
| 36 | + /** |
| 37 | + * @var TaxConfig | \PHPUnit_Framework_MockObject_MockObject |
| 38 | + */ |
| 39 | + private $taxConfigMock; |
| 40 | + |
| 41 | + protected function setUp() |
| 42 | + { |
| 43 | + parent::setUp(); |
| 44 | + |
| 45 | + $websiteMock = $this->getMock(WebsiteInterface::class, [], [], '', false); |
| 46 | + $websiteMock->expects($this->any())->method('getName')->willReturn('testWebsiteName'); |
| 47 | + $storeMock = $this->getMockForAbstractClass( |
| 48 | + StoreInterface::class, |
| 49 | + [], |
| 50 | + '', |
| 51 | + false, |
| 52 | + true, |
| 53 | + true, |
| 54 | + ['getWebsite', 'getName'] |
| 55 | + ); |
| 56 | + $storeMock->expects($this->any())->method('getName')->willReturn('testStoreName'); |
| 57 | + $storeMock->expects($this->any())->method('getWebsite')->willReturn($websiteMock); |
| 58 | + $this->storeManagerMock = $this->getMock(StoreManagerInterface::class, [], [], '', false); |
| 59 | + $this->storeManagerMock->expects($this->any())->method('getStores')->willReturn([$storeMock]); |
| 60 | + |
| 61 | + $this->urlBuilderMock = $this->getMock(UrlInterface::class, [], [], '', false); |
| 62 | + $this->taxConfigMock = $this->getMock(TaxConfig::class, [], [], '', false); |
| 63 | + $this->roundingErrorsNotification = (new ObjectManager($this))->getObject( |
| 64 | + RoundingErrorsNotification::class, |
| 65 | + [ |
| 66 | + 'storeManager' => $this->storeManagerMock, |
| 67 | + 'urlBuilder' => $this->urlBuilderMock, |
| 68 | + 'taxConfig' => $this->taxConfigMock, |
| 69 | + ] |
| 70 | + ); |
| 71 | + } |
| 72 | + |
| 73 | + public function testIsDisplayedNotDisplayedUnitBased() |
| 74 | + { |
| 75 | + $this->taxConfigMock->expects($this->any())->method('isWrongDisplaySettingsIgnored')->willReturn(false); |
| 76 | + |
| 77 | + $this->taxConfigMock->expects($this->any()) |
| 78 | + ->method('getAlgorithm')->willReturn(\Magento\Tax\Model\Calculation::CALC_UNIT_BASE); |
| 79 | + |
| 80 | + $this->taxConfigMock->expects($this->any()) |
| 81 | + ->method('getPriceDisplayType')->willReturn(\Magento\Tax\Model\Config::DISPLAY_TYPE_EXCLUDING_TAX); |
| 82 | + $this->taxConfigMock->expects($this->any()) |
| 83 | + ->method('getShippingPriceDisplayType')->willReturn(\Magento\Tax\Model\Config::DISPLAY_TYPE_EXCLUDING_TAX); |
| 84 | + |
| 85 | + $this->taxConfigMock->expects($this->any())->method('displayCartPricesBoth')->willReturn(false); |
| 86 | + $this->taxConfigMock->expects($this->any())->method('displayCartSubtotalBoth')->willReturn(false); |
| 87 | + $this->taxConfigMock->expects($this->any())->method('displayCartShippingBoth')->willReturn(false); |
| 88 | + $this->taxConfigMock->expects($this->any())->method('displaySalesPricesBoth')->willReturn(false); |
| 89 | + $this->taxConfigMock->expects($this->any())->method('displaySalesSubtotalBoth')->willReturn(false); |
| 90 | + |
| 91 | + $this->taxConfigMock->expects($this->any())->method('displaySalesShippingBoth')->willReturn(true); |
| 92 | + |
| 93 | + $this->assertFalse($this->roundingErrorsNotification->isDisplayed()); |
| 94 | + } |
| 95 | + |
| 96 | + public function testIsDisplayedNotDisplayed() |
| 97 | + { |
| 98 | + $this->taxConfigMock->expects($this->any())->method('isWrongDisplaySettingsIgnored')->willReturn(false); |
| 99 | + |
| 100 | + $this->taxConfigMock->expects($this->any()) |
| 101 | + ->method('getAlgorithm')->willReturn(\Magento\Tax\Model\Calculation::CALC_ROW_BASE); |
| 102 | + |
| 103 | + $this->taxConfigMock->expects($this->any()) |
| 104 | + ->method('getPriceDisplayType')->willReturn(\Magento\Tax\Model\Config::DISPLAY_TYPE_EXCLUDING_TAX); |
| 105 | + $this->taxConfigMock->expects($this->any()) |
| 106 | + ->method('getShippingPriceDisplayType')->willReturn(\Magento\Tax\Model\Config::DISPLAY_TYPE_EXCLUDING_TAX); |
| 107 | + |
| 108 | + $this->taxConfigMock->expects($this->any())->method('displayCartPricesBoth')->willReturn(false); |
| 109 | + $this->taxConfigMock->expects($this->any())->method('displayCartSubtotalBoth')->willReturn(false); |
| 110 | + $this->taxConfigMock->expects($this->any())->method('displayCartShippingBoth')->willReturn(false); |
| 111 | + $this->taxConfigMock->expects($this->any())->method('displaySalesPricesBoth')->willReturn(false); |
| 112 | + $this->taxConfigMock->expects($this->any())->method('displaySalesSubtotalBoth')->willReturn(false); |
| 113 | + $this->taxConfigMock->expects($this->any())->method('displaySalesShippingBoth')->willReturn(false); |
| 114 | + |
| 115 | + $this->assertFalse($this->roundingErrorsNotification->isDisplayed()); |
| 116 | + } |
| 117 | + |
| 118 | + public function testIsDisplayedIgnoreWrongConfiguration() |
| 119 | + { |
| 120 | + $this->taxConfigMock->expects($this->any())->method('isWrongDisplaySettingsIgnored')->willReturn(true); |
| 121 | + $this->assertFalse($this->roundingErrorsNotification->isDisplayed()); |
| 122 | + } |
| 123 | + |
| 124 | + public function testGetText() |
| 125 | + { |
| 126 | + $this->taxConfigMock->expects($this->any())->method('isWrongDisplaySettingsIgnored')->willReturn(false); |
| 127 | + |
| 128 | + $this->taxConfigMock->expects($this->any())->method('displaySalesShippingBoth')->willReturn(true); |
| 129 | + |
| 130 | + $this->urlBuilderMock->expects($this->any()) |
| 131 | + ->method('getUrl') |
| 132 | + ->with('tax/tax/ignoreTaxNotification', ['section' => 'price_display']) |
| 133 | + ->willReturn('http://example.com'); |
| 134 | + $this->roundingErrorsNotification->isDisplayed(); |
| 135 | + $this->assertEquals( |
| 136 | + '<strong>Warning tax configuration can result in rounding errors. ' |
| 137 | + . '</strong><p>Store(s) affected: testWebsiteName (testStoreName)</p><p>Click on the link to ' |
| 138 | + . '<a href="http://example.com">ignore this notification</a></p>', |
| 139 | + $this->roundingErrorsNotification->getText() |
| 140 | + ); |
| 141 | + } |
| 142 | +} |
0 commit comments