HtmlContentTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Ui\Test\Unit\Config\Converter;
  7. use Magento\Ui\Config\Converter\HtmlContent;
  8. /**
  9. * Class HtmlContentTest
  10. */
  11. class HtmlContentTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * @var HtmlContent
  15. */
  16. private $converter;
  17. /**
  18. * Set up mocks
  19. */
  20. public function setUp()
  21. {
  22. $this->converter = new HtmlContent();
  23. }
  24. public function testConvert()
  25. {
  26. $xml = '<?xml version="1.0"?>' .
  27. '<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' .
  28. '<block class="Magento\Customer\Block\Adminhtml\Edit\Tab\View" name="customer_edit_tab_view" ' .
  29. 'template="Magento_Customer::tab/view.phtml">' .
  30. '<block class="Magento\Customer\Block\Adminhtml\Edit\Tab\View\PersonalInfo" '.
  31. 'name="personal_info" template="Magento_Customer::tab/view/personal_info.phtml"/>' .
  32. '</block>' .
  33. '</layout>';
  34. $expectedResult = [
  35. 'xsi:type' => 'array',
  36. 'item' => [
  37. 'layout' => [
  38. 'xsi:type' => 'string',
  39. 'name' => 'layout',
  40. 'value' => ''
  41. ],
  42. 'name' => [
  43. 'xsi:type' => 'string',
  44. 'name' => 'block',
  45. 'value' => 'customer_edit_tab_view',
  46. ],
  47. ],
  48. ];
  49. $dom = new \DOMDocument('1.0', 'UTF-8');
  50. $dom->load(dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'testForm.xml');
  51. $domXpath = new \DOMXPath($dom);
  52. $node = $domXpath->query('//form/htmlContent/block')->item(0);
  53. $actualResult = $this->converter->convert($node, []);
  54. $this->assertTrue(isset($actualResult['item']['layout']['value']));
  55. // assert xml structures
  56. $this->assertXmlStringEqualsXmlString($xml, $actualResult['item']['layout']['value']);
  57. $actualResult['item']['layout']['value'] = '';
  58. // assert that all expected keys in array are exists
  59. $this->assertEquals($expectedResult, $actualResult);
  60. }
  61. }