Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DesignAbstractionTest.php
Go to the documentation of this file.
1 <?php
7 
11 class DesignAbstractionTest extends \PHPUnit\Framework\TestCase
12 {
17  protected $_block;
18 
19  protected function setUp()
20  {
21  parent::setUp();
22 
24  $layoutUtility = new \Magento\Framework\View\Utility\Layout($this);
25  $appState = $objectManager->get(\Magento\Framework\App\State::class);
26  $appState->setAreaCode(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE);
27  $processorMock = $this->getMockBuilder(\Magento\Framework\View\Layout\ProcessorInterface::class)
28  ->setMethods(['isPageLayoutDesignAbstraction'])
29  ->getMockForAbstractClass();
30  $processorMock->expects($this->exactly(2))->method('isPageLayoutDesignAbstraction')->will(
31  $this->returnCallback(
32  function ($abstraction) {
33  return $abstraction['design_abstraction'] === 'page_layout';
34  }
35  )
36  );
37  $processorFactoryMock =
38  $this->createPartialMock(\Magento\Framework\View\Layout\ProcessorFactory::class, ['create']);
39  $processorFactoryMock->expects($this->exactly(2))->method('create')->will(
40  $this->returnCallback(
41  function ($data) use ($processorMock, $layoutUtility) {
42  return $data === [] ? $processorMock : $layoutUtility->getLayoutUpdateFromFixture(
43  glob(__DIR__ . '/_files/layout/*.xml')
44  );
45  }
46  )
47  );
48 
49  $this->_block = new DesignAbstraction(
50  $objectManager->get(\Magento\Framework\View\Element\Template\Context::class),
51  $processorFactoryMock,
52  $objectManager->get(\Magento\Theme\Model\ResourceModel\Theme\CollectionFactory::class),
53  $appState,
54  [
55  'name' => 'design_abstractions',
56  'id' => 'design_abstraction_select',
57  'class' => 'design-abstraction-select',
58  'title' => 'Design Abstraction Select'
59  ]
60  );
61  }
62 
63  public function testToHtml()
64  {
65  $this->assertXmlStringEqualsXmlFile(
66  __DIR__ . '/_files/design-abstraction_select.html',
67  $this->_block->toHtml()
68  );
69  }
70 }
$objectManager
Definition: bootstrap.php:17
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60