mirror of
https://github.com/Universal-Omega/PortableInfobox.git
synced 2024-11-15 11:59:56 +00:00
don't render image inside hero module title
This commit is contained in:
parent
6425ac0299
commit
cf22303f9d
|
@ -120,8 +120,8 @@ class PortableInfoboxRenderService extends WikiaService {
|
|||
}
|
||||
}
|
||||
|
||||
if ( $type === 'title' && $this->isWikiaMobile() ) {
|
||||
$data[ 'value' ] = $this->sanitizeInfoboxTitle( $data[ 'value' ] );
|
||||
if ( $this->isWikiaMobile() ) {
|
||||
$data = $this->sanitizeInfoboxTitle( $type, $data );
|
||||
}
|
||||
|
||||
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
|
||||
* @return string
|
||||
* @param $type type of infobox item
|
||||
* @param $data infobox item data
|
||||
* @return infobox $data with sanitized title param if needed
|
||||
*/
|
||||
public function sanitizeInfoboxTitle( $title ) {
|
||||
$title = strip_tags( $title );
|
||||
$title = trim( $title );
|
||||
public function sanitizeInfoboxTitle( $type, $data ) {
|
||||
if ( $type === 'title' && !empty( $data['value'] ) ) {
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -417,19 +417,89 @@ class PortableInfoboxRenderServiceTest extends WikiaBaseTest {
|
|||
</aside>',
|
||||
'description' => 'Mobile: A small image. Should not render hero'
|
||||
],
|
||||
[
|
||||
'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' => [
|
||||
'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' => [
|
||||
'isInvalidImage' => true,
|
||||
'isWikiaMobile' => true,
|
||||
'fileWidth' => '450',
|
||||
[
|
||||
'type' => 'title',
|
||||
'data' => [
|
||||
'value' => 'Test Title'
|
||||
'value' => 'Test <img /><a href="example.com">Title</a>'
|
||||
]
|
||||
],
|
||||
[
|
||||
'type' => 'image',
|
||||
'data' => []
|
||||
'data' => [
|
||||
'url' => 'http://image.jpg',
|
||||
'thumbnail' => 'thumbnail.jpg',
|
||||
'ref' => 44
|
||||
]
|
||||
],
|
||||
[
|
||||
'type' => 'data',
|
||||
|
@ -440,39 +510,46 @@ class PortableInfoboxRenderServiceTest extends WikiaBaseTest {
|
|||
]
|
||||
],
|
||||
'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 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>
|
||||
<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'
|
||||
</aside>',
|
||||
'description' => 'Mobile: Infobox with title with HTML tags, image and key-value pair'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers PortableInfoboxRenderService::sanitizeInfoboxTitle
|
||||
* @covers PortableInfoboxRenderService::sanitizeInfoboxTitle
|
||||
* @dataProvider sanitizeInfoboxTitleSourceProvider
|
||||
*
|
||||
* @param $source string
|
||||
* @param $input
|
||||
* @param $data
|
||||
* @param $expected string
|
||||
*/
|
||||
public function testSanitizeInfoboxTitle( $source, $expected ) {
|
||||
public function testSanitizeInfoboxTitle( $input, $data, $expected ) {
|
||||
$renderService = new PortableInfoboxRenderService();
|
||||
|
||||
$this->assertEquals( $expected, $renderService->sanitizeInfoboxTitle( $source ) );
|
||||
$this->assertEquals( $expected, $renderService->sanitizeInfoboxTitle( $input , $data ) );
|
||||
}
|
||||
|
||||
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']
|
||||
['title', [ 'value' => 'Test Title' ], [ 'value' => 'Test Title' ] ],
|
||||
['title', ['value' => ' Test Title '] , [ 'value' => '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']],
|
||||
['title', ['value' => 'Test Title <a href="example.com">with link</a>'], [ 'value' => 'Test Title with link'] ],
|
||||
['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>' ] ],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue