From cf22303f9d815b23d4aa98025733ed5b4a5a864b Mon Sep 17 00:00:00 2001 From: Diana Date: Tue, 21 Jul 2015 23:13:28 +0000 Subject: [PATCH] don't render image inside hero module title --- .../PortableInfoboxRenderService.class.php | 26 ++-- tests/PortableInfoboxRenderServiceTest.php | 117 +++++++++++++++--- 2 files changed, 114 insertions(+), 29 deletions(-) diff --git a/services/PortableInfoboxRenderService.class.php b/services/PortableInfoboxRenderService.class.php index 224d759..bf6920f 100644 --- a/services/PortableInfoboxRenderService.class.php +++ b/services/PortableInfoboxRenderService.class.php @@ -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; } } diff --git a/tests/PortableInfoboxRenderServiceTest.php b/tests/PortableInfoboxRenderServiceTest.php index 76177a4..608a291 100644 --- a/tests/PortableInfoboxRenderServiceTest.php +++ b/tests/PortableInfoboxRenderServiceTest.php @@ -417,19 +417,89 @@ class PortableInfoboxRenderServiceTest extends WikiaBaseTest { ', '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' => '', + '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' => '', + '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 Title' ] ], [ 'type' => 'image', - 'data' => [] + 'data' => [ + 'url' => 'http://image.jpg', + 'thumbnail' => 'thumbnail.jpg', + 'ref' => 44 + ] ], [ 'type' => 'data', @@ -440,39 +510,46 @@ class PortableInfoboxRenderServiceTest extends WikiaBaseTest { ] ], 'output' => '', - 'description' => 'Mobile: Simple infobox with title, INVALID image and key-value pair' + ', + '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 ' , 'Test Title'], - [ 'Test Title with link' , 'Test Title with link'], - [ 'Real world DBGT Logotitle example' , 'Real world title example'] + ['title', [ 'value' => 'Test Title' ], [ 'value' => 'Test Title' ] ], + ['title', ['value' => ' Test Title '] , [ 'value' => 'Test Title'] ], + ['title', ['value' => 'Test Title ' ], [ 'value' => 'Test Title']], + ['title', ['value' => 'Test Title with link'], [ 'value' => 'Test Title with link'] ], + ['title', ['value' => 'Real world DBGT Logotitle example'] , [ 'value' => 'Real world title example'] ], + ['hero-mobile', ['title' => ['value' => 'Test Title'] ], ['title' => ['value' => 'Test Title'] ] ], + ['hero-mobile', ['title' => ['value' => 'Real world DBGT Logotitle example'] ] , ['title' => ['value' => 'Real world title example'] ] ], + ['data', [ 'value' => 'Test Group' ], [ 'value' => 'Test Group' ] ], ]; } }