Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
NotificationsTest.php
Go to the documentation of this file.
1 <?php
8 
15 
19 class NotificationsTest extends \PHPUnit\Framework\TestCase
20 {
24  private $notifications;
25 
29  private $storeManagerMock;
30 
34  private $urlBuilderMock;
35 
39  private $taxConfigMock;
40 
44  private $notificationMock;
45 
46  protected function setUp()
47  {
48  parent::setUp();
49 
50  $this->storeManagerMock = $this->createMock(StoreManagerInterface::class);
51  $this->urlBuilderMock = $this->createMock(UrlInterface::class);
52  $this->taxConfigMock = $this->createMock(TaxConfig::class);
53  $this->notificationMock = $this->createMock(NotificationInterface::class);
54  $this->notifications = (new ObjectManager($this))->getObject(
55  Notifications::class,
56  [
57  'storeManager' => $this->storeManagerMock,
58  'urlBuilder' => $this->urlBuilderMock,
59  'taxConfig' => $this->taxConfigMock,
60  'notifications' => [$this->notificationMock]
61  ]
62  );
63  }
64 
68  public function testIsDisplayed(
69  $isNotificationDisplayed,
70  $expectedResult
71  ) {
72  $this->notificationMock->expects($this->once())->method('isDisplayed')->willReturn($isNotificationDisplayed);
73  $this->assertEquals($expectedResult, $this->notifications->isDisplayed());
74  }
75 
79  public function dataProviderIsDisplayed()
80  {
81  return [
82  [true, true],
83  [false, false]
84  ];
85  }
86 
87  public function testGetText()
88  {
89  $this->notificationMock->expects($this->once())->method('getText')->willReturn('Notification Text.');
90  $this->taxConfigMock->expects($this->once())->method('getInfoUrl')->willReturn('http://info-url');
91  $this->urlBuilderMock->expects($this->once())->method('getUrl')
92  ->with('adminhtml/system_config/edit/section/tax')->willReturn('http://tax-config-url');
93 
94  $this->assertEquals(
95  'Notification Text.<p>Please see <a href="http://info-url">documentation</a> for more details. '
96  . 'Click here to go to <a href="http://tax-config-url">Tax Configuration</a> and change your settings.</p>',
97  $this->notifications->getText()
98  );
99  }
100 }
testIsDisplayed( $isNotificationDisplayed, $expectedResult)