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