Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CacheOutdatedTest.php
Go to the documentation of this file.
1 <?php
7 
8 class CacheOutdatedTest extends \PHPUnit\Framework\TestCase
9 {
14 
19 
23  protected $_urlInterfaceMock;
24 
28  protected $_messageModel;
29 
30  protected function setUp()
31  {
32  $this->_authorizationMock = $this->createMock(\Magento\Framework\AuthorizationInterface::class);
33  $this->_urlInterfaceMock = $this->createMock(\Magento\Framework\UrlInterface::class);
34  $this->_cacheTypeListMock = $this->createMock(\Magento\Framework\App\Cache\TypeListInterface::class);
35 
36  $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
37  $arguments = [
38  'authorization' => $this->_authorizationMock,
39  'urlBuilder' => $this->_urlInterfaceMock,
40  'cacheTypeList' => $this->_cacheTypeListMock,
41  ];
42  $this->_messageModel = $objectManagerHelper->getObject(
43  \Magento\AdminNotification\Model\System\Message\CacheOutdated::class,
45  );
46  }
47 
53  public function testGetIdentity($expectedSum, $cacheTypes)
54  {
55  $this->_cacheTypeListMock->expects(
56  $this->any()
57  )->method(
58  'getInvalidated'
59  )->will(
60  $this->returnValue($cacheTypes)
61  );
62  $this->assertEquals($expectedSum, $this->_messageModel->getIdentity());
63  }
64 
68  public function getIdentityDataProvider()
69  {
70  $cacheTypeMock1 = $this->createPartialMock(\stdClass::class, ['getCacheType']);
71  $cacheTypeMock1->expects($this->any())->method('getCacheType')->will($this->returnValue('Simple'));
72 
73  $cacheTypeMock2 = $this->createPartialMock(\stdClass::class, ['getCacheType']);
74  $cacheTypeMock2->expects($this->any())->method('getCacheType')->will($this->returnValue('Advanced'));
75 
76  return [
77  ['c13cfaddc2c53e8d32f59bfe89719beb', [$cacheTypeMock1]],
78  ['69aacdf14d1d5fcef7168b9ac308215e', [$cacheTypeMock1, $cacheTypeMock2]]
79  ];
80  }
81 
88  public function testIsDisplayed($expected, $allowed, $cacheTypes)
89  {
90  $this->_authorizationMock->expects($this->once())->method('isAllowed')->will($this->returnValue($allowed));
91  $this->_cacheTypeListMock->expects(
92  $this->any()
93  )->method(
94  'getInvalidated'
95  )->will(
96  $this->returnValue($cacheTypes)
97  );
98  $this->assertEquals($expected, $this->_messageModel->isDisplayed());
99  }
100 
104  public function isDisplayedDataProvider()
105  {
106  $cacheTypesMock = $this->createPartialMock(\stdClass::class, ['getCacheType']);
107  $cacheTypesMock->expects($this->any())->method('getCacheType')->will($this->returnValue('someVal'));
108  $cacheTypes = [$cacheTypesMock, $cacheTypesMock];
109  return [
110  [false, false, []],
111  [false, false, $cacheTypes],
112  [false, true, []],
113  [true, true, $cacheTypes]
114  ];
115  }
116 
117  public function testGetText()
118  {
119  $messageText = 'One or more of the Cache Types are invalidated';
120 
121  $this->_cacheTypeListMock->expects($this->any())->method('getInvalidated')->will($this->returnValue([]));
122  $this->_urlInterfaceMock->expects($this->once())->method('getUrl')->will($this->returnValue('someURL'));
123  $this->assertContains($messageText, $this->_messageModel->getText());
124  }
125 
126  public function testGetLink()
127  {
128  $url = 'backend/admin/cache';
129  $this->_urlInterfaceMock->expects($this->once())->method('getUrl')->will($this->returnValue($url));
130  $this->assertEquals($url, $this->_messageModel->getLink());
131  }
132 }
$arguments