HtmlContentTest.php 2.28 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\Ui\Test\Unit\Config\Converter;

use Magento\Ui\Config\Converter\HtmlContent;

/**
 * Class HtmlContentTest
 */
class HtmlContentTest extends \PHPUnit\Framework\TestCase
{
    /**
     * @var HtmlContent
     */
    private $converter;

    /**
     * Set up mocks
     */
    public function setUp()
    {
        $this->converter = new HtmlContent();
    }

    public function testConvert()
    {
        $xml = '<?xml version="1.0"?>' .
                '<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' .
                        '<block class="Magento\Customer\Block\Adminhtml\Edit\Tab\View" name="customer_edit_tab_view" ' .
                                'template="Magento_Customer::tab/view.phtml">' .
                            '<block class="Magento\Customer\Block\Adminhtml\Edit\Tab\View\PersonalInfo" '.
                                    'name="personal_info" template="Magento_Customer::tab/view/personal_info.phtml"/>' .
                        '</block>' .
                '</layout>';
        $expectedResult = [
            'xsi:type' => 'array',
            'item' => [
                'layout' => [
                    'xsi:type' => 'string',
                    'name' => 'layout',
                    'value' => ''
                ],
                'name' => [
                    'xsi:type' => 'string',
                    'name' => 'block',
                    'value' => 'customer_edit_tab_view',
                ],
            ],
        ];

        $dom = new \DOMDocument('1.0', 'UTF-8');
        $dom->load(dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'testForm.xml');
        $domXpath = new \DOMXPath($dom);
        $node = $domXpath->query('//form/htmlContent/block')->item(0);

        $actualResult = $this->converter->convert($node, []);
        $this->assertTrue(isset($actualResult['item']['layout']['value']));

        // assert xml structures
        $this->assertXmlStringEqualsXmlString($xml, $actualResult['item']['layout']['value']);
        $actualResult['item']['layout']['value'] = '';

        // assert that all expected keys in array are exists
        $this->assertEquals($expectedResult, $actualResult);
    }
}