NotificationsTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Tax\Test\Unit\Model\System\Message;
  7. use Magento\Tax\Model\Config as TaxConfig;
  8. use Magento\Tax\Model\System\Message\Notifications;
  9. use Magento\Store\Model\StoreManagerInterface;
  10. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
  11. use Magento\Framework\UrlInterface;
  12. use Magento\Tax\Model\System\Message\NotificationInterface;
  13. /**
  14. * Test class for @see \Magento\Tax\Model\System\Message\Notifications
  15. */
  16. class NotificationsTest extends \PHPUnit\Framework\TestCase
  17. {
  18. /**
  19. * @var Notifications
  20. */
  21. private $notifications;
  22. /**
  23. * @var StoreManagerInterface | \PHPUnit_Framework_MockObject_MockObject
  24. */
  25. private $storeManagerMock;
  26. /**
  27. * @var UrlInterface | \PHPUnit_Framework_MockObject_MockObject
  28. */
  29. private $urlBuilderMock;
  30. /**
  31. * @var TaxConfig | \PHPUnit_Framework_MockObject_MockObject
  32. */
  33. private $taxConfigMock;
  34. /**
  35. * @var NotificationInterface | \PHPUnit_Framework_MockObject_MockObject
  36. */
  37. private $notificationMock;
  38. protected function setUp()
  39. {
  40. parent::setUp();
  41. $this->storeManagerMock = $this->createMock(StoreManagerInterface::class);
  42. $this->urlBuilderMock = $this->createMock(UrlInterface::class);
  43. $this->taxConfigMock = $this->createMock(TaxConfig::class);
  44. $this->notificationMock = $this->createMock(NotificationInterface::class);
  45. $this->notifications = (new ObjectManager($this))->getObject(
  46. Notifications::class,
  47. [
  48. 'storeManager' => $this->storeManagerMock,
  49. 'urlBuilder' => $this->urlBuilderMock,
  50. 'taxConfig' => $this->taxConfigMock,
  51. 'notifications' => [$this->notificationMock]
  52. ]
  53. );
  54. }
  55. /**
  56. * @dataProvider dataProviderIsDisplayed
  57. */
  58. public function testIsDisplayed(
  59. $isNotificationDisplayed,
  60. $expectedResult
  61. ) {
  62. $this->notificationMock->expects($this->once())->method('isDisplayed')->willReturn($isNotificationDisplayed);
  63. $this->assertEquals($expectedResult, $this->notifications->isDisplayed());
  64. }
  65. /**
  66. * @return array
  67. */
  68. public function dataProviderIsDisplayed()
  69. {
  70. return [
  71. [true, true],
  72. [false, false]
  73. ];
  74. }
  75. public function testGetText()
  76. {
  77. $this->notificationMock->expects($this->once())->method('getText')->willReturn('Notification Text.');
  78. $this->taxConfigMock->expects($this->once())->method('getInfoUrl')->willReturn('http://info-url');
  79. $this->urlBuilderMock->expects($this->once())->method('getUrl')
  80. ->with('adminhtml/system_config/edit/section/tax')->willReturn('http://tax-config-url');
  81. $this->assertEquals(
  82. 'Notification Text.<p>Please see <a href="http://info-url">documentation</a> for more details. '
  83. . 'Click here to go to <a href="http://tax-config-url">Tax Configuration</a> and change your settings.</p>',
  84. $this->notifications->getText()
  85. );
  86. }
  87. }