formatOutput = true; $DOM->preserveWhiteSpace = false; $DOM->loadXML( $html ); return $DOM->saveXML(); } /** * @covers ::renderInfobox * @covers \PortableInfobox\Helpers\PortableInfoboxTemplateEngine * @param $input * @param $expectedOutput * @param $description * @param $accentColor * @param $accentColorText * @dataProvider renderInfoboxDataProvider */ public function testRenderInfobox( $input, $expectedOutput, $description, $accentColor, $accentColorText ) { $infoboxRenderService = new PortableInfoboxRenderService(); $actualOutput = $infoboxRenderService->renderInfobox( $input, '', '', $accentColor, $accentColorText, '', '' ); $expectedHtml = $this->normalizeHTML( $expectedOutput ); $actualHtml = $this->normalizeHTML( $actualOutput ); $this->assertEquals( $expectedHtml, $actualHtml, $description ); } // phpcs:disable Generic.Files.LineLength public function renderInfoboxDataProvider() { return [ [ 'input' => [], 'output' => '', 'description' => 'Empty data should yield no infobox markup', 'accentColor' => '', 'accentColorText' => '' ], [ 'input' => [ [ 'type' => 'title', 'data' => [ 'value' => 'Test Title', 'source' => null, 'item-name' => null ] ] ], 'output' => '', 'description' => 'Only title', 'accentColor' => '', 'accentColorText' => '' ], [ 'input' => [ [ 'type' => 'title', 'data' => [ 'value' => 'Test Title', 'source' => null, 'item-name' => null ] ] ], 'output' => '', 'description' => 'Only title with custom colors', 'accentColor' => '#FFF', 'accentColorText' => '#000' ], [ 'input' => [ [ 'type' => 'media', 'data' => [ [ 'alt' => 'image alt', 'url' => 'http://image.jpg', 'caption' => 'Lorem ipsum dolor', 'width' => '400', 'height' => '200', 'thumbnail' => 'http://thumbnail.jpg', 'thumbnail2x' => 'http://thumbnail2x.jpg', 'isImage' => true, 'source' => null, 'item-name' => null ] ] ] ], 'output' => '', 'description' => 'Only image', 'accentColor' => '', 'accentColorText' => '' ], [ 'input' => [ [ 'type' => 'media', 'data' => [ [ 'alt' => 'image alt', 'url' => 'http://image.jpg', 'caption' => 'Lorem ipsum dolor', 'isVideo' => true, 'source' => null, 'item-name' => null ] ] ] ], 'output' => '', 'description' => 'Only video', 'accentColor' => '', 'accentColorText' => '' ], [ 'input' => [ [ 'type' => 'navigation', 'data' => [ 'value' => 'navigation value', 'item-name' => null ] ] ], 'output' => '', 'description' => 'navigation only', 'accentColor' => '', 'accentColorText' => '' ], [ 'input' => [ [ 'type' => 'data', 'data' => [ 'label' => 'test label', 'value' => 'test value', 'source' => null, 'item-name' => null ] ] ], 'output' => '', 'description' => 'Only pair', 'accentColor' => '', 'accentColorText' => '' ], [ 'input' => [ [ 'type' => 'title', 'data' => [ 'value' => 'Test Title', 'source' => null, 'item-name' => null ] ], [ 'type' => 'media', 'data' => [ [ 'alt' => 'image alt', 'url' => 'http://image.jpg', 'width' => '400', 'height' => '200', 'thumbnail' => 'http://thumbnail.jpg', 'thumbnail2x' => 'http://thumbnail2x.jpg', 'isImage' => true, 'source' => null, 'item-name' => null ] ] ], [ 'type' => 'data', 'data' => [ 'label' => 'test label', 'value' => 'test value', 'source' => 'test', 'item-name' => null ] ] ], 'output' => '', 'description' => 'Simple infobox with title, image and key-value pair', 'accentColor' => '', 'accentColorText' => '' ], [ 'input' => [ [ 'type' => 'title', 'data' => [ 'value' => 'Test Title', 'source' => null, 'item-name' => null ] ], [ 'type' => 'media', 'data' => [] ], [ 'type' => 'data', 'data' => [ 'label' => 'test label', 'value' => 'test value', 'source' => null, 'item-name' => null ] ] ], 'output' => '', 'description' => 'Simple infobox with title, INVALID image and key-value pair', 'accentColor' => '', 'accentColorText' => '' ], [ 'input' => [ [ 'type' => 'title', 'data' => [ 'value' => 'Test Title', 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => 'test label', 'value' => 'test value', 'source' => null, 'item-name' => 'testname' ] ] ], 'output' => '', 'description' => 'Simple infobox with title, empty image and key-value pair', 'accentColor' => '', 'accentColorText' => '' ], [ 'input' => [ [ 'type' => 'title', 'data' => [ 'value' => 'Test Title', 'source' => null, 'item-name' => null ] ], [ 'type' => 'group', 'data' => [ 'value' => [ [ 'type' => 'header', 'data' => [ 'value' => 'Test Header', 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => 'test label', 'value' => 'test value', 'source' => null, 'item-name' => 'dataname' ] ], [ 'type' => 'data', 'data' => [ 'label' => 'test label', 'value' => 'test value', 'source' => 'datasrc', 'item-name' => null ] ] ], 'layout' => 'default', 'collapse' => null, 'row-items' => null, 'item-name' => null ] ] ], 'output' => '', 'description' => 'Infobox with title, group with header and two key-value pairs', 'accentColor' => '', 'accentColorText' => '' ], [ 'input' => [ [ 'type' => 'title', 'data' => [ 'value' => 'Test Title', 'source' => null, 'item-name' => null ] ], [ 'type' => 'group', 'data' => [ 'value' => [ [ 'type' => 'header', 'data' => [ 'value' => 'Test Header', 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => 'test label', 'value' => 'test value', 'source' => null, 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => 'test label', 'value' => 'test value', 'source' => null, 'item-name' => null ] ] ], 'layout' => 'default', 'collapse' => null, 'row-items' => null, 'item-name' => null ] ] ], 'output' => '', 'description' => 'Infobox with title, group with header and two key-value pairs, custom' . 'accent color and accent text color', 'accentColor' => '#FFF', 'accentColorText' => '#000' ], [ 'input' => [ [ 'type' => 'group', 'data' => [ 'value' => [ [ 'type' => 'header', 'data' => [ 'value' => 'Test header', 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => 'test label', 'value' => 'test value', 'source' => null, 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => 'test label', 'value' => 'test value', 'source' => null, 'item-name' => null ] ] ], 'layout' => 'horizontal', 'collapse' => null, 'row-items' => null, 'item-name' => null ] ] ], 'output' => '', 'description' => 'Infobox with horizontal group', 'accentColor' => '', 'accentColorText' => '' ], [ 'input' => [ [ 'type' => 'group', 'data' => [ 'value' => [ [ 'type' => 'data', 'data' => [ 'label' => '', 'value' => 'test value', 'source' => null, 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => '', 'value' => 'test value', 'source' => null, 'item-name' => null ] ] ], 'layout' => 'horizontal', 'collapse' => null, 'row-items' => null, 'item-name' => null ] ] ], 'output' => '', 'description' => 'Infobox with horizontal group without header and labels', 'accentColor' => '', 'accentColorText' => '' ], [ 'input' => [ [ 'type' => 'navigation', 'data' => [ 'value' => '
Links
', 'item-name' => null ] ] ], 'output' => '', 'description' => 'Infobox with navigation', 'accentColor' => '', 'accentColorText' => '' ], // horizontal group tests [ 'input' => [ [ 'type' => 'group', 'data' => [ 'value' => [ [ 'type' => 'data', 'data' => [ 'label' => 'test label 1', 'value' => 'test value 1', 'source' => null, 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => 'test label 2', 'value' => 'test value 2', 'source' => 'src', 'item-name' => 'name' ] ] ], 'layout' => 'horizontal', 'collapse' => null, 'row-items' => null, 'item-name' => null ] ] ], 'output' => '', 'description' => 'Horizontal group data without header', 'accentColor' => '', 'accentColorText' => '' ], [ 'input' => [ [ 'type' => 'group', 'data' => [ 'value' => [ [ 'type' => 'header', 'data' => [ 'value' => 'test header', 'source' => null, 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => '', 'value' => 'test value 1', 'source' => null, 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => 'test label 2', 'value' => 'test value 2', 'source' => null, 'item-name' => null ] ] ], 'layout' => 'horizontal', 'collapse' => null, 'row-items' => null, 'item-name' => null ] ] ], 'output' => '', 'description' => 'Horizontal group data with empty label', 'accentColor' => '', 'accentColorText' => '' ], [ 'input' => [ [ 'type' => 'group', 'data' => [ 'value' => [ [ 'type' => 'data', 'data' => [ 'label' => '', 'value' => 'test value 1', 'source' => null, 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => '', 'value' => 'test value 2', 'source' => null, 'item-name' => null ] ] ], 'layout' => 'horizontal', 'collapse' => null, 'row-items' => null, 'item-name' => null ] ] ], 'output' => '', 'description' => 'Horizontal group data with empty label', 'accentColor' => '', 'accentColorText' => '' ], [ 'input' => [ [ 'type' => 'group', 'data' => [ 'value' => [ [ 'type' => 'data', 'data' => [ 'label' => 'Test 1', 'value' => 'test value 1', 'span' => 1, 'layout' => null, 'source' => null, 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => 'Test 2', 'value' => 'test value 2', 'span' => 1, 'layout' => null, 'source' => null, 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => 'Test 3', 'value' => 'test value 3', 'span' => 1, 'layout' => null, 'source' => null, 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => 'Test 4', 'value' => 'test value 4', 'span' => 1, 'layout' => null, 'source' => null, 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => 'Test 5', 'value' => 'test value 5', 'span' => 1, 'layout' => null, 'source' => null, 'item-name' => null ] ] ], 'layout' => null, 'collapse' => null, 'row-items' => 3, 'item-name' => null ] ] ], 'output' => '', 'description' => 'Flex wrapped group of 5 elements with row size 3', 'accentColor' => '', 'accentColorText' => '' ], [ 'input' => [ [ 'type' => 'group', 'data' => [ 'value' => [ [ 'type' => 'data', 'data' => [ 'label' => 'Test 1', 'value' => 'test value 1', 'span' => 1, 'layout' => null, 'source' => null, 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => 'Test 2', 'value' => 'test value 2', 'span' => 1, 'layout' => null, 'source' => null, 'item-name' => 'test2' ] ], [ 'type' => 'data', 'data' => [ 'label' => 'Test 3', 'value' => 'test value 3', 'span' => 1, 'layout' => null, 'source' => 'test3', 'item-name' => 'test3' ] ], [ 'type' => 'data', 'data' => [ 'label' => 'Test 4', 'value' => 'test value 4', 'span' => 1, 'layout' => null, 'source' => 'test4', 'item-name' => 'test4' ] ] ], 'layout' => null, 'collapse' => null, 'row-items' => 3, 'item-name' => null ] ] ], 'output' => '', 'description' => 'Flex wrapped group of 4 elements with row size 3', 'accentColor' => '', 'accentColorText' => '' ], [ 'input' => [ [ 'type' => 'group', 'data' => [ 'value' => [ [ 'type' => 'data', 'data' => [ 'label' => 'Test 1', 'value' => 'test value 1', 'span' => 1, 'layout' => null, 'source' => null, 'item-name' => null ] ] ], 'layout' => null, 'collapse' => null, 'row-items' => 3, 'item-name' => null ] ] ], 'output' => '', 'description' => 'Flex wrapped group of a single element with row size 3', 'accentColor' => '', 'accentColorText' => '' ], [ 'input' => [ [ 'type' => 'group', 'data' => [ 'value' => [ [ 'type' => 'data', 'data' => [ 'label' => 'Test 1', 'value' => 'test value 1', 'span' => 2, 'layout' => null, 'source' => null, 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => 'Test 2', 'value' => 'test value 2', 'span' => 1, 'layout' => null, 'source' => null, 'item-name' => null ] ] ], 'layout' => null, 'collapse' => null, 'row-items' => 3, 'item-name' => null ] ] ], 'output' => '', 'description' => 'Flex wrapped group of 2 + 1 with row size 3', 'accentColor' => '', 'accentColorText' => '' ], [ 'input' => [ [ 'type' => 'group', 'data' => [ 'value' => [ [ 'type' => 'data', 'data' => [ 'label' => 'Test 1', 'value' => 'test value 1', 'span' => 2, 'layout' => null, 'source' => null, 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => 'Test 2', 'value' => 'test value 2', 'span' => 1, 'layout' => null, 'source' => null, 'item-name' => null ] ] ], 'layout' => null, 'collapse' => null, 'row-items' => 7, 'item-name' => null ] ] ], 'output' => '', 'description' => 'Flex wrapped group of 2 + 1 with row size 7', 'accentColor' => '', 'accentColorText' => '' ], [ 'input' => [ [ 'type' => 'group', 'data' => [ 'value' => [ [ 'type' => 'data', 'data' => [ 'label' => 'Test 1', 'value' => 'test value 1', 'span' => 2, 'layout' => null, 'source' => null, 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => 'Test 2', 'value' => 'test value 2', 'span' => 2, 'layout' => null, 'source' => null, 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => 'Test 3', 'value' => 'test value 3', 'span' => 2, 'layout' => null, 'source' => null, 'item-name' => null ] ] ], 'layout' => null, 'collapse' => null, 'row-items' => 3, 'item-name' => null ] ] ], 'output' => '', 'description' => 'Flex wrapped group of 2 + 2 + 2 with row size 3', 'accentColor' => '', 'accentColorText' => '' ], [ 'input' => [ [ 'type' => 'group', 'data' => [ 'value' => [ [ 'type' => 'data', 'data' => [ 'label' => 'Test 1', 'value' => 'test value 1', 'span' => 1, 'layout' => null, 'source' => null, 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => 'Test 2', 'value' => 'test value 2', 'span' => 1, 'layout' => null, 'source' => null, 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => 'Test 3', 'value' => 'test value 3', 'span' => null, 'layout' => 'default', 'source' => null, 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => 'Test 4', 'value' => 'test value 4', 'span' => 1, 'layout' => null, 'source' => null, 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => 'Test 5', 'value' => 'test value 5', 'span' => 1, 'layout' => null, 'source' => null, 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => 'Test 6', 'value' => 'test value 6', 'span' => 1, 'layout' => null, 'source' => null, 'item-name' => null ] ] ], 'layout' => null, 'collapse' => null, 'row-items' => 3, 'item-name' => null ] ] ], 'output' => '', 'description' => 'Flex wrapped group of 1 + 1 + default + 1 + 1 + 1 with row size 3', 'accentColor' => '', 'accentColorText' => '' ], [ 'input' => [ [ 'type' => 'group', 'data' => [ 'value' => [ [ 'type' => 'data', 'data' => [ 'label' => 'Test 1', 'value' => 'test value 1', 'span' => 1, 'layout' => null, 'source' => null, 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => 'Test 2', 'value' => 'test value 2', 'span' => 1, 'layout' => null, 'source' => null, 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => 'Test 3', 'value' => 'test value 3', 'span' => 1, 'layout' => null, 'source' => null, 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => 'Test 4', 'value' => 'test value 4', 'span' => 1, 'layout' => null, 'source' => null, 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => 'Test 5', 'value' => 'test value 5', 'span' => 1, 'layout' => null, 'source' => null, 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => 'Test 6', 'value' => 'test value 6', 'span' => null, 'layout' => 'default', 'source' => null, 'item-name' => null ] ] ], 'layout' => null, 'collapse' => null, 'row-items' => 3, 'item-name' => null ] ] ], 'output' => '', 'description' => 'Flex wrapped group of 1 + 1 + 1 + 1 + 1 + default with row size 3', 'accentColor' => '', 'accentColorText' => '' ], [ 'input' => [ [ 'type' => 'group', 'data' => [ 'value' => [ [ 'type' => 'data', 'data' => [ 'label' => 'Test 1', 'value' => 'test value 1', 'span' => 40, 'layout' => null, 'source' => null, 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => 'Test 2', 'value' => 'test value 2', 'span' => 1, 'layout' => null, 'source' => null, 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => 'Test 3', 'value' => 'test value 3', 'span' => 1, 'layout' => null, 'source' => null, 'item-name' => null ] ] ], 'layout' => null, 'collapse' => null, 'row-items' => 3, 'item-name' => null ] ] ], 'output' => '', 'description' => 'Flex wrapped group of 40 + 1 + 1 with row size 3', 'accentColor' => '', 'accentColorText' => '' ], [ 'input' => [ [ 'type' => 'group', 'data' => [ 'value' => [ [ 'type' => 'data', 'data' => [ 'label' => 'Test 1', 'value' => 'test value 1', 'span' => 1, 'layout' => null, 'source' => null, 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => 'Test 2', 'value' => 'test value 2', 'span' => 40, 'layout' => null, 'source' => null, 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => 'Test 3', 'value' => 'test value 3', 'span' => 1, 'layout' => null, 'source' => null, 'item-name' => null ] ] ], 'layout' => null, 'collapse' => null, 'row-items' => 3, 'item-name' => null ] ] ], 'output' => '', 'description' => 'Flex wrapped group of 1 + 40 + 1 with row size 3', 'accentColor' => '', 'accentColorText' => '' ], [ 'input' => [ [ 'type' => 'group', 'data' => [ 'value' => [ [ 'type' => 'data', 'data' => [ 'label' => 'Test 1', 'value' => 'test value 1', 'span' => 1, 'layout' => null, 'source' => null, 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => 'Test 2', 'value' => 'test value 2', 'span' => 1, 'layout' => null, 'source' => null, 'item-name' => null ] ], [ 'type' => 'title', 'data' => [ 'value' => 'title value', 'source' => null, 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => 'Test 3', 'value' => 'test value 3', 'span' => 1, 'layout' => null, 'source' => null, 'item-name' => null ] ] ], 'layout' => null, 'collapse' => null, 'row-items' => 3, 'item-name' => null ] ] ], 'output' => '', 'description' => 'Flex wrapped group of 1 + 1 + title + 1 with row size 3', 'accentColor' => '', 'accentColorText' => '' ], [ 'input' => [ [ 'type' => 'group', 'data' => [ 'value' => [ [ 'type' => 'data', 'data' => [ 'label' => null, 'value' => 'test value 1', 'span' => 1, 'layout' => null, 'source' => null, 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => null, 'value' => 'test value 2', 'span' => 1, 'layout' => null, 'source' => null, 'item-name' => null ] ], [ 'type' => 'title', 'data' => [ 'value' => 'title value', 'source' => null, 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => null, 'value' => 'test value 3', 'span' => 1, 'layout' => null, 'source' => null, 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => 'Test 4', 'value' => 'test value 4', 'span' => 1, 'layout' => null, 'source' => null, 'item-name' => null ] ] ], 'layout' => null, 'collapse' => null, 'row-items' => 3, 'item-name' => null ] ] ], 'output' => '', 'description' => 'Flex wrapped group of 1 (no label) + 1 (no label) + title + 1 (no label) + 1 with row size 3', 'accentColor' => '', 'accentColorText' => '' ], [ 'input' => [ [ 'type' => 'title', 'data' => [ 'value' => 'Test Title', 'source' => null, 'item-name' => null ] ], [ 'type' => 'media', 'data' => [ [ 'alt' => 'image alt', 'url' => 'http://image.jpg', 'caption' => 'caption', 'ref' => 1, 'width' => '400', 'height' => '200', 'thumbnail' => 'http://thumbnail.jpg', 'thumbnail2x' => 'http://thumbnail2x.jpg', 'isImage' => true, 'isFirst' => true, 'source' => 'src', 'item-name' => 'img' ], [ 'alt' => 'image alt', 'url' => 'http://image.jpg', 'caption' => 'caption', 'ref' => 2, 'width' => '400', 'height' => '200', 'thumbnail' => 'http://thumbnail.jpg', 'thumbnail2x' => 'http://thumbnail2x.jpg', 'isImage' => true, 'source' => 'src', 'item-name' => 'img' ] ] ] ], 'output' => '', 'description' => 'Simple infobox with title and image collection', 'accentColor' => '', 'accentColorText' => '' ], [ 'input' => [ [ 'type' => 'title', 'data' => [ 'value' => 'Test Title', 'source' => null, 'item-name' => null ] ], [ 'type' => 'group', 'data' => [ 'value' => [ [ 'type' => 'header', 'data' => [ 'value' => 'Test Header', 'source' => null, 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => 'test label', 'value' => 'test value', 'source' => null, 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => 'test label', 'value' => 'test value', 'source' => null, 'item-name' => null ] ] ], 'layout' => 'default', 'collapse' => 'open', 'row-items' => null, 'item-name' => null ] ] ], 'output' => '', 'description' => 'Infobox with title, collapsible group with header and two key-value pairs', 'accentColor' => '', 'accentColorText' => '' ], [ 'input' => [ [ 'type' => 'title', 'data' => [ 'value' => 'Test Title', 'source' => null, 'item-name' => null ] ], [ 'type' => 'group', 'data' => [ 'value' => [ [ 'type' => 'header', 'data' => [ 'value' => 'Test Header', 'item-name' => 'header' ] ], [ 'type' => 'data', 'data' => [ 'label' => 'test label', 'value' => 'test value', 'source' => null, 'item-name' => null ] ], [ 'type' => 'data', 'data' => [ 'label' => 'test label', 'value' => 'test value', 'source' => null, 'item-name' => null ] ] ], 'layout' => 'default', 'collapse' => 'closed', 'row-items' => null, 'item-name' => null ] ] ], 'output' => '', 'description' => 'Infobox with title, collapsed group with header and two key-value pairs', 'accentColor' => '', 'accentColorText' => '' ] ]; } // phpcs:enable }