Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
HtmlContentTest.php
Go to the documentation of this file.
1 <?php
7 
9 
13 class HtmlContentTest extends \PHPUnit\Framework\TestCase
14 {
18  private $converter;
19 
23  public function setUp()
24  {
25  $this->converter = new HtmlContent();
26  }
27 
28  public function testConvert()
29  {
30  $xml = '<?xml version="1.0"?>' .
31  '<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' .
32  '<block class="Magento\Customer\Block\Adminhtml\Edit\Tab\View" name="customer_edit_tab_view" ' .
33  'template="Magento_Customer::tab/view.phtml">' .
34  '<block class="Magento\Customer\Block\Adminhtml\Edit\Tab\View\PersonalInfo" '.
35  'name="personal_info" template="Magento_Customer::tab/view/personal_info.phtml"/>' .
36  '</block>' .
37  '</layout>';
38  $expectedResult = [
39  'xsi:type' => 'array',
40  'item' => [
41  'layout' => [
42  'xsi:type' => 'string',
43  'name' => 'layout',
44  'value' => ''
45  ],
46  'name' => [
47  'xsi:type' => 'string',
48  'name' => 'block',
49  'value' => 'customer_edit_tab_view',
50  ],
51  ],
52  ];
53 
54  $dom = new \DOMDocument('1.0', 'UTF-8');
55  $dom->load(dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'testForm.xml');
56  $domXpath = new \DOMXPath($dom);
57  $node = $domXpath->query('//form/htmlContent/block')->item(0);
58 
59  $actualResult = $this->converter->convert($node, []);
60  $this->assertTrue(isset($actualResult['item']['layout']['value']));
61 
62  // assert xml structures
63  $this->assertXmlStringEqualsXmlString($xml, $actualResult['item']['layout']['value']);
64  $actualResult['item']['layout']['value'] = '';
65 
66  // assert that all expected keys in array are exists
67  $this->assertEquals($expectedResult, $actualResult);
68  }
69 }
defined('MTF_BOOT_FILE')||define('MTF_BOOT_FILE' __FILE__
Definition: bootstrap.php:7