don't render image inside hero module title

This commit is contained in:
Diana 2015-07-21 23:13:28 +00:00
parent 6425ac0299
commit cf22303f9d
2 changed files with 114 additions and 29 deletions

View file

@ -120,8 +120,8 @@ class PortableInfoboxRenderService extends WikiaService {
} }
} }
if ( $type === 'title' && $this->isWikiaMobile() ) { if ( $this->isWikiaMobile() ) {
$data[ 'value' ] = $this->sanitizeInfoboxTitle( $data[ 'value' ] ); $data = $this->sanitizeInfoboxTitle( $type, $data );
} }
return $this->templateEngine->clearData() return $this->templateEngine->clearData()
@ -269,15 +269,23 @@ class PortableInfoboxRenderService extends WikiaService {
} }
/** /**
* removes all html tags from title * checks if infobox item is the title or title inside the hero module
* and if so, removes from it all HTML tags.
* *
* @param $title * @param $type type of infobox item
* @return string * @param $data infobox item data
* @return infobox $data with sanitized title param if needed
*/ */
public function sanitizeInfoboxTitle( $title ) { public function sanitizeInfoboxTitle( $type, $data ) {
$title = strip_tags( $title ); if ( $type === 'title' && !empty( $data['value'] ) ) {
$title = trim( $title ); $data['value'] = trim( strip_tags( $data['value'] ) );
return $data;
}
if ( $type === 'hero-mobile' && !empty( $data['title']['value'] ) ) {
$data['title']['value'] = trim( strip_tags( $data['title']['value'] ) );
return $data;
}
return $title; return $data;
} }
} }

View file

@ -449,6 +449,79 @@ class PortableInfoboxRenderServiceTest extends WikiaBaseTest {
</div> </div>
</aside>', </aside>',
'description' => 'Mobile: Simple infobox with title, INVALID image and key-value pair' 'description' => 'Mobile: Simple infobox with title, INVALID image and key-value pair'
],
[
'input' => [
'isInvalidImage' => true,
'isWikiaMobile' => true,
[
'type' => 'title',
'data' => [
'value' => 'Test Title'
]
],
[
'type' => 'image',
'data' => []
],
[
'type' => 'data',
'data' => [
'label' => 'test label',
'value' => 'test value'
]
]
],
'output' => '<aside class="portable-infobox">
<div class="portable-infobox-item item-type-title portable-infobox-item-margins">
<h2 class="portable-infobox-title">Test Title</h2>
</div>
<div class="portable-infobox-item item-type-key-val portable-infobox-item-margins">
<h3 class="portable-infobox-item-label portable-infobox-secondary-font">test label</h3>
<div class="portable-infobox-item-value">test value</div>
</div>
</aside>',
'description' => 'Mobile: Simple infobox with title, INVALID image and key-value pair'
],
[
'input' => [
'isWikiaMobile' => true,
'fileWidth' => '450',
[
'type' => 'title',
'data' => [
'value' => 'Test <img /><a href="example.com">Title</a>'
]
],
[
'type' => 'image',
'data' => [
'url' => 'http://image.jpg',
'thumbnail' => 'thumbnail.jpg',
'ref' => 44
]
],
[
'type' => 'data',
'data' => [
'label' => 'test label',
'value' => 'test value'
]
]
],
'output' => '<aside class="portable-infobox">
<div class="portable-infobox-item item-type-hero">
<hgroup class="portable-infobox-hero-title-wrapper portable-infobox-item-margins">
<h2 class="portable-infobox-hero-title">Test Title</h2>
</hgroup>
<img src="data:image/gif;base64,R0lGODlhAQABAIABAAAAAP///yH5BAEAAAEALAAAAAABAAEAQAICTAEAOw%3D%3D" data-src="http://image.jpg" class="portable-infobox-image lazy media article-media" alt="" data-image-key="" data-image-name="" data-ref="44" data-params=\'[{"name":"", "full":"http://image.jpg"}]\'/>
</div>
<div class="portable-infobox-item item-type-key-val portable-infobox-item-margins">
<h3 class="portable-infobox-item-label portable-infobox-secondary-font">test label</h3>
<div class="portable-infobox-item-value">test value</div>
</div>
</aside>',
'description' => 'Mobile: Infobox with title with HTML tags, image and key-value pair'
] ]
]; ];
} }
@ -457,22 +530,26 @@ class PortableInfoboxRenderServiceTest extends WikiaBaseTest {
* @covers PortableInfoboxRenderService::sanitizeInfoboxTitle * @covers PortableInfoboxRenderService::sanitizeInfoboxTitle
* @dataProvider sanitizeInfoboxTitleSourceProvider * @dataProvider sanitizeInfoboxTitleSourceProvider
* *
* @param $source string * @param $input
* @param $data
* @param $expected string * @param $expected string
*/ */
public function testSanitizeInfoboxTitle( $source, $expected ) { public function testSanitizeInfoboxTitle( $input, $data, $expected ) {
$renderService = new PortableInfoboxRenderService(); $renderService = new PortableInfoboxRenderService();
$this->assertEquals( $expected, $renderService->sanitizeInfoboxTitle( $source ) ); $this->assertEquals( $expected, $renderService->sanitizeInfoboxTitle( $input , $data ) );
} }
public function sanitizeInfoboxTitleSourceProvider() { public function sanitizeInfoboxTitleSourceProvider() {
return [ return [
[ 'Test Title' , 'Test Title'], ['title', [ 'value' => 'Test Title' ], [ 'value' => 'Test Title' ] ],
[ ' Test Title ' , 'Test Title'], ['title', ['value' => ' Test Title '] , [ 'value' => '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'], ['title', ['value' => 'Test Title <img src=\'data:image/gif;base64,R0lGODlhAQABAIABAAAAAP///yH5BAEAAAEALAAAAAABAAEAQAICTAEAOw%3D%3D\' class=\'article-media\' data-ref=\'1\' width=\'400\' height=\'100\' /> ' ], [ 'value' => 'Test Title']],
[ 'Test Title <a href="example.com">with link</a>' , 'Test Title with link'], ['title', ['value' => 'Test Title <a href="example.com">with link</a>'], [ 'value' => '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'] ['title', ['value' => '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'] , [ 'value' => 'Real world title example'] ],
['hero-mobile', ['title' => ['value' => 'Test Title'] ], ['title' => ['value' => 'Test Title'] ] ],
['hero-mobile', ['title' => ['value' => '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'] ] , ['title' => ['value' => 'Real world title example'] ] ],
['data', [ 'value' => 'Test <a>Group</a>' ], [ 'value' => 'Test <a>Group</a>' ] ],
]; ];
} }
} }