mirror of
https://github.com/Universal-Omega/PortableInfobox.git
synced 2024-11-15 20:09:44 +00:00
add sanitizer tests
This commit is contained in:
parent
8afcb73d10
commit
a4e03f9147
|
@ -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
|
||||||
|
|
62
tests/sanitizers/NodeDataSanitizerTest.php
Normal file
62
tests/sanitizers/NodeDataSanitizerTest.php
Normal 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>'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
37
tests/sanitizers/NodeHeroImageSanitizerTest.php
Normal file
37
tests/sanitizers/NodeHeroImageSanitizerTest.php
Normal 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'] ]
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
59
tests/sanitizers/NodeHorizontalGroupSanitizerTest.php
Normal file
59
tests/sanitizers/NodeHorizontalGroupSanitizerTest.php
Normal 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'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
48
tests/sanitizers/NodeTitleSanitizerTest.php
Normal file
48
tests/sanitizers/NodeTitleSanitizerTest.php
Normal 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']
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue