NotificationAboutFailedSubscriptionTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Analytics\Test\Unit\Model\System\Message;
  7. use Magento\Analytics\Model\SubscriptionStatusProvider;
  8. use Magento\Analytics\Model\System\Message\NotificationAboutFailedSubscription;
  9. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
  10. use Magento\Framework\UrlInterface;
  11. class NotificationAboutFailedSubscriptionTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * @var \PHPUnit_Framework_MockObject_MockObject|SubscriptionStatusProvider
  15. */
  16. private $subscriptionStatusMock;
  17. /**
  18. * @var \PHPUnit_Framework_MockObject_MockObject|UrlInterface
  19. */
  20. private $urlBuilderMock;
  21. /**
  22. * @var NotificationAboutFailedSubscription
  23. */
  24. private $notification;
  25. /**
  26. * @var ObjectManagerHelper
  27. */
  28. private $objectManagerHelper;
  29. /**
  30. * @return void
  31. */
  32. protected function setUp()
  33. {
  34. $this->subscriptionStatusMock = $this->getMockBuilder(SubscriptionStatusProvider::class)
  35. ->disableOriginalConstructor()
  36. ->getMock();
  37. $this->urlBuilderMock = $this->getMockBuilder(UrlInterface::class)
  38. ->getMockForAbstractClass();
  39. $this->objectManagerHelper = new ObjectManagerHelper($this);
  40. $this->notification = $this->objectManagerHelper->getObject(
  41. NotificationAboutFailedSubscription::class,
  42. [
  43. 'subscriptionStatusProvider' => $this->subscriptionStatusMock,
  44. 'urlBuilder' => $this->urlBuilderMock
  45. ]
  46. );
  47. }
  48. public function testIsDisplayedWhenMessageShouldBeDisplayed()
  49. {
  50. $this->subscriptionStatusMock->expects($this->once())
  51. ->method('getStatus')
  52. ->willReturn(
  53. SubscriptionStatusProvider::FAILED
  54. );
  55. $this->assertTrue($this->notification->isDisplayed());
  56. }
  57. /**
  58. * @dataProvider notDisplayedNotificationStatuses
  59. *
  60. * @param $status
  61. */
  62. public function testIsDisplayedWhenMessageShouldNotBeDisplayed($status)
  63. {
  64. $this->subscriptionStatusMock->expects($this->once())
  65. ->method('getStatus')
  66. ->willReturn($status);
  67. $this->assertFalse($this->notification->isDisplayed());
  68. }
  69. public function testGetTextShouldBuildMessage()
  70. {
  71. $retryUrl = 'http://magento.dev/retryUrl';
  72. $this->urlBuilderMock->expects($this->once())
  73. ->method('getUrl')
  74. ->with('analytics/subscription/retry')
  75. ->willReturn($retryUrl);
  76. $messageDetails = 'Failed to synchronize data to the Magento Business Intelligence service. ';
  77. $messageDetails .= sprintf('<a href="%s">Retry Synchronization</a>', $retryUrl);
  78. $this->assertEquals($messageDetails, $this->notification->getText());
  79. }
  80. /**
  81. * Provide statuses according to which message should not be displayed.
  82. *
  83. * @return array
  84. */
  85. public function notDisplayedNotificationStatuses()
  86. {
  87. return [
  88. [SubscriptionStatusProvider::PENDING],
  89. [SubscriptionStatusProvider::DISABLED],
  90. [SubscriptionStatusProvider::ENABLED],
  91. ];
  92. }
  93. }