Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ApplyDiscountOnPricesTest.php
Go to the documentation of this file.
1 <?php
8 
10 use Magento\Tax\Model\System\Message\Notification\ApplyDiscountOnPrices as ApplyDiscountOnPricesNotification;
16 
22 class ApplyDiscountOnPricesTest extends \PHPUnit\Framework\TestCase
23 {
27  private $applyDiscountOnPricesNotification;
28 
32  private $storeManagerMock;
33 
37  private $urlBuilderMock;
38 
42  private $taxConfigMock;
43 
44  protected function setUp()
45  {
46  parent::setUp();
47 
48  $websiteMock = $this->createMock(WebsiteInterface::class);
49  $websiteMock->expects($this->any())->method('getName')->willReturn('testWebsiteName');
50  $storeMock = $this->getMockForAbstractClass(
51  StoreInterface::class,
52  [],
53  '',
54  false,
55  true,
56  true,
57  ['getWebsite', 'getName']
58  );
59  $storeMock->expects($this->any())->method('getName')->willReturn('testStoreName');
60  $storeMock->expects($this->any())->method('getWebsite')->willReturn($websiteMock);
61  $this->storeManagerMock = $this->createMock(StoreManagerInterface::class);
62  $this->storeManagerMock->expects($this->any())->method('getStores')->willReturn([$storeMock]);
63 
64  $this->urlBuilderMock = $this->createMock(UrlInterface::class);
65  $this->taxConfigMock = $this->createMock(TaxConfig::class);
66  $this->applyDiscountOnPricesNotification = (new ObjectManager($this))->getObject(
67  ApplyDiscountOnPricesNotification::class,
68  [
69  'storeManager' => $this->storeManagerMock,
70  'urlBuilder' => $this->urlBuilderMock,
71  'taxConfig' => $this->taxConfigMock,
72  ]
73  );
74  }
75 
79  public function testIsDisplayed(
80  $isWrongApplyDiscountSettingIgnored,
81  $priceIncludesTax,
82  $applyTaxAfterDiscount,
83  $discountTax,
84  $expectedResult
85  ) {
86  $this->taxConfigMock->expects($this->any())->method('isWrongApplyDiscountSettingIgnored')
87  ->willReturn($isWrongApplyDiscountSettingIgnored);
88  $this->taxConfigMock->expects($this->any())->method('priceIncludesTax')->willReturn($priceIncludesTax);
89  $this->taxConfigMock->expects($this->any())->method('applyTaxAfterDiscount')
90  ->willReturn($applyTaxAfterDiscount);
91  $this->taxConfigMock->expects($this->any())->method('discountTax')->willReturn($discountTax);
92 
93  $this->assertEquals($expectedResult, $this->applyDiscountOnPricesNotification->isDisplayed());
94  }
95 
99  public function dataProviderIsDisplayed()
100  {
101  return [
102  [
103  false, // $isWrongApplyDiscountSettingIgnored,
104  false, // $priceIncludesTax,
105  true, // $applyTaxAfterDiscount,
106  true, // $discountTax,
107  true // $expectedResult
108  ],
109  [
110  false, // $isWrongApplyDiscountSettingIgnored,
111  false, // $priceIncludesTax,
112  true, // $applyTaxAfterDiscount,
113  false, // $discountTax,
114  false // $expectedResult
115  ],
116  [
117  false, // $isWrongApplyDiscountSettingIgnored,
118  false, // $priceIncludesTax,
119  false, // $applyTaxAfterDiscount,
120  true, // $discountTax,
121  false // $expectedResult
122  ],
123  [
124  false, // $isWrongApplyDiscountSettingIgnored,
125  true, // $priceIncludesTax,
126  true, // $applyTaxAfterDiscount,
127  true, // $discountTax,
128  false // $expectedResult
129  ],
130  [
131  true, // $isWrongApplyDiscountSettingIgnored,
132  false, // $priceIncludesTax,
133  true, // $applyTaxAfterDiscount,
134  true, // $discountTax,
135  false // $expectedResult
136  ]
137  ];
138  }
139 
140  public function testGetText()
141  {
142  $this->taxConfigMock->expects($this->any())->method('isWrongApplyDiscountSettingIgnored')->willReturn(false);
143 
144  $this->taxConfigMock->expects($this->any())->method('priceIncludesTax')->willReturn(false);
145  $this->taxConfigMock->expects($this->any())->method('applyTaxAfterDiscount')->willReturn(true);
146  $this->taxConfigMock->expects($this->any())->method('discountTax')->willReturn(true);
147 
148  $this->urlBuilderMock->expects($this->any())
149  ->method('getUrl')
150  ->with('tax/tax/ignoreTaxNotification', ['section' => 'apply_discount'])
151  ->willReturn('http://example.com');
152  $this->applyDiscountOnPricesNotification->isDisplayed();
153  $this->assertEquals(
154  '<strong>To apply the discount on prices including tax and apply the tax after discount, '
155  . 'set Catalog Prices to “Including Tax”. </strong><p>Store(s) affected: testWebsiteName '
156  . '(testStoreName)</p><p>Click on the link to '
157  . '<a href="http://example.com">ignore this notification</a></p>',
158  $this->applyDiscountOnPricesNotification->getText()
159  );
160  }
161 }
testIsDisplayed( $isWrongApplyDiscountSettingIgnored, $priceIncludesTax, $applyTaxAfterDiscount, $discountTax, $expectedResult)