From 9ceba1d2d0b5e6b3902d4e3490b780a8739f0c8e Mon Sep 17 00:00:00 2001 From: idradm Date: Wed, 20 Apr 2016 10:38:44 +0200 Subject: [PATCH] DAT-3942 make sure isVideo param is always set, update tests --- services/Parser/Nodes/NodeImage.php | 3 ++- tests/nodes/NodeImageTest.php | 28 +++++++++++++++------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/services/Parser/Nodes/NodeImage.php b/services/Parser/Nodes/NodeImage.php index f9b915b..4f41bca 100644 --- a/services/Parser/Nodes/NodeImage.php +++ b/services/Parser/Nodes/NodeImage.php @@ -152,7 +152,8 @@ class NodeImage extends Node { 'name' => $titleObj ? $titleObj->getText() : '', 'key' => $titleObj ? $titleObj->getDBKey() : '', 'alt' => $alt, - 'caption' => $caption + 'caption' => $caption, + 'isVideo' => false ]; if ( $this->isVideo( $fileObj ) ) { diff --git a/tests/nodes/NodeImageTest.php b/tests/nodes/NodeImageTest.php index 6af1cbf..29ef2c0 100644 --- a/tests/nodes/NodeImageTest.php +++ b/tests/nodes/NodeImageTest.php @@ -37,9 +37,8 @@ class NodeImageTest extends WikiaBaseTest { /** * @covers \Wikia\PortableInfobox\Parser\Nodes\NodeImage::getMarkers * @dataProvider markersProvider - * - * @param $markup - * @param $params + * @param $ext + * @param $value * @param $expected */ public function testMarkers( $ext, $value, $expected ) { @@ -62,7 +61,6 @@ class NodeImageTest extends WikiaBaseTest { } - /** * @covers \Wikia\PortableInfobox\Parser\Nodes\NodeImage::getData * @dataProvider dataProvider @@ -80,30 +78,30 @@ class NodeImageTest extends WikiaBaseTest { public function dataProvider() { // markup, params, expected return [ - [ + [ '', [ ], - [ [ 'url' => '', 'name' => '', 'key' => '', 'alt' => null, 'caption' => null ] ] + [ [ 'url' => '', 'name' => '', 'key' => '', 'alt' => null, 'caption' => null, 'isVideo' => false ] ] ], [ '', [ 'img' => 'test.jpg' ], - [ [ 'url' => '', 'name' => 'Test.jpg', 'key' => 'Test.jpg', 'alt' => null, 'caption' => null ] ] + [ [ 'url' => '', 'name' => 'Test.jpg', 'key' => 'Test.jpg', 'alt' => null, 'caption' => null, 'isVideo' => false ] ] ], [ 'test alt', [ 'img' => 'test.jpg' ], - [ [ 'url' => '', 'name' => 'Test.jpg', 'key' => 'Test.jpg', 'alt' => 'test alt', 'caption' => null ] ] + [ [ 'url' => '', 'name' => 'Test.jpg', 'key' => 'Test.jpg', 'alt' => 'test alt', 'caption' => null, 'isVideo' => false ] ] ], [ 'test alt', [ 'img' => 'test.jpg', 'alt source' => 2 ], - [ [ 'url' => '', 'name' => 'Test.jpg', 'key' => 'Test.jpg', 'alt' => 2, 'caption' => null ] ] + [ [ 'url' => '', 'name' => 'Test.jpg', 'key' => 'Test.jpg', 'alt' => 2, 'caption' => null, 'isVideo' => false ] ] ], [ 'test alt', [ 'img' => 'test.jpg' ], - [ [ 'url' => '', 'name' => 'Test.jpg', 'key' => 'Test.jpg', 'alt' => 'test alt', 'caption' => 'test.jpg' ] ] + [ [ 'url' => '', 'name' => 'Test.jpg', 'key' => 'Test.jpg', 'alt' => 'test alt', 'caption' => 'test.jpg', 'isVideo' => false ] ] ], ]; } @@ -167,13 +165,17 @@ class NodeImageTest extends WikiaBaseTest { /** * @dataProvider testVideoProvider + * @param $markup + * @param $params + * @param $expected + * @throws \Wikia\PortableInfobox\Parser\XmlMarkupParseErrorException */ public function testVideo( $markup, $params, $expected ) { global $wgHooks; // backup the hooks - $tmpHooks = $wgHooks['PortableInfoboxNodeImage::getData']; - $wgHooks['PortableInfoboxNodeImage::getData'] = []; + $tmpHooks = $wgHooks[ 'PortableInfoboxNodeImage::getData' ]; + $wgHooks[ 'PortableInfoboxNodeImage::getData' ] = [ ]; $fileMock = new FileMock(); $xmlObj = Wikia\PortableInfobox\Parser\XmlParser::parseXmlString( $markup ); @@ -185,7 +187,7 @@ class NodeImageTest extends WikiaBaseTest { $this->assertEquals( $expected, $nodeImage->getData() ); // restore the hooks - $wgHooks['PortableInfoboxNodeImage::getData'] = $tmpHooks; + $wgHooks[ 'PortableInfoboxNodeImage::getData' ] = $tmpHooks; } public function testVideoProvider() {