mirror of
https://github.com/Universal-Omega/PortableInfobox.git
synced 2024-11-15 11:59:56 +00:00
move sanitizeInfoboxTitle to renderService
This commit is contained in:
parent
3bea79bbe9
commit
6425ac0299
|
@ -4,24 +4,10 @@ namespace Wikia\PortableInfobox\Parser\Nodes;
|
|||
class NodeTitle extends Node {
|
||||
public function getData() {
|
||||
if ( !isset( $this->data ) ) {
|
||||
$title = $this->sanitizeInfoboxTitle( $this->getValueWithDefault( $this->xmlNode ) );
|
||||
|
||||
$title = $this->getValueWithDefault( $this->xmlNode );
|
||||
$this->data = [ 'value' => $title ];
|
||||
}
|
||||
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* removes all html tags from title
|
||||
*
|
||||
* @param $title
|
||||
* @return string
|
||||
*/
|
||||
public function sanitizeInfoboxTitle( $title ) {
|
||||
$title = strip_tags( $title );
|
||||
$title = trim( $title );
|
||||
|
||||
return $title;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ class PortableInfoboxRenderService extends WikiaService {
|
|||
const LOGGER_LABEL = 'portable-infobox-render-not-supported-type';
|
||||
const DESKTOP_THUMBNAIL_WIDTH = 270;
|
||||
const MOBILE_THUMBNAIL_WIDTH = 360;
|
||||
const MIN_BIG_IMAGE_WIDTH = 300;
|
||||
const MINIMAL_HERO_IMG_WIDTH = 300;
|
||||
const MOBILE_TEMPLATE_POSTFIX = '-mobile';
|
||||
|
||||
private $templates = [
|
||||
|
@ -120,6 +120,10 @@ class PortableInfoboxRenderService extends WikiaService {
|
|||
}
|
||||
}
|
||||
|
||||
if ( $type === 'title' && $this->isWikiaMobile() ) {
|
||||
$data[ 'value' ] = $this->sanitizeInfoboxTitle( $data[ 'value' ] );
|
||||
}
|
||||
|
||||
return $this->templateEngine->clearData()
|
||||
->setData( $data )
|
||||
->render( $this->templates[ $type ] );
|
||||
|
@ -199,7 +203,7 @@ class PortableInfoboxRenderService extends WikiaService {
|
|||
|
||||
/**
|
||||
* checks if infobox data item is valid hero component data.
|
||||
* If image is smaller than MIN_BIG_IMAGE_WIDTH const, don't render the hero module.
|
||||
* If image is smaller than MINIMAL_HERO_IMG_WIDTH const, doesn't render the hero module.
|
||||
*
|
||||
* @param array $item - infobox data item
|
||||
* @param array $heroData - hero component data
|
||||
|
@ -216,7 +220,7 @@ class PortableInfoboxRenderService extends WikiaService {
|
|||
if ( $type === 'image' && !array_key_exists( 'image', $heroData ) ) {
|
||||
$imageWidth = $this->getFileWidth( $item[ 'data' ][ 'name' ] );
|
||||
|
||||
if ( $imageWidth > self::MIN_BIG_IMAGE_WIDTH ) {
|
||||
if ( $imageWidth > self::MINIMAL_HERO_IMG_WIDTH ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -263,4 +267,17 @@ class PortableInfoboxRenderService extends WikiaService {
|
|||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* removes all html tags from title
|
||||
*
|
||||
* @param $title
|
||||
* @return string
|
||||
*/
|
||||
public function sanitizeInfoboxTitle( $title ) {
|
||||
$title = strip_tags( $title );
|
||||
$title = trim( $title );
|
||||
|
||||
return $title;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ class PortableInfoboxRenderServiceTest extends WikiaBaseTest {
|
|||
* 'getUrl', 'getWidth' and 'getHeight' functions. In case of small image return small image sizes.
|
||||
* @return PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private function getThumbnailImageMock( $input ) {
|
||||
private function getThumbnailImageMock() {
|
||||
|
||||
$mockThumbnailImage = $this->getMockBuilder( 'ThumbnailImage' )
|
||||
->setMethods( [ 'getUrl', 'getWidth', 'getHeight' ] )
|
||||
|
@ -452,4 +452,27 @@ class PortableInfoboxRenderServiceTest extends WikiaBaseTest {
|
|||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers PortableInfoboxRenderService::sanitizeInfoboxTitle
|
||||
* @dataProvider sanitizeInfoboxTitleSourceProvider
|
||||
*
|
||||
* @param $source string
|
||||
* @param $expected string
|
||||
*/
|
||||
public function testSanitizeInfoboxTitle( $source, $expected ) {
|
||||
$renderService = new PortableInfoboxRenderService();
|
||||
|
||||
$this->assertEquals( $expected, $renderService->sanitizeInfoboxTitle( $source ) );
|
||||
}
|
||||
|
||||
public function sanitizeInfoboxTitleSourceProvider() {
|
||||
return [
|
||||
[ 'Test Title' , 'Test Title'],
|
||||
[ ' Test Title ' , 'Test Title'],
|
||||
[ 'Test Title <img src=\'data:image/gif;base64,R0lGODlhAQABAIABAAAAAP///yH5BAEAAAEALAAAAAABAAEAQAICTAEAOw%3D%3D\' class=\'article-media\' data-ref=\'1\' width=\'400\' height=\'100\' /> ' , 'Test Title'],
|
||||
[ 'Test Title <a href="example.com">with link</a>' , 'Test Title with link'],
|
||||
[ 'Real world <a href="http://vignette-poz.wikia-dev.com/mediawiki116/images/b/b6/DBGT_Logo.svg/revision/latest?cb=20150601155347" class="image image-thumbnail" ><img src="http://vignette-poz.wikia-dev.com/mediawiki116/images/b/b6/DBGT_Logo.svg/revision/latest/scale-to-width-down/30?cb=20150601155347" alt="DBGT Logo" class="" data-image-key="DBGT_Logo.svg" data-image-name="DBGT Logo.svg" width="30" height="18" ></a>title example' , 'Real world title example']
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
class NodeTitleTest extends WikiaBaseTest {
|
||||
protected function setUp() {
|
||||
$this->setupFile = dirname( __FILE__ ) . '/../../PortableInfobox.setup.php';
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers NodeTitle::sanitizeInfoboxTitle
|
||||
* @dataProvider sourceProvider
|
||||
*
|
||||
* @param $source string
|
||||
* @param $expected string
|
||||
*/
|
||||
public function testSanitizeInfoboxTitle( $source, $expected ) {
|
||||
$markup = '<title></title>';
|
||||
$node = \Wikia\PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, [ ] );
|
||||
|
||||
$this->assertEquals( $expected, $node->sanitizeInfoboxTitle( $source ) );
|
||||
}
|
||||
|
||||
public function sourceProvider() {
|
||||
return [
|
||||
[ 'Test Title' , 'Test Title'],
|
||||
[ ' Test Title ' , 'Test Title'],
|
||||
[ 'Test Title <img src=\'data:image/gif;base64,R0lGODlhAQABAIABAAAAAP///yH5BAEAAAEALAAAAAABAAEAQAICTAEAOw%3D%3D\' class=\'article-media\' data-ref=\'1\' width=\'400\' height=\'100\' /> ' , 'Test Title'],
|
||||
[ 'Test Title <a href="example.com">with link</a>' , 'Test Title with link'],
|
||||
[ 'Real world <a href="http://vignette-poz.wikia-dev.com/mediawiki116/images/b/b6/DBGT_Logo.svg/revision/latest?cb=20150601155347" class="image image-thumbnail" ><img src="http://vignette-poz.wikia-dev.com/mediawiki116/images/b/b6/DBGT_Logo.svg/revision/latest/scale-to-width-down/30?cb=20150601155347" alt="DBGT Logo" class="" data-image-key="DBGT_Logo.svg" data-image-name="DBGT Logo.svg" width="30" height="18" ></a>title example' , 'Real world title example']
|
||||
];
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue