setupFile = dirname( __FILE__ ) . '/../PortableInfobox.setup.php'; parent::setUp(); $mock = $this->getMock( 'PortableInfoboxRenderService', [ 'getThumbnailUrl' ] ); $mock->expects( $this->any() )->method( 'getThumbnailUrl' )->will( $this->returnValue( 'http://image.jpg' ) ); $this->infoboxRenderService = $mock; } /** * @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); $expectedHtml = $expectedDOM->saveXML(); $actualHtml = $actualDOM->saveXML(); $this->assertEquals( $expectedHtml, $actualHtml, $description ); } public function testRenderInfoboxDataProvider() { return [ [ 'input' => [], 'output' => '', 'description' => 'Empty data should yield no infobox markup' ], [ 'input' => [ [ 'type' => 'title', 'data' => [ 'value' => 'Test Title' ] ] ], 'output' => '', 'description' => 'Only title' ], [ 'input' => [ [ 'type' => 'footer', 'data' => [ 'value' => 'Footer value', ] ] ], 'output' => '', 'description' => 'Footer only' ], [ 'input' => [ [ 'type' => 'image', 'data' => [ 'alt' => 'image alt', 'url' => 'http://image.jpg' ] ] ], 'output' => '', 'description' => 'Only image' ], [ 'input' => [ [ 'type' => 'data', 'data' => [ 'label' => 'test label', 'value' => 'test value' ] ] ], 'output' => '', 'description' => 'Only pair' ], [ 'input' => [ [ 'type' => 'title', 'data' => [ 'value' => 'Test Title' ] ], [ 'type' => 'image', 'data' => [ 'alt' => 'image alt', 'value' => 'http://image.jpg' ] ], [ 'type' => 'data', 'data' => [ 'label' => 'test label', 'value' => 'test value' ] ] ], 'output' => '', 'description' => 'Simple infobox with title, image and key-value pair' ], [ 'input' => [ [ 'type' => 'title', 'data' => [ 'value' => 'Test Title' ] ], [ 'type' => 'data', 'data' => [ 'label' => 'test label', 'value' => 'test value' ] ] ], 'output' => '', 'description' => 'Simple infobox with title, empty image and key-value pair' ], [ 'input' => [ [ 'type' => 'title', 'data' => [ 'value' => 'Test Title' ] ], [ 'type' => 'group', 'data' => [ 'value' => [ [ 'type' => 'header', 'data' => [ 'value' => 'Test Header' ] ], [ 'type' => 'data', 'data' => [ 'label' => 'test label', 'value' => 'test value' ] ], [ 'type' => 'data', 'data' => [ 'label' => 'test label', 'value' => 'test value' ] ] ] ] ] ], 'output' => '', 'description' => 'Infobox with title, image and group with header two key-value pairs' ], [ 'input' => [ [ 'type' => 'comparison', 'data' => [ 'value' => [ [ 'type' => 'set', 'data' => [ 'value' => [ [ 'type' => 'header', 'data' => [ 'value' => 'Test Header' ] ], [ 'type' => 'data', 'data' => [ 'label' => 'test label', 'value' => 'test value' ] ], [ 'type' => 'data', 'data' => [ 'label' => 'test label', 'value' => 'test value' ] ] ] ] ], ], ] ] ], 'output' => '', 'description' => 'Infobox with comparison with two sets of which one is empty' ], [ 'input' => [ [ 'type' => 'footer', 'data' => [ 'value' => '
Links
' ] ] ], 'output' => '', 'description' => 'Infobox with footer' ] ]; } }