add sanitizer tests

This commit is contained in:
dianafa 2015-12-23 16:08:43 +01:00
parent 8afcb73d10
commit a4e03f9147
5 changed files with 206 additions and 116 deletions

View file

@ -183,122 +183,6 @@ class PortableInfoboxRenderServiceHelperTest extends WikiaBaseTest {
]; ];
} }
/**
* @param string $input
* @param array $data
* @param string $expected
* @dataProvider sanitizeInfoboxFieldsDataProvider
*/
public function testSanitizeInfoboxFields( $input, $data, $expected ) {
$this->assertEquals(
$expected,
$this->helper->sanitizeInfoboxFields( $input , $data )
);
}
public function sanitizeInfoboxFieldsDataProvider() {
return [
['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',
[
'label' => 'Data <a>Link</a>',
'value' => 'Data <a>Value</a>' ],
[
'label' => 'Data <a>Link</a>',
'value' => 'Data <a>Value</a>'
]
],
['data',
['label' => 'Test data label <img src=\'data:image/gif;base64,R0lGODlhAQABAIABAAAAAP///yH5BAEAAAEALAAAAAABAAEAQAICTAEAOw%3D%3D\' class=\'article-media\' data-ref=\'1\' width=\'400\' height=\'100\' />with image'],
['label' => 'Test data label with image']
],
['data',
[
'label' => 'Data <div class="some class">with <h2>div </h2>with <small>class</small></div> and other tags',
'value' => 'Data <small>Value</small>'
],
[
'label' => 'Data with div with class and other tags',
'value' => 'Data <small>Value</small>'
]
],
['data',
[
'label' => '<img src="money.jpg" class="test classes" width="20" />',
'value' => 'Data <small>Value</small>'
],
[
'label' => '<img src="money.jpg" class="test classes" width="20" />',
'value' => 'Data <small>Value</small>'
]
],
['horizontal-group-content',
[
'labels' => [
0 => '<img src="money.jpg" class="test classes" width="20" />',
1 => 'Label with <a>link</a>',
2 => 'Label with <small>link</small>',
3 => 'Money <img src="money.jpg" class="test classes" width="20" />'
],
'values' => [
0 => 'Data <small>Value</small>',
1 => 'Data <a>Value</a>',
2 => '<img src="money.jpg" class="test classes" width="20" />',
3 => '$50'
]
],
[
'labels' => [
0 => '<img src="money.jpg" class="test classes" width="20" />',
1 => 'Label with <a>link</a>',
2 => 'Label with link',
3 => 'Money',
],
'values' => [
0 => 'Data <small>Value</small>',
1 => 'Data <a>Value</a>',
2 => '<img src="money.jpg" class="test classes" width="20" />',
3 => '$50'
]
]
],
['image',
[ 'caption' => 'Test <a>Title with</a> <span><small>small</small></span> tag, span tag and <img src="sfefes"/>tag' ],
[ 'caption' => 'Test <a>Title with</a> small tag, span tag and tag' ]
],
['image',
[ 'caption' => '<a href="http://vignette-poz.wikia-dev.com//images/9/95/All_Stats_%2B2.png/revision/latest?cb=20151222111955" class="image image-thumbnail"><img src="abc" alt="All Stats +2" class="thumbimage" /></a>' ],
[ 'caption' => '<a href="http://vignette-poz.wikia-dev.com//images/9/95/All_Stats_%2B2.png/revision/latest?cb=20151222111955" class="image image-thumbnail"></a>' ],
],
];
}
/** /**
* @param array $item * @param array $item
* @param array $heroData * @param array $heroData

View file

@ -0,0 +1,62 @@
<?php
class NodeDataSanitizerTest extends WikiaBaseTest {
private $sanitizer;
protected function setUp() {
$this->setupFile = dirname( __FILE__ ) . '/../../PortableInfobox.setup.php';
$this->sanitizer = new NodeDataSanitizer();
parent::setUp();
}
/**
* @param $data
* @param $expected
* @dataProvider testSanitizeDataProvider
*/
function testSanitize( $data, $expected ) {
$this->assertEquals(
$expected,
$this->sanitizer->sanitize( $data )
);
}
function testSanitizeDataProvider() {
return [
[
[
'label' => 'Data <a>Link</a>',
'value' => 'Data <a>Value</a>' ],
[
'label' => 'Data <a>Link</a>',
'value' => 'Data <a>Value</a>'
]
],
[
['label' => 'Test data label <img src=\'data:image/gif;base64,R0lGODlhAQABAIABAAAAAP///yH5BAEAAAEALAAAAAABAAEAQAICTAEAOw%3D%3D\' class=\'article-media\' data-ref=\'1\' width=\'400\' height=\'100\' />with image'],
['label' => 'Test data label with image']
],
[
[
'label' => 'Data <div class="some class">with <h2>div </h2>with <small>class</small></div> and other tags',
'value' => 'Data <small>Value</small>'
],
[
'label' => 'Data with div with class and other tags',
'value' => 'Data <small>Value</small>'
]
],
[
[
'label' => '<img src="money.jpg" class="test classes" width="20" />',
'value' => 'Data <small>Value</small>'
],
[
'label' => '<img src="money.jpg" class="test classes" width="20" />',
'value' => 'Data <small>Value</small>'
]
],
];
}
}

View file

@ -0,0 +1,37 @@
<?php
class NodeHeroImageSanitizerTest extends WikiaBaseTest {
private $sanitizer;
protected function setUp() {
$this->setupFile = dirname( __FILE__ ) . '/../../PortableInfobox.setup.php';
$this->sanitizer = new NodeHeroImageSanitizer();
parent::setUp();
}
/**
* @param $data
* @param $expected
* @dataProvider testSanitizeDataProvider
*/
function testSanitize( $data, $expected ) {
$this->assertEquals(
$expected,
$this->sanitizer->sanitize( $data )
);
}
function testSanitizeDataProvider() {
return [
[
['title' => ['value' => 'Test Title'] ],
['title' => ['value' => 'Test Title'] ]
],
[
['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'] ]
],
];
}
}

View file

@ -0,0 +1,59 @@
<?php
class NodeHorizontalGroupSanitizerTest extends WikiaBaseTest {
private $sanitizer;
protected function setUp() {
$this->setupFile = dirname( __FILE__ ) . '/../../PortableInfobox.setup.php';
$this->sanitizer = new NodeHorizontalGroupSanitizer();
parent::setUp();
}
/**
* @param $data
* @param $expected
* @dataProvider testSanitizeDataProvider
*/
function testSanitize( $data, $expected ) {
$this->assertEquals(
$expected,
$this->sanitizer->sanitize( $data )
);
}
function testSanitizeDataProvider() {
return [
[
[
'labels' => [
0 => '<img src="money.jpg" class="test classes" width="20" />',
1 => 'Label with <a>link</a>',
2 => 'Label with <small>link</small>',
3 => 'Money <img src="money.jpg" class="test classes" width="20" />'
],
'values' => [
0 => 'Data <small>Value</small>',
1 => 'Data <a>Value</a>',
2 => '<img src="money.jpg" class="test classes" width="20" />',
3 => '$50'
]
],
[
'labels' => [
0 => '<img src="money.jpg" class="test classes" width="20" />',
1 => 'Label with <a>link</a>',
2 => 'Label with link',
3 => 'Money',
],
'values' => [
0 => 'Data <small>Value</small>',
1 => 'Data <a>Value</a>',
2 => '<img src="money.jpg" class="test classes" width="20" />',
3 => '$50'
]
]
]
];
}
}

View file

@ -0,0 +1,48 @@
<?php
class NodeTitleSanitizerTest extends WikiaBaseTest {
private $sanitizer;
protected function setUp() {
$this->setupFile = dirname( __FILE__ ) . '/../../PortableInfobox.setup.php';
$this->sanitizer = new NodeTitleSanitizer();
parent::setUp();
}
/**
* @param $data
* @param $expected
* @dataProvider testSanitizeDataProvider
*/
function testSanitize( $data, $expected ) {
$this->assertEquals(
$expected,
$this->sanitizer->sanitize( $data )
);
}
function testSanitizeDataProvider() {
return [
[
['value' => 'Test Title' ],
[ 'value' => 'Test Title' ]
],
[
['value' => ' Test Title '],
['value' => 'Test 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']],
[
['value' => 'Test Title <a href="example.com">with link</a>'],
[ 'value' => 'Test Title with link']
],
[
['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']
],
];
}
}