Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DiscountErrorsTest.php
Go to the documentation of this file.
1 <?php
7 
15 
19 class DiscountErrorsTest extends \PHPUnit\Framework\TestCase
20 {
24  private $discountErrorsNotification;
25 
29  private $storeManagerMock;
30 
34  private $urlBuilderMock;
35 
39  private $taxConfigMock;
40 
41  protected function setUp()
42  {
43  parent::setUp();
44 
45  $websiteMock = $this->createMock(WebsiteInterface::class);
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->createMock(StoreManagerInterface::class);
59  $this->storeManagerMock->expects($this->any())->method('getStores')->willReturn([$storeMock]);
60 
61  $this->urlBuilderMock = $this->createMock(UrlInterface::class);
62  $this->taxConfigMock = $this->createMock(TaxConfig::class);
63  $this->discountErrorsNotification = (new ObjectManager($this))->getObject(
64  DiscountErrorsNotification::class,
65  [
66  'storeManager' => $this->storeManagerMock,
67  'urlBuilder' => $this->urlBuilderMock,
68  'taxConfig' => $this->taxConfigMock,
69  ]
70  );
71  }
72 
73  public function testIsDisplayed()
74  {
75  $this->taxConfigMock->expects($this->any())->method('applyTaxAfterDiscount')->willReturn(false);
76  $this->taxConfigMock->expects($this->any())->method('isWrongDiscountSettingsIgnored')->willReturn(false);
77  $this->assertTrue($this->discountErrorsNotification->isDisplayed());
78  }
79 
81  {
82  $this->taxConfigMock->expects($this->any())->method('applyTaxAfterDiscount')->willReturn(false);
83  $this->taxConfigMock->expects($this->any())->method('isWrongDiscountSettingsIgnored')->willReturn(true);
84  $this->assertFalse($this->discountErrorsNotification->isDisplayed());
85  }
86 
87  public function testGetText()
88  {
89  $this->taxConfigMock->expects($this->any())->method('applyTaxAfterDiscount')->willReturn(false);
90  $this->taxConfigMock->expects($this->any())->method('isWrongDiscountSettingsIgnored')->willReturn(false);
91  $this->urlBuilderMock->expects($this->any())
92  ->method('getUrl')
93  ->with('tax/tax/ignoreTaxNotification', ['section' => 'discount'])
94  ->willReturn('http://example.com');
95  $this->discountErrorsNotification->isDisplayed();
96  $this->assertEquals(
97  '<strong>With customer tax applied “Before Discount”, the final discount calculation may not match '
98  . 'customers’ expectations. </strong><p>Store(s) affected: testWebsiteName (testStoreName)'
99  . '</p><p>Click on the link to <a href="http://example.com">ignore this notification</a></p>',
100  $this->discountErrorsNotification->getText()
101  );
102  }
103 }