Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InvalidTest.php
Go to the documentation of this file.
1 <?php
7 
8 class InvalidTest extends \PHPUnit\Framework\TestCase
9 {
13  private $indexerMock = null;
14 
18  protected $model;
19 
23  protected function setUp()
24  {
25  $collectionMock = $this->createPartialMock(\Magento\Indexer\Model\Indexer\Collection::class, ['getItems']);
26 
27  $this->indexerMock = $this->createPartialMock(\Magento\Indexer\Model\Indexer::class, ['getStatus']);
28 
29  $urlBuilder = $this->createMock(\Magento\Framework\UrlInterface::class);
30 
31  $collectionMock->expects($this->any())->method('getItems')->with()->willReturn([$this->indexerMock]);
32 
33  $this->model = new \Magento\Indexer\Model\Message\Invalid(
34  $collectionMock,
35  $urlBuilder
36  );
37  }
38 
39  public function testDisplayMessage()
40  {
41  $this->indexerMock->expects($this->any())->method('getStatus')->with()
42  ->willReturn(\Magento\Framework\Indexer\StateInterface::STATUS_INVALID);
43 
44  $this->assertTrue($this->model->isDisplayed());
45  }
46 
47  public function testHideMessage()
48  {
49  $this->indexerMock->expects($this->any())->method('getStatus')->with()
50  ->willReturn('Status other than "invalid"');
51 
52  $this->assertFalse($this->model->isDisplayed());
53  }
54 }