Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GetPageByIdentifierTest.php
Go to the documentation of this file.
1 <?php
7 
9 
14 class GetPageByIdentifierTest extends \PHPUnit\Framework\TestCase
15 {
20 
24  protected $page;
25 
29  protected $pageFactory;
30 
34  protected $pageResource;
35 
36  public function setUp()
37  {
38  $this->pageFactory = $this->getMockBuilder(\Magento\Cms\Model\PageFactory::class)
39  ->disableOriginalConstructor(true)
40  ->setMethods(['create'])
41  ->getMock();
42 
43  $this->pageResource = $this->getMockBuilder(\Magento\Cms\Model\ResourceModel\Page::class)
44  ->disableOriginalConstructor(true)
45  ->getMock();
46 
47  $this->page = $this->getMockBuilder(\Magento\Cms\Model\Page::class)
48  ->disableOriginalConstructor()
49  ->setMethods(['setStoreId', 'getId'])
50  ->getMock();
51 
52  $this->getPageByIdentifierCommand = new GetPageByIdentifier($this->pageFactory, $this->pageResource);
53  }
54 
58  public function testGetByIdentifier()
59  {
60  $identifier = 'home';
61  $storeId = 0;
62 
63  $this->pageFactory->expects($this->once())
64  ->method('create')
65  ->willReturn($this->page);
66 
67  $this->page->expects($this->once())
68  ->method('setStoreId')
69  ->willReturn($this->page);
70 
71  $this->page->expects($this->once())
72  ->method('getId')
73  ->willReturn(1);
74 
75  $this->pageResource->expects($this->once())
76  ->method('load')
77  ->with($this->page, $identifier)
78  ->willReturn($this->page);
79 
80  $this->getPageByIdentifierCommand->execute($identifier, $storeId);
81  }
82 }