infoboxRenderService = new PortableInfoboxRenderService(); } /** * @param $input * @param $expectedOutput * @param $description * @dataProvider testRenderInfoboxDataProvider */ public function testRenderInfobox( $input, $expectedOutput, $description ) { $actualOutput = $this->infoboxRenderService->renderInfobox( $input ); $actualDOM = new DOMDocument('1.0'); $expectedDOM = new DOMDocument('1.0'); $actualDOM->formatOutput = true; $actualDOM->preserveWhiteSpace = false; $expectedDOM->formatOutput = true; $expectedDOM->preserveWhiteSpace = false; $actualDOM->loadXML($actualOutput); $expectedDOM->loadXML($expectedOutput); $this->assertEquals( $expectedDOM->saveXML(), $actualDOM->saveXML(), $description ); } public function testRenderInfoboxDataProvider() { return [ [ 'input' => [], 'output' => '', 'description' => 'Empty data should yield no infobox markup' ], [ 'input' => [ [ 'type' => 'title', 'data' => [ 'value' => 'Test Title' ], 'isEmpty' => false ] ], 'output' => '', 'description' => 'Only title' ], [ 'input' => [ [ 'type' => 'image', 'data' => [ 'alt' => 'image alt', 'value' => 'http://image.jpg' ], 'isEmpty' => false ] ], 'output' => '', 'description' => 'Only image' ], [ 'input' => [ [ 'type' => 'title', 'data' => [ 'value' => 'Test Title' ], 'isEmpty' => false ], [ 'type' => 'image', 'data' => [ 'alt' => 'image alt', 'value' => 'http://image.jpg' ], 'isEmpty' => false ], [ 'type' => 'pair', 'data' => [ 'label' => 'test label', 'value' => 'test value' ], 'isEmpty' => false ] ], 'output' => '', 'description' => 'Simple infobox with title, image and key-value pair' ], [ 'input' => [ [ 'type' => 'title', 'data' => [ 'value' => 'Test Title' ], 'isEmpty' => false ], [ 'type' => 'image', 'data' => [], 'isEmpty' => true ], [ 'type' => 'pair', 'data' => [ 'label' => 'test label', 'value' => 'test value' ], 'isEmpty' => false ] ], 'output' => '', 'description' => 'Simple infobox with title, empty image and key-value pair' ] ]; } }