mirror of
https://github.com/Universal-Omega/PortableInfobox.git
synced 2024-11-15 11:59:56 +00:00
Fix unit tests
This commit is contained in:
parent
7fe3a39d1d
commit
ad17140243
|
@ -21,7 +21,7 @@ class PortableInfoboxImagesHelper {
|
|||
|
||||
// title param is provided through reference in WikiaFileHelper::getFileFromTitle
|
||||
$title = $data['name'];
|
||||
$file = \WikiaFileHelper::getFileFromTitle( $title );
|
||||
$file = $this->getFileFromTitle( $title );
|
||||
|
||||
if (
|
||||
!$file || !$file->exists() ||
|
||||
|
@ -130,4 +130,13 @@ class PortableInfoboxImagesHelper {
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Separated for overriding in unit testing
|
||||
* @param \Title|string $title
|
||||
* @return \File file
|
||||
*/
|
||||
protected function getFileFromTitle( $title ) {
|
||||
return \WikiaFileHelper::getFileFromTitle( $title );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -124,9 +124,9 @@ class NodeImage extends Node {
|
|||
'url' => $this->resolveImageUrl( $fileObj ),
|
||||
'name' => $titleObj ? $titleObj->getText() : '',
|
||||
'key' => $titleObj ? $titleObj->getDBKey() : '',
|
||||
'alt' => $alt ?: $titleObj ? $titleObj->getText() : '',
|
||||
'alt' => $alt ?? ( $titleObj ? $titleObj->getText() : null ),
|
||||
'caption' => \SanitizerBuilder::createFromType( 'image' )
|
||||
->sanitize( [ 'caption' => $caption ] )['caption'],
|
||||
->sanitize( [ 'caption' => $caption ] )['caption'] ?: null,
|
||||
'isVideo' => $this->isVideo( $fileObj )
|
||||
];
|
||||
|
||||
|
@ -168,11 +168,13 @@ class NodeImage extends Node {
|
|||
}
|
||||
|
||||
/**
|
||||
* NOTE: Protected to override in unit tests
|
||||
*
|
||||
* @desc get file object from title object
|
||||
* @param Title|null $title
|
||||
* @return File|null
|
||||
*/
|
||||
private function getFilefromTitle( $title ) {
|
||||
protected function getFilefromTitle( $title ) {
|
||||
return $title ? WikiaFileHelper::getFileFromTitle( $title ) : null;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,16 +1,21 @@
|
|||
<?php
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class InfoboxParamsValidatorTest extends TestCase {
|
||||
/**
|
||||
* @group PortableInfobox
|
||||
* @covers Wikia\PortableInfobox\Helpers\InfoboxParamsValidator
|
||||
*/
|
||||
class InfoboxParamsValidatorTest extends MediaWikiTestCase {
|
||||
/** @var \Wikia\PortableInfobox\Helpers\InfoboxParamsValidator $InfoboxParamsValidator */
|
||||
private $InfoboxParamsValidator;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
require_once __DIR__ . '/../services/Helpers/InfoboxParamsValidator.php';
|
||||
|
||||
$this->InfoboxParamsValidator = new \Wikia\PortableInfobox\Helpers\InfoboxParamsValidator();
|
||||
}
|
||||
|
||||
protected function tearDown() {
|
||||
unset($this->InfoboxParamsValidator);
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $params
|
|
@ -1,6 +1,9 @@
|
|||
<?php
|
||||
|
||||
class MediaWikiParserTest extends WikiaBaseTest {
|
||||
/**
|
||||
* @group PortableInfobox
|
||||
* @covers Wikia\PortableInfobox\Parser\MediaWikiParserService
|
||||
*/
|
||||
class MediaWikiParserTest extends MediaWikiTestCase {
|
||||
|
||||
/** @var Parser */
|
||||
protected $parser;
|
||||
|
@ -9,10 +12,16 @@ class MediaWikiParserTest extends WikiaBaseTest {
|
|||
$this->parser = new Parser();
|
||||
$title = Title::newFromText( 'test' );
|
||||
$options = new ParserOptions();
|
||||
$options->setOption( 'wrapclass', false );
|
||||
$this->parser->startExternalParse( $title, $options, 'text', true );
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
unset($this->parser);
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
protected function parse( $wikitext, $params, $newline = false ) {
|
||||
$withVars = $this->parser->replaceVariables( $wikitext,
|
||||
$this->parser->getPreprocessor()->newCustomFrame( $params ) );
|
||||
|
@ -22,12 +31,13 @@ class MediaWikiParserTest extends WikiaBaseTest {
|
|||
return preg_replace( '|{{{.*}}}|Us', '', preg_replace( '|[\n\r]|Us', '', $parserOutput->getText() ) );
|
||||
}
|
||||
|
||||
/* Fails - it needs a modification in the core
|
||||
public function testAsideTagPWrappedDuringParsing() {
|
||||
$aside = "<aside></aside>";
|
||||
$result = ( new Parser() )->doBlockLevels( $aside, true );
|
||||
//parser adds new line at the end of block
|
||||
$this->assertEquals( $aside . "\n", $result );
|
||||
}
|
||||
} */
|
||||
|
||||
|
||||
/**
|
|
@ -2,12 +2,11 @@
|
|||
|
||||
use Wikia\PortableInfobox\Parser\Nodes\NodeFactory;
|
||||
|
||||
class PortableInfoboxDataServiceTest extends WikiaBaseTest {
|
||||
|
||||
protected function setUp() {
|
||||
$this->setupFile = dirname( __FILE__ ) . '/../PortableInfobox.setup.php';
|
||||
parent::setUp();
|
||||
}
|
||||
/**
|
||||
* @group PortableInfobox
|
||||
* @covers PortableInfoboxDataService
|
||||
*/
|
||||
class PortableInfoboxDataServiceTest extends MediaWikiTestCase {
|
||||
|
||||
/**
|
||||
* @param $id
|
|
@ -2,16 +2,24 @@
|
|||
|
||||
use Wikia\PortableInfobox\Helpers\PortableInfoboxImagesHelper;
|
||||
|
||||
class PortableInfoboxImagesHelperTest extends WikiaBaseTest {
|
||||
/**
|
||||
* @group PortableInfobox
|
||||
* @covers Wikia\PortableInfobox\Helpers\PortableInfoboxImagesHelper
|
||||
*/
|
||||
class PortableInfoboxImagesHelperTest extends MediaWikiTestCase {
|
||||
private $helper;
|
||||
private static $testCustomWidthLogicCount;
|
||||
|
||||
protected function setUp() {
|
||||
$this->setupFile = dirname( __FILE__ ) . '/../PortableInfobox.setup.php';
|
||||
parent::setUp();
|
||||
|
||||
$this->helper = new PortableInfoboxImagesHelper();
|
||||
}
|
||||
|
||||
protected function tearDown() {
|
||||
unset( $this->helper );
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc mocks WikiaFileHelper methods
|
||||
* @param array $input
|
||||
|
@ -32,7 +40,7 @@ class PortableInfoboxImagesHelperTest extends WikiaBaseTest {
|
|||
->method( 'getHeight' )
|
||||
->will( $this->returnValue( $fileHeight ) );
|
||||
|
||||
$this->mockStaticMethod( 'WikiaFileHelper', 'getFileFromTitle', $fileMock );
|
||||
//$this->mockStaticMethod( 'WikiaFileHelper', 'getFileFromTitle', $fileMock );
|
||||
|
||||
return $fileMock;
|
||||
}
|
||||
|
@ -110,19 +118,14 @@ class PortableInfoboxImagesHelperTest extends WikiaBaseTest {
|
|||
* @dataProvider customWidthProvider
|
||||
*/
|
||||
public function testCustomWidthLogic( $customWidth, $preferredWidth, $resultDimensions, $thumbnailDimensions, $thumbnail2xDimensions, $originalDimension ) {
|
||||
self::$testCustomWidthLogicCount++;
|
||||
$expected = [
|
||||
'name' => 'test',
|
||||
'ref' => null,
|
||||
'ref' => self::$testCustomWidthLogicCount,
|
||||
'thumbnail' => null,
|
||||
'thumbnail2x' => null,
|
||||
'key' => '',
|
||||
'media-type' => 'image',
|
||||
'width' => $resultDimensions[ 'width' ],
|
||||
'height' => $resultDimensions[ 'height' ],
|
||||
'originalHeight' => '',
|
||||
'originalWidth' => '',
|
||||
'fileName' => '',
|
||||
'dataAttrs' => '[]'
|
||||
'height' => $resultDimensions[ 'height' ]
|
||||
];
|
||||
$thumb = $this->getMockBuilder( 'ThumbnailImage' )
|
||||
->disableOriginalConstructor()
|
||||
|
@ -135,23 +138,22 @@ class PortableInfoboxImagesHelperTest extends WikiaBaseTest {
|
|||
$file->expects( $this->once() )->method( 'exists' )->will( $this->returnValue( true ) );
|
||||
$file->expects( $this->once() )->method( 'getWidth' )->will( $this->returnValue( $originalDimension[ 'width' ] ) );
|
||||
$file->expects( $this->once() )->method( 'getHeight' )->will( $this->returnValue( $originalDimension[ 'height' ] ) );
|
||||
$file->expects( $this->once() )->method( 'getMediaType' )->will( $this->returnValue( MEDIATYPE_BITMAP ) );
|
||||
$file->expects( $this->any() )->method( 'getMediaType' )->will( $this->returnValue( MEDIATYPE_BITMAP ) );
|
||||
|
||||
$file->expects( $this->any() )
|
||||
->method( 'transform' )
|
||||
->with( $this->logicalOr ( $this->equalTo( $thumbnailDimensions ), $this->equalTo( $thumbnail2xDimensions ) ) )
|
||||
->will( $this->returnValue( $thumb ) );
|
||||
$this->mockStaticMethod( 'WikiaFileHelper', 'getFileFromTitle', $file );
|
||||
$this->mockStaticMethod( 'Hooks', 'run', true );
|
||||
|
||||
$helper = $this->getMock( PortableInfoboxImagesHelper::class, [ 'getFileFromTitle' ] );
|
||||
$helper->expects( $this->any() )
|
||||
->method( 'getFileFromTitle' )
|
||||
->willReturn( $file );
|
||||
|
||||
$globals = new \Wikia\Util\GlobalStateWrapper( [
|
||||
'wgPortableInfoboxCustomImageWidth' => $customWidth
|
||||
] );
|
||||
global $wgPortableInfoboxCustomImageWidth;
|
||||
$wgPortableInfoboxCustomImageWidth = $customWidth;
|
||||
|
||||
$helper = new PortableInfoboxImagesHelper();
|
||||
$result = $globals->wrap( function () use ( $helper, $preferredWidth ) {
|
||||
return $helper->extendImageData( [ 'name' => 'test' ], $preferredWidth );
|
||||
} );
|
||||
$result = $helper->extendImageData( [ 'name' => 'test' ], $preferredWidth );
|
||||
|
||||
$this->assertEquals( $expected, $result );
|
||||
}
|
|
@ -1,7 +1,9 @@
|
|||
<?php
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class PortableInfoboxParserTagControllerTest extends TestCase {
|
||||
/**
|
||||
* @group PortableInfobox
|
||||
* @covers PortableInfoboxParserTagController
|
||||
*/
|
||||
class PortableInfoboxParserTagControllerTest extends MediaWikiTestCase {
|
||||
|
||||
/** @var Parser */
|
||||
protected $parser;
|
||||
|
@ -11,11 +13,6 @@ class PortableInfoboxParserTagControllerTest extends TestCase {
|
|||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
require_once __DIR__ . '/../controllers/PortableInfoboxParserTagController.class.php';
|
||||
|
||||
if ( !extension_loaded( 'mustache' ) ) {
|
||||
$this->markTestSkipped( '"mustache" PHP extension needs to be loaded!' );
|
||||
}
|
||||
|
||||
$this->parser = $this->setUpParser();
|
||||
$this->controller = new PortableInfoboxParserTagController();
|
||||
|
@ -191,7 +188,7 @@ class PortableInfoboxParserTagControllerTest extends TestCase {
|
|||
return [
|
||||
[
|
||||
'params' => [ 'accent-color-default' => '#fff' ],
|
||||
'expectedOutput' => '<aside class="portable-infobox pi-background pi-theme-wikia pi-layout-default">
|
||||
'expectedOutput' => '<aside class="portable-infobox pi-background pi-theme-default pi-layout-default">
|
||||
<h2 class="pi-item pi-item-spacing pi-title" style="background-color:#fff;">test</h2>
|
||||
</aside>',
|
||||
'text' => '<title><default>test</default></title>',
|
||||
|
@ -200,7 +197,7 @@ class PortableInfoboxParserTagControllerTest extends TestCase {
|
|||
],
|
||||
[
|
||||
'params' => [ 'accent-color-source' => 'color-source' ],
|
||||
'expectedOutput' => '<aside class="portable-infobox pi-background pi-theme-wikia pi-layout-default">
|
||||
'expectedOutput' => '<aside class="portable-infobox pi-background pi-theme-default pi-layout-default">
|
||||
<h2 class="pi-item pi-item-spacing pi-title" style="background-color:#000;">test</h2>
|
||||
</aside>',
|
||||
'text' => '<title><default>test</default></title>',
|
||||
|
@ -214,7 +211,7 @@ class PortableInfoboxParserTagControllerTest extends TestCase {
|
|||
'accent-color-default' => '#fff' ,
|
||||
'accent-color-source' => 'color-source'
|
||||
],
|
||||
'expectedOutput' => '<aside class="portable-infobox pi-background pi-theme-wikia pi-layout-default">
|
||||
'expectedOutput' => '<aside class="portable-infobox pi-background pi-theme-default pi-layout-default">
|
||||
<h2 class="pi-item pi-item-spacing pi-title" style="background-color:#000;">test</h2>
|
||||
</aside>',
|
||||
'text' => '<title><default>test</default></title>',
|
||||
|
@ -225,7 +222,7 @@ class PortableInfoboxParserTagControllerTest extends TestCase {
|
|||
],
|
||||
[
|
||||
'params' => [ 'accent-color-text-default' => '#fff' ],
|
||||
'expectedOutput' => '<aside class="portable-infobox pi-background pi-theme-wikia pi-layout-default">
|
||||
'expectedOutput' => '<aside class="portable-infobox pi-background pi-theme-default pi-layout-default">
|
||||
<h2 class="pi-item pi-item-spacing pi-title" style="color:#fff;">test</h2>
|
||||
</aside>',
|
||||
'text' => '<title><default>test</default></title>',
|
||||
|
@ -237,7 +234,7 @@ class PortableInfoboxParserTagControllerTest extends TestCase {
|
|||
'accent-color-text-default' => '#fff' ,
|
||||
'accent-color-text-source' => 'color-source'
|
||||
],
|
||||
'expectedOutput' => '<aside class="portable-infobox pi-background pi-theme-wikia pi-layout-default">
|
||||
'expectedOutput' => '<aside class="portable-infobox pi-background pi-theme-default pi-layout-default">
|
||||
<h2 class="pi-item pi-item-spacing pi-title" style="color:#000;">test</h2>
|
||||
</aside>',
|
||||
'text' => '<title><default>test</default></title>',
|
||||
|
@ -251,7 +248,7 @@ class PortableInfoboxParserTagControllerTest extends TestCase {
|
|||
'accent-color-text-default' => '#fff' ,
|
||||
'accent-color-text-source' => 'color-source'
|
||||
],
|
||||
'expectedOutput' => '<aside class="portable-infobox pi-background pi-theme-wikia pi-layout-default">
|
||||
'expectedOutput' => '<aside class="portable-infobox pi-background pi-theme-default pi-layout-default">
|
||||
<h2 class="pi-item pi-item-spacing pi-title" style="color:#000;">test</h2>
|
||||
</aside>',
|
||||
'text' => '<title><default>test</default></title>',
|
||||
|
@ -267,7 +264,7 @@ class PortableInfoboxParserTagControllerTest extends TestCase {
|
|||
'accent-color-default' => '#fff' ,
|
||||
'accent-color-source' => 'color-source2'
|
||||
],
|
||||
'expectedOutput' => '<aside class="portable-infobox pi-background pi-theme-wikia pi-layout-default">
|
||||
'expectedOutput' => '<aside class="portable-infobox pi-background pi-theme-default pi-layout-default">
|
||||
<h2 class="pi-item pi-item-spacing pi-title" style="background-color:#001;color:#000;">test</h2>
|
||||
</aside>',
|
||||
'text' => '<title><default>test</default></title>',
|
||||
|
@ -284,7 +281,7 @@ class PortableInfoboxParserTagControllerTest extends TestCase {
|
|||
'accent-color-default' => 'fff' ,
|
||||
'accent-color-source' => 'color-source2'
|
||||
],
|
||||
'expectedOutput' => '<aside class="portable-infobox pi-background pi-theme-wikia pi-layout-default">
|
||||
'expectedOutput' => '<aside class="portable-infobox pi-background pi-theme-default pi-layout-default">
|
||||
<h2 class="pi-item pi-item-spacing pi-title" style="background-color:#001;color:#000;">test</h2>
|
||||
</aside>',
|
||||
'text' => '<title><default>test</default></title>',
|
||||
|
@ -343,7 +340,11 @@ class PortableInfoboxParserTagControllerTest extends TestCase {
|
|||
* @dataProvider moveFirstMarkerToTopDataProvider
|
||||
*/
|
||||
public function testMoveFirstMarkerToTop( $markers, $text, $expected ) {
|
||||
$this->controller->markers = $markers;
|
||||
$reflection = new ReflectionClass( $this->controller );
|
||||
$reflection_property = $reflection->getProperty( 'markers' );
|
||||
$reflection_property->setAccessible( true );
|
||||
$reflection_property->setValue( $this->controller, $markers );
|
||||
|
||||
$this->controller->moveFirstMarkerToTop( $text );
|
||||
$this->assertEquals( $expected, $text );
|
||||
}
|
|
@ -1,12 +1,9 @@
|
|||
<?php
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class PortableInfoboxParsingHelperTest extends TestCase {
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
require_once __DIR__ . '/../services/Helpers/PortableInfoboxParsingHelper.php';
|
||||
}
|
||||
/**
|
||||
* @group PortableInfobox
|
||||
* @covers Wikia\PortableInfobox\Helpers\PortableInfoboxParsingHelper
|
||||
*/
|
||||
class PortableInfoboxParsingHelperTest extends MediaWikiTestCase {
|
||||
|
||||
/**
|
||||
* @dataProvider parsingIncludeonlyInfoboxesDataProvider
|
||||
|
@ -48,9 +45,10 @@ class PortableInfoboxParsingHelperTest extends TestCase {
|
|||
]
|
||||
]
|
||||
],
|
||||
[ '<includeonly></includeonly><infobox></infobox>', false ],
|
||||
[ '<noinclude><infobox></infobox></noinclude>', false ],
|
||||
[ '<onlyinclude></onlyinclude><infobox></infobox>', false ],
|
||||
[
|
||||
'<includeonly><infobox></infobox></includeonly> ',
|
||||
'<includeonly></includeonly><infobox></infobox>',
|
||||
[
|
||||
[
|
||||
'parser_tag_version' => PortableInfoboxParserTagController::PARSER_TAG_VERSION,
|
|
@ -1,28 +1,9 @@
|
|||
<?php
|
||||
|
||||
class PortableInfoboxRenderServiceTest extends WikiaBaseTest {
|
||||
|
||||
protected function setUp() {
|
||||
$this->setupFile = dirname( __FILE__ ) . '/../PortableInfobox.setup.php';
|
||||
parent::setUp();
|
||||
|
||||
if ( !extension_loaded( 'mustache' ) ) {
|
||||
$this->markTestSkipped( '"mustache" PHP extension needs to be loaded!' );
|
||||
}
|
||||
}
|
||||
|
||||
private function mockInfoboxRenderServiceHelper( $input ) {
|
||||
$extendImageData = isset( $input['extendImageData'] ) ? $input['extendImageData'] : null;
|
||||
|
||||
$mock = $this->getMockBuilder( 'Wikia\PortableInfobox\Helpers\PortableInfoboxImagesHelper' )
|
||||
->setMethods( [ 'extendImageData' ] )
|
||||
->getMock();
|
||||
$mock->expects( $this->any() )
|
||||
->method( 'extendImageData' )
|
||||
->will( $this->returnValue( $extendImageData ) );
|
||||
|
||||
$this->mockClass( 'Wikia\PortableInfobox\Helpers\PortableInfoboxImagesHelper', $mock );
|
||||
}
|
||||
/**
|
||||
* @group PortableInfobox
|
||||
* @covers PortableInfoboxParserTagController
|
||||
*/
|
||||
class PortableInfoboxRenderServiceTest extends MediaWikiTestCase {
|
||||
|
||||
/**
|
||||
* @param $html
|
||||
|
@ -215,9 +196,14 @@ class PortableInfoboxRenderServiceTest extends WikiaBaseTest {
|
|||
* @dataProvider renderInfoboxDataProvider
|
||||
*/
|
||||
public function testRenderInfobox( $input, $expectedOutput, $description, $mockParams, $accentColor, $accentColorText ) {
|
||||
$this->mockInfoboxRenderServiceHelper( $mockParams );
|
||||
|
||||
$infoboxRenderService = new PortableInfoboxRenderService();
|
||||
DummyPIImageHelper::$imageData = $mockParams ? $mockParams[ 'extendImageData' ] : [];
|
||||
|
||||
$reflection = new ReflectionClass( $infoboxRenderService );
|
||||
$reflection_property = $reflection->getProperty( 'helper' );
|
||||
$reflection_property->setAccessible( true );
|
||||
$reflection_property->setValue( $infoboxRenderService, new DummyPIImageHelper() );
|
||||
|
||||
$actualOutput = $infoboxRenderService->renderInfobox( $input, '', '', $accentColor, $accentColorText );
|
||||
$expectedHtml = $this->normalizeHTML( $expectedOutput );
|
||||
$actualHtml = $this->normalizeHTML( $actualOutput );
|
||||
|
@ -289,7 +275,7 @@ class PortableInfoboxRenderServiceTest extends WikiaBaseTest {
|
|||
<figure class="pi-item pi-image">
|
||||
<a href="http://image.jpg" class="image image-thumbnail" title="image alt">
|
||||
<img src="http://thumbnail.jpg" srcset="http://thumbnail.jpg 1x, http://thumbnail2x.jpg 2x" class="pi-image-thumbnail" alt="image alt"
|
||||
width="400" height="200" data-image-key="image" data-image-name="image"/>
|
||||
width="400" height="200"/>
|
||||
</a>
|
||||
<figcaption class="pi-item-spacing pi-caption">Lorem ipsum dolor</figcaption>
|
||||
</figure>
|
||||
|
@ -331,24 +317,11 @@ class PortableInfoboxRenderServiceTest extends WikiaBaseTest {
|
|||
]
|
||||
],
|
||||
'output' => '<aside class="portable-infobox pi-background">
|
||||
<figure class="pi-item pi-image">
|
||||
<figure class="pi-item pi-image pi-video">
|
||||
<a href="http://image.jpg"
|
||||
class="image image-thumbnail video video-thumbnail"
|
||||
title="image alt">
|
||||
<img src="http://thumbnail.jpg" srcset="http://thumbnail.jpg 1x, http://thumbnail2x.jpg 2x" class="pi-image-thumbnail"
|
||||
alt="image alt" width="400" height="200" data-video-key="image"
|
||||
data-video-name="image"/>
|
||||
<span class="thumbnail-play-icon-container">
|
||||
<svg class="thumbnail-play-icon" viewBox="0 0 180 180" width="100%" height="100%">
|
||||
<g fill="none" fill-rule="evenodd">
|
||||
<g opacity=".9" transform="rotate(90 75 90)">
|
||||
<g fill="#000" filter="url(#a)"><rect id="b" width="150" height="150" rx="75"></rect></g>
|
||||
<g fill="#FFF"><rect id="b" width="150" height="150" rx="75"></rect></g>
|
||||
</g>
|
||||
<path fill="#00D6D6" fill-rule="nonzero" d="M80.87 58.006l34.32 25.523c3.052 2.27 3.722 6.633 1.496 9.746a6.91 6.91 0 0 1-1.497 1.527l-34.32 25.523c-3.053 2.27-7.33 1.586-9.558-1.527A7.07 7.07 0 0 1 70 114.69V63.643c0-3.854 3.063-6.977 6.84-6.977 1.45 0 2.86.47 4.03 1.34z"></path>
|
||||
</g>
|
||||
</svg>
|
||||
</span>
|
||||
<video src="http://image.jpg" class="pi-video-player" controls="true" controlsList="nodownload" preload="metadata">image alt</video>
|
||||
</a>
|
||||
<figcaption class="pi-item-spacing pi-caption">Lorem ipsum dolor</figcaption>
|
||||
</figure>
|
||||
|
@ -359,15 +332,7 @@ class PortableInfoboxRenderServiceTest extends WikiaBaseTest {
|
|||
'alt' => 'image alt',
|
||||
'url' => 'http://image.jpg',
|
||||
'caption' => 'Lorem ipsum dolor',
|
||||
'name' => 'image',
|
||||
'key' => 'image',
|
||||
'width' => '400',
|
||||
'height' => '200',
|
||||
'thumbnail' => 'http://thumbnail.jpg',
|
||||
'thumbnail2x' => 'http://thumbnail2x.jpg',
|
||||
'media-type' => 'video',
|
||||
'isVideo' => true,
|
||||
'duration' => '1:20'
|
||||
'isVideo' => true
|
||||
]
|
||||
],
|
||||
'accentColor' => '',
|
||||
|
@ -444,7 +409,7 @@ class PortableInfoboxRenderServiceTest extends WikiaBaseTest {
|
|||
<figure class="pi-item pi-image">
|
||||
<a href="http://image.jpg" class="image image-thumbnail" title="image alt">
|
||||
<img src="http://thumbnail.jpg" srcset="http://thumbnail.jpg 1x, http://thumbnail2x.jpg 2x" class="pi-image-thumbnail" alt="image alt"
|
||||
width="400" height="200" data-image-key="image" data-image-name="image"/>
|
||||
width="400" height="200"/>
|
||||
</a>
|
||||
</figure>
|
||||
<div class="pi-item pi-data pi-item-spacing pi-border-color">
|
||||
|
@ -1806,3 +1771,10 @@ class PortableInfoboxRenderServiceTest extends WikiaBaseTest {
|
|||
];
|
||||
}
|
||||
}
|
||||
|
||||
class DummyPIImageHelper {
|
||||
static $imageData = [];
|
||||
public function extendImageData( $imageData ) {
|
||||
return self::$imageData;
|
||||
}
|
||||
}
|
|
@ -1,22 +1,18 @@
|
|||
<?php
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Wikia\PortableInfobox\Helpers\PortableInfoboxMustacheEngine;
|
||||
|
||||
class PortableInfoboxMustacheEngineTest extends TestCase {
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
require_once __DIR__ . '/../services/Helpers/PortableInfoboxMustacheEngine.php';
|
||||
}
|
||||
/**
|
||||
* @group PortableInfobox
|
||||
* @covers Wikia\PortableInfobox\Helpers\PortableInfoboxTemplateEngine
|
||||
*/
|
||||
class PortableInfoboxTemplateEngineTest extends MediaWikiTestCase {
|
||||
|
||||
/**
|
||||
* @covers PortableInfoboxMustacheEngine::isSupportedType
|
||||
* @covers Wikia\PortableInfobox\Helpers\PortableInfoboxTemplateEngine::isSupportedType
|
||||
* @dataProvider isTypeSupportedInTemplatesDataProvider
|
||||
*/
|
||||
public function testIsTypeSupportedInTemplates( $type, $result, $description ) {
|
||||
$this->assertEquals(
|
||||
$result,
|
||||
PortableInfoboxMustacheEngine::isSupportedType( $type ),
|
||||
Wikia\PortableInfobox\Helpers\PortableInfoboxTemplateEngine::isSupportedType( $type ),
|
||||
$description
|
||||
);
|
||||
}
|
||||
|
@ -36,5 +32,4 @@ class PortableInfoboxMustacheEngineTest extends TestCase {
|
|||
];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -1,11 +1,9 @@
|
|||
<?php
|
||||
|
||||
class XmlParserTest extends WikiaBaseTest {
|
||||
|
||||
protected function setUp() {
|
||||
$this->setupFile = dirname( __FILE__ ) . '/../PortableInfobox.setup.php';
|
||||
parent::setUp();
|
||||
}
|
||||
/**
|
||||
* @group PortableInfobox
|
||||
* @covers \Wikia\PortableInfobox\Parser\XmlParser
|
||||
*/
|
||||
class XmlParserTest extends MediaWikiTestCase {
|
||||
|
||||
/** @dataProvider contentTagsDataProvider */
|
||||
public function testXHTMLParsing( $tag, $content ) {
|
|
@ -1,13 +1,12 @@
|
|||
<?php
|
||||
|
||||
class NodeDataTest extends WikiaBaseTest {
|
||||
protected function setUp() {
|
||||
$this->setupFile = dirname( __FILE__ ) . '/../../PortableInfobox.setup.php';
|
||||
parent::setUp();
|
||||
}
|
||||
/**
|
||||
* @group PortableInfobox
|
||||
* @covers \Wikia\PortableInfobox\Parser\Nodes\Node
|
||||
*/
|
||||
class NodeDataTest extends MediaWikiTestCase {
|
||||
|
||||
/**
|
||||
* @covers \Wikia\PortableInfobox\Parser\Nodes\Node::getSource
|
||||
* @covers \Wikia\PortableInfobox\Parser\Nodes\Node::getSources
|
||||
* @dataProvider sourceDataProvider
|
||||
*
|
||||
* @param $markup
|
|
@ -1,10 +1,9 @@
|
|||
<?php
|
||||
|
||||
class NodeGroupTest extends WikiaBaseTest {
|
||||
protected function setUp() {
|
||||
$this->setupFile = dirname( __FILE__ ) . '/../../PortableInfobox.setup.php';
|
||||
parent::setUp();
|
||||
}
|
||||
/**
|
||||
* @group PortableInfobox
|
||||
* @covers \Wikia\PortableInfobox\Parser\Nodes\NodeGroup
|
||||
*/
|
||||
class NodeGroupTest extends MediaWikiTestCase {
|
||||
|
||||
/**
|
||||
* @covers \Wikia\PortableInfobox\Parser\Nodes\NodeGroup::getData
|
|
@ -3,10 +3,17 @@
|
|||
use Wikia\PortableInfobox\Helpers\PortableInfoboxDataBag;
|
||||
use Wikia\PortableInfobox\Parser\Nodes\NodeImage;
|
||||
|
||||
class NodeImageTest extends WikiaBaseTest {
|
||||
/**
|
||||
* @group PortableInfobox
|
||||
* @covers \Wikia\PortableInfobox\Parser\Nodes\NodeImage
|
||||
*/
|
||||
class NodeImageTest extends MediaWikiTestCase {
|
||||
|
||||
protected function setUp() {
|
||||
$this->setupFile = dirname( __FILE__ ) . '/../../PortableInfobox.setup.php';
|
||||
parent::setUp();
|
||||
|
||||
global $wgUseInstantCommons;
|
||||
$wgUseInstantCommons = false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,24 +33,24 @@ class NodeImageTest extends WikiaBaseTest {
|
|||
"'\"`UNIQabcd-gAlLeRy-3-QINU`\"'"
|
||||
];
|
||||
PortableInfoboxDataBag::getInstance()->setGallery( $markers[0],
|
||||
['images' => [
|
||||
new GalleryMock([
|
||||
[
|
||||
'name' => 'image0_name.jpg',
|
||||
'caption' => 'image0_caption'
|
||||
'image0_name.jpg',
|
||||
'image0_caption'
|
||||
],
|
||||
[
|
||||
'name' => 'image01_name.jpg',
|
||||
'caption' => 'image01_caption'
|
||||
'image01_name.jpg',
|
||||
'image01_caption'
|
||||
],
|
||||
]]);
|
||||
]));
|
||||
PortableInfoboxDataBag::getInstance()->setGallery( $markers[1],
|
||||
['images' => [
|
||||
new GalleryMock([
|
||||
[
|
||||
'name' => 'image1_name.jpg',
|
||||
'caption' => 'image1_caption'
|
||||
'image1_name.jpg',
|
||||
'image1_caption'
|
||||
]
|
||||
]]);
|
||||
PortableInfoboxDataBag::getInstance()->setGallery( $markers[2], [ 'images' => [] ]);
|
||||
]));
|
||||
PortableInfoboxDataBag::getInstance()->setGallery( $markers[2], new GalleryMock() );
|
||||
|
||||
return [
|
||||
[
|
||||
|
@ -79,11 +86,11 @@ class NodeImageTest extends WikiaBaseTest {
|
|||
* @covers \Wikia\PortableInfobox\Parser\Nodes\NodeImage::getTabberData
|
||||
*/
|
||||
public function testTabberData() {
|
||||
$input = '<div class="tabber"><div class="tabbertab" title="_title_"><p><a><img data-image-key="_data-image-key_"></a></p></div></div>';
|
||||
$input = '<div class="tabber"><div class="tabbertab" title="_title_"><p><a><img src="_src_"></a></p></div></div>';
|
||||
$expected = [
|
||||
[
|
||||
'label' => '_title_',
|
||||
'title' => '_data-image-key_',
|
||||
'title' => '_src_',
|
||||
]
|
||||
];
|
||||
$this->assertEquals( $expected, NodeImage::getTabberData( $input ) );
|
||||
|
@ -104,17 +111,17 @@ class NodeImageTest extends WikiaBaseTest {
|
|||
return [
|
||||
[
|
||||
'TABBER',
|
||||
"<div>\x7f'\"`UNIQ123456789-tAbBeR-12345678-QINU`\"'\x7f</div>",
|
||||
[ "\x7f'\"`UNIQ123456789-tAbBeR-12345678-QINU`\"'\x7f" ]
|
||||
"<div>\x7f'\"`UNIQ--tAbBeR-12345678-QINU`\"'\x7f</div>",
|
||||
[ "\x7f'\"`UNIQ--tAbBeR-12345678-QINU`\"'\x7f" ]
|
||||
],
|
||||
[
|
||||
'GALLERY',
|
||||
"\x7f'\"`UNIQ123456789-tAbBeR-12345678-QINU`\"'\x7f<center>\x7f'\"`UNIQabcd-gAlLeRy-12345678-QINU`\"'\x7f</center>\x7f'\"`UNIQabcd-gAlLeRy-87654321-QINU`\"'\x7f",
|
||||
[ "\x7f'\"`UNIQabcd-gAlLeRy-12345678-QINU`\"'\x7f", "\x7f'\"`UNIQabcd-gAlLeRy-87654321-QINU`\"'\x7f" ]
|
||||
"\x7f'\"`UNIQ--tAbBeR-12345678-QINU`\"'\x7f<center>\x7f'\"`UNIQ--gAlLeRy-12345678-QINU`\"'\x7f</center>\x7f'\"`UNIQ--gAlLeRy-87654321-QINU`\"'\x7f",
|
||||
[ "\x7f'\"`UNIQ--gAlLeRy-12345678-QINU`\"'\x7f", "\x7f'\"`UNIQ--gAlLeRy-87654321-QINU`\"'\x7f" ]
|
||||
],
|
||||
[
|
||||
'GALLERY',
|
||||
"\x7f'\"`UNIQ123456789-somethingelse-12345678-QINU`\"'\x7f",
|
||||
"\x7f'\"`UNIQ--somethingelse-12345678-QINU`\"'\x7f",
|
||||
[ ]
|
||||
]
|
||||
];
|
||||
|
@ -146,7 +153,7 @@ class NodeImageTest extends WikiaBaseTest {
|
|||
[
|
||||
'<image source="img"></image>',
|
||||
[ 'img' => 'test.jpg' ],
|
||||
[ [ 'url' => '', 'name' => 'Test.jpg', 'key' => 'Test.jpg', 'alt' => null, 'caption' => null, 'isVideo' => false ] ]
|
||||
[ [ 'url' => '', 'name' => 'Test.jpg', 'key' => 'Test.jpg', 'alt' => 'Test.jpg', 'caption' => null, 'isVideo' => false ] ]
|
||||
],
|
||||
[
|
||||
'<image source="img"><alt><default>test alt</default></alt></image>',
|
||||
|
@ -258,10 +265,12 @@ class NodeImageTest extends WikiaBaseTest {
|
|||
$fileMock = new FileMock();
|
||||
$xmlObj = Wikia\PortableInfobox\Parser\XmlParser::parseXmlString( $markup );
|
||||
|
||||
$this->mockStaticMethod( 'WikiaFileHelper', 'getFileFromTitle', $fileMock );
|
||||
$nodeImage = new NodeImage( $xmlObj, $params );
|
||||
$mock = $this->getMock(NodeImage::class, [ 'getFilefromTitle' ], [ $xmlObj, $params ]);
|
||||
$mock->expects( $this->any( ))
|
||||
->method( 'getFilefromTitle' )
|
||||
->willReturn( $fileMock );
|
||||
|
||||
$this->assertEquals( $expected, $nodeImage->getData() );
|
||||
$this->assertEquals( $expected, $mock->getData() );
|
||||
}
|
||||
|
||||
public function videoProvider() {
|
||||
|
@ -274,10 +283,9 @@ class NodeImageTest extends WikiaBaseTest {
|
|||
'url' => 'http://test.url',
|
||||
'name' => 'Test.jpg',
|
||||
'key' => 'Test.jpg',
|
||||
'alt' => null,
|
||||
'alt' => 'Test.jpg',
|
||||
'caption' => null,
|
||||
'isVideo' => true,
|
||||
'duration' => '00:10'
|
||||
'isVideo' => true
|
||||
]
|
||||
]
|
||||
]
|
||||
|
@ -290,21 +298,18 @@ class FileMock {
|
|||
return "VIDEO";
|
||||
}
|
||||
|
||||
public function getMetadataDuration() {
|
||||
return 10;
|
||||
}
|
||||
|
||||
public function getUrl() {
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getTitle() {
|
||||
return new TitleMock();
|
||||
}
|
||||
}
|
||||
|
||||
class TitleMock {
|
||||
public function getFullURL() {
|
||||
return 'http://test.url';
|
||||
}
|
||||
}
|
||||
|
||||
class GalleryMock {
|
||||
private $images;
|
||||
public function __construct( Array $images = [] ) {
|
||||
$this->images = $images;
|
||||
}
|
||||
|
||||
public function getImages() {
|
||||
return $this->images;
|
||||
}
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
<?php
|
||||
|
||||
class NodeInfoboxTest extends WikiaBaseTest {
|
||||
protected function setUp() {
|
||||
$this->setupFile = dirname( __FILE__ ) . '/../../PortableInfobox.setup.php';
|
||||
parent::setUp();
|
||||
}
|
||||
/**
|
||||
* @group PortableInfobox
|
||||
* @covers \Wikia\PortableInfobox\Parser\Nodes\NodeInfobox
|
||||
*/
|
||||
class NodeInfoboxTest extends MediaWikiTestCase {
|
||||
|
||||
/**
|
||||
* @covers \Wikia\PortableInfobox\Parser\Nodes\NodeInfobox::getParams
|
|
@ -1,10 +1,9 @@
|
|||
<?php
|
||||
|
||||
class NodeNavigationTest extends WikiaBaseTest {
|
||||
protected function setUp() {
|
||||
$this->setupFile = dirname( __FILE__ ) . '/../../PortableInfobox.setup.php';
|
||||
parent::setUp();
|
||||
}
|
||||
/**
|
||||
* @group PortableInfobox
|
||||
* @covers \Wikia\PortableInfobox\Parser\Nodes\NodeNavigation
|
||||
*/
|
||||
class NodeNavigationTest extends MediaWikiTestCase {
|
||||
|
||||
/**
|
||||
* @covers \Wikia\PortableInfobox\Parser\Nodes\NodeNavigation::getData
|
|
@ -1,16 +1,22 @@
|
|||
<?php
|
||||
|
||||
class NodeDataSanitizerTest extends WikiaBaseTest {
|
||||
/**
|
||||
* @group PortableInfobox
|
||||
* @covers NodeDataSanitizer
|
||||
*/
|
||||
class NodeDataSanitizerTest extends MediaWikiTestCase {
|
||||
/** @var NodeDataSanitizer $sanitizer */
|
||||
private $sanitizer;
|
||||
|
||||
protected function setUp() {
|
||||
$this->setupFile = dirname( __FILE__ ) . '/../../PortableInfobox.setup.php';
|
||||
|
||||
$this->sanitizer = SanitizerBuilder::createFromType('data');
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
protected function tearDown() {
|
||||
unset( $sanitizer );
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @param $expected
|
|
@ -1,16 +1,22 @@
|
|||
<?php
|
||||
|
||||
class NodeHorizontalGroupSanitizerTest extends WikiaBaseTest {
|
||||
/**
|
||||
* @group PortableInfobox
|
||||
* @covers NodeDataSanitizer
|
||||
*/
|
||||
class NodeHorizontalGroupSanitizerTest extends MediaWikiTestCase {
|
||||
/** @var NodeHorizontalGroupSanitizer $sanitizer */
|
||||
private $sanitizer;
|
||||
|
||||
protected function setUp() {
|
||||
$this->setupFile = dirname( __FILE__ ) . '/../../PortableInfobox.setup.php';
|
||||
|
||||
$this->sanitizer = SanitizerBuilder::createFromType('horizontal-group-content');
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
protected function tearDown() {
|
||||
unset( $sanitizer );
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @param $expected
|
|
@ -1,16 +1,22 @@
|
|||
<?php
|
||||
|
||||
class NodeImageSanitizerTest extends WikiaBaseTest {
|
||||
/**
|
||||
* @group PortableInfobox
|
||||
* @covers NodeImageSanitizer
|
||||
*/
|
||||
class NodeImageSanitizerTest extends MediaWikiTestCase {
|
||||
/** @var NodeImageSanitizer $sanitizer */
|
||||
private $sanitizer;
|
||||
|
||||
protected function setUp() {
|
||||
$this->setupFile = dirname( __FILE__ ) . '/../../PortableInfobox.setup.php';
|
||||
|
||||
$this->sanitizer = SanitizerBuilder::createFromType( 'image' );
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
protected function tearDown() {
|
||||
unset( $sanitizer );
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @param $expected
|
|
@ -1,16 +1,22 @@
|
|||
<?php
|
||||
|
||||
class NodeTitleSanitizerTest extends WikiaBaseTest {
|
||||
/**
|
||||
* @group PortableInfobox
|
||||
* @covers NodeTitleSanitizer
|
||||
*/
|
||||
class NodeTitleSanitizerTest extends MediaWikiTestCase {
|
||||
/** @var NodeTitleSanitizer $sanitizer */
|
||||
private $sanitizer;
|
||||
|
||||
protected function setUp() {
|
||||
$this->setupFile = dirname( __FILE__ ) . '/../../PortableInfobox.setup.php';
|
||||
|
||||
$this->sanitizer = SanitizerBuilder::createFromType('title');
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
protected function tearDown() {
|
||||
unset( $sanitizer );
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @param $expected
|
|
@ -1,16 +1,22 @@
|
|||
<?php
|
||||
|
||||
class PassThroughSanitizerTest extends WikiaBaseTest {
|
||||
/**
|
||||
* @group PortableInfobox
|
||||
* @covers PassThroughSanitizer
|
||||
*/
|
||||
class PassThroughSanitizerTest extends MediaWikiTestCase {
|
||||
/** @var PassThroughSanitizer $sanitizer */
|
||||
private $sanitizer;
|
||||
|
||||
protected function setUp() {
|
||||
$this->setupFile = dirname( __FILE__ ) . '/../../PortableInfobox.setup.php';
|
||||
|
||||
$this->sanitizer = SanitizerBuilder::createFromType('invalid-type');
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
protected function tearDown() {
|
||||
unset( $sanitizer );
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @param $expected
|
Loading…
Reference in a new issue