CacheOutdatedTest.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\AdminNotification\Test\Unit\Model\System\Message;
  7. class CacheOutdatedTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \PHPUnit_Framework_MockObject_MockObject
  11. */
  12. protected $_authorizationMock;
  13. /**
  14. * @var \PHPUnit_Framework_MockObject_MockObject
  15. */
  16. protected $_cacheTypeListMock;
  17. /**
  18. * @var \PHPUnit_Framework_MockObject_MockObject
  19. */
  20. protected $_urlInterfaceMock;
  21. /**
  22. * @var \Magento\AdminNotification\Model\System\Message\CacheOutdated
  23. */
  24. protected $_messageModel;
  25. protected function setUp()
  26. {
  27. $this->_authorizationMock = $this->createMock(\Magento\Framework\AuthorizationInterface::class);
  28. $this->_urlInterfaceMock = $this->createMock(\Magento\Framework\UrlInterface::class);
  29. $this->_cacheTypeListMock = $this->createMock(\Magento\Framework\App\Cache\TypeListInterface::class);
  30. $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  31. $arguments = [
  32. 'authorization' => $this->_authorizationMock,
  33. 'urlBuilder' => $this->_urlInterfaceMock,
  34. 'cacheTypeList' => $this->_cacheTypeListMock,
  35. ];
  36. $this->_messageModel = $objectManagerHelper->getObject(
  37. \Magento\AdminNotification\Model\System\Message\CacheOutdated::class,
  38. $arguments
  39. );
  40. }
  41. /**
  42. * @param string $expectedSum
  43. * @param array $cacheTypes
  44. * @dataProvider getIdentityDataProvider
  45. */
  46. public function testGetIdentity($expectedSum, $cacheTypes)
  47. {
  48. $this->_cacheTypeListMock->expects(
  49. $this->any()
  50. )->method(
  51. 'getInvalidated'
  52. )->will(
  53. $this->returnValue($cacheTypes)
  54. );
  55. $this->assertEquals($expectedSum, $this->_messageModel->getIdentity());
  56. }
  57. /**
  58. * @return array
  59. */
  60. public function getIdentityDataProvider()
  61. {
  62. $cacheTypeMock1 = $this->createPartialMock(\stdClass::class, ['getCacheType']);
  63. $cacheTypeMock1->expects($this->any())->method('getCacheType')->will($this->returnValue('Simple'));
  64. $cacheTypeMock2 = $this->createPartialMock(\stdClass::class, ['getCacheType']);
  65. $cacheTypeMock2->expects($this->any())->method('getCacheType')->will($this->returnValue('Advanced'));
  66. return [
  67. ['c13cfaddc2c53e8d32f59bfe89719beb', [$cacheTypeMock1]],
  68. ['69aacdf14d1d5fcef7168b9ac308215e', [$cacheTypeMock1, $cacheTypeMock2]]
  69. ];
  70. }
  71. /**
  72. * @param bool $expected
  73. * @param bool $allowed
  74. * @param array $cacheTypes
  75. * @dataProvider isDisplayedDataProvider
  76. */
  77. public function testIsDisplayed($expected, $allowed, $cacheTypes)
  78. {
  79. $this->_authorizationMock->expects($this->once())->method('isAllowed')->will($this->returnValue($allowed));
  80. $this->_cacheTypeListMock->expects(
  81. $this->any()
  82. )->method(
  83. 'getInvalidated'
  84. )->will(
  85. $this->returnValue($cacheTypes)
  86. );
  87. $this->assertEquals($expected, $this->_messageModel->isDisplayed());
  88. }
  89. /**
  90. * @return array
  91. */
  92. public function isDisplayedDataProvider()
  93. {
  94. $cacheTypesMock = $this->createPartialMock(\stdClass::class, ['getCacheType']);
  95. $cacheTypesMock->expects($this->any())->method('getCacheType')->will($this->returnValue('someVal'));
  96. $cacheTypes = [$cacheTypesMock, $cacheTypesMock];
  97. return [
  98. [false, false, []],
  99. [false, false, $cacheTypes],
  100. [false, true, []],
  101. [true, true, $cacheTypes]
  102. ];
  103. }
  104. public function testGetText()
  105. {
  106. $messageText = 'One or more of the Cache Types are invalidated';
  107. $this->_cacheTypeListMock->expects($this->any())->method('getInvalidated')->will($this->returnValue([]));
  108. $this->_urlInterfaceMock->expects($this->once())->method('getUrl')->will($this->returnValue('someURL'));
  109. $this->assertContains($messageText, $this->_messageModel->getText());
  110. }
  111. public function testGetLink()
  112. {
  113. $url = 'backend/admin/cache';
  114. $this->_urlInterfaceMock->expects($this->once())->method('getUrl')->will($this->returnValue($url));
  115. $this->assertEquals($url, $this->_messageModel->getLink());
  116. }
  117. }