2015-06-11 10:54:10 +00:00
|
|
|
<?php
|
2018-08-08 09:42:22 +00:00
|
|
|
/**
|
|
|
|
* @group PortableInfobox
|
2018-08-09 09:49:10 +00:00
|
|
|
* @covers PortableInfobox\Helpers\InfoboxParamsValidator
|
2018-08-08 09:42:22 +00:00
|
|
|
*/
|
2021-12-15 22:01:13 +00:00
|
|
|
class InfoboxParamsValidatorTest extends MediaWikiIntegrationTestCase {
|
2018-08-09 09:49:10 +00:00
|
|
|
/** @var PortableInfobox\Helpers\InfoboxParamsValidator $InfoboxParamsValidator */
|
2015-06-11 10:54:10 +00:00
|
|
|
private $InfoboxParamsValidator;
|
|
|
|
|
2021-09-11 23:07:07 +00:00
|
|
|
protected function setUp(): void {
|
2015-06-11 10:54:10 +00:00
|
|
|
parent::setUp();
|
2018-08-09 09:49:10 +00:00
|
|
|
$this->InfoboxParamsValidator = new PortableInfobox\Helpers\InfoboxParamsValidator();
|
2015-06-11 10:54:10 +00:00
|
|
|
}
|
2018-08-13 14:31:50 +00:00
|
|
|
|
2021-09-11 23:07:07 +00:00
|
|
|
protected function tearDown(): void {
|
2018-08-16 09:25:53 +00:00
|
|
|
unset( $this->InfoboxParamsValidator );
|
2018-08-08 09:42:22 +00:00
|
|
|
parent::tearDown();
|
|
|
|
}
|
2015-06-11 10:54:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $params
|
2017-03-15 18:07:51 +00:00
|
|
|
* @dataProvider infoboxParamsFailValidationDataProvider
|
2015-06-11 10:54:10 +00:00
|
|
|
*/
|
2016-12-29 13:17:48 +00:00
|
|
|
public function testInfoboxParamsFailValidation( $params ) {
|
2021-09-11 23:07:07 +00:00
|
|
|
$this->expectException( PortableInfobox\Helpers\InvalidInfoboxParamsException::class );
|
|
|
|
|
2015-06-11 10:54:10 +00:00
|
|
|
$this->InfoboxParamsValidator->validateParams( $params );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $params
|
2017-03-15 18:07:51 +00:00
|
|
|
* @dataProvider infoboxParamsPassValidationDataProvider
|
2015-06-11 10:54:10 +00:00
|
|
|
*/
|
2016-12-29 13:17:48 +00:00
|
|
|
public function testInfoboxParamsPassValidation( $params ) {
|
2015-06-11 10:54:10 +00:00
|
|
|
$this->assertEquals( true, $this->InfoboxParamsValidator->validateParams( $params ) );
|
|
|
|
}
|
|
|
|
|
2017-03-15 18:07:51 +00:00
|
|
|
public function infoboxParamsFailValidationDataProvider() {
|
2015-06-11 10:54:10 +00:00
|
|
|
return [
|
|
|
|
[
|
|
|
|
'params' => [
|
|
|
|
'theme' => 'test',
|
|
|
|
'abc' => 'def',
|
|
|
|
'layout' => 'myLayout'
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'params' => [
|
|
|
|
'abc' => 'def',
|
|
|
|
]
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2017-03-15 18:07:51 +00:00
|
|
|
public function infoboxParamsPassValidationDataProvider() {
|
2015-06-11 10:54:10 +00:00
|
|
|
return [
|
|
|
|
[
|
2018-08-16 09:25:53 +00:00
|
|
|
'params' => [],
|
2015-06-11 10:54:10 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'params' => [
|
|
|
|
'theme' => 'test',
|
|
|
|
'theme-source' => 'loremIpsum',
|
|
|
|
'layout' => 'myLayout'
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'params' => [
|
|
|
|
'theme' => 'test',
|
|
|
|
]
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
2016-12-28 09:12:21 +00:00
|
|
|
|
|
|
|
/**
|
2018-08-26 11:00:00 +00:00
|
|
|
* @param string $color
|
|
|
|
* @param bool $addHash
|
2017-03-15 18:07:51 +00:00
|
|
|
* @dataProvider passValidateColorValueDataProvider
|
2016-12-28 09:12:21 +00:00
|
|
|
*/
|
2018-08-26 11:00:00 +00:00
|
|
|
public function testPassValidateColorValue( $color, $addHash = false ) {
|
|
|
|
$this->assertEquals(
|
|
|
|
( $addHash ? '#' : '' ) . strtolower( preg_replace( '/\s+/', '', $color ) ),
|
|
|
|
$this->InfoboxParamsValidator->validateColorValue( $color )
|
|
|
|
);
|
2016-12-28 09:12:21 +00:00
|
|
|
}
|
|
|
|
|
2017-03-15 18:07:51 +00:00
|
|
|
public function passValidateColorValueDataProvider() {
|
2016-12-28 09:12:21 +00:00
|
|
|
return [
|
2016-12-29 13:17:48 +00:00
|
|
|
[ 'color' => '#aaa' ],
|
|
|
|
[ 'color' => '#abc' ],
|
|
|
|
[ 'color' => '#a12' ],
|
|
|
|
[ 'color' => '#12f' ],
|
|
|
|
[ 'color' => '#fff' ],
|
|
|
|
[ 'color' => '#000' ],
|
|
|
|
[ 'color' => '#999' ],
|
2018-08-26 11:00:00 +00:00
|
|
|
[ 'color' => '#aaaa' ],
|
2016-12-29 13:17:48 +00:00
|
|
|
[ 'color' => '#aaaaaa' ],
|
|
|
|
[ 'color' => '#abcabc' ],
|
|
|
|
[ 'color' => '#a12acd' ],
|
|
|
|
[ 'color' => '#12f126' ],
|
|
|
|
[ 'color' => '#adf129' ],
|
|
|
|
[ 'color' => '#125fff' ],
|
|
|
|
[ 'color' => '#ffffff' ],
|
|
|
|
[ 'color' => '#000000' ],
|
|
|
|
[ 'color' => '#999999' ],
|
2018-08-26 11:00:00 +00:00
|
|
|
[ 'color' => '#ffffffff' ],
|
|
|
|
[ 'color' => 'aaa', true ],
|
|
|
|
[ 'color' => 'abc', true ],
|
|
|
|
[ 'color' => 'a12', true ],
|
|
|
|
[ 'color' => '12f', true ],
|
|
|
|
[ 'color' => 'fff', true ],
|
|
|
|
[ 'color' => '000', true ],
|
|
|
|
[ 'color' => '999', true ],
|
|
|
|
[ 'color' => 'aaaa', true ],
|
|
|
|
[ 'color' => 'a12acd', true ],
|
|
|
|
[ 'color' => 'aaaaaa', true ],
|
|
|
|
[ 'color' => 'abcabc', true ],
|
|
|
|
[ 'color' => 'ffffff', true ],
|
|
|
|
[ 'color' => '000000', true ],
|
|
|
|
[ 'color' => '999999', true ],
|
|
|
|
[ 'color' => '125fff', true ],
|
|
|
|
[ 'color' => 'ffffffff', true ],
|
|
|
|
[ 'color' => 'rgb(0,0,0)' ],
|
|
|
|
[ 'color' => 'RGB(20,3,255)' ],
|
|
|
|
[ 'color' => 'rgb( 20, 3, 255 )' ],
|
|
|
|
[ 'color' => 'rgb(255,255,255)' ],
|
|
|
|
[ 'color' => 'rgb(0%,25%,100%)' ],
|
|
|
|
[ 'color' => 'rgb(10%,75%,33%)' ],
|
|
|
|
[ 'color' => 'RGB(100%,100%,100%)' ],
|
|
|
|
[ 'color' => 'rgba(0,0,0,0)' ],
|
|
|
|
[ 'color' => 'rgba(0,0,0,0%)' ],
|
|
|
|
[ 'color' => 'rgba(20,3,255,50%)' ],
|
|
|
|
[ 'color' => 'RGBA(20, 3, 255,.5)' ],
|
|
|
|
[ 'color' => 'rgba( 20, 3, 255, 0.5 )' ],
|
|
|
|
[ 'color' => 'rgba(255,255,255, 1)' ],
|
|
|
|
[ 'color' => 'rgba(255,255,255, 100%)' ],
|
|
|
|
[ 'color' => 'rgba(0%,25%,99% ,25%)' ],
|
|
|
|
[ 'color' => 'RGBA(100%,100%,100%, 1)' ],
|
|
|
|
[ 'color' => 'rgba(100%,100%,100%, 100%)' ],
|
|
|
|
[ 'color' => 'hsl(0,0%,0%)' ],
|
|
|
|
[ 'color' => 'hsl(40, 78%, 45%)' ],
|
|
|
|
[ 'color' => 'HSL( -80, 58%, 30%)' ],
|
|
|
|
[ 'color' => 'hsl(360,100%,100%)' ],
|
|
|
|
[ 'color' => 'hsla(0,0%,0%,0)' ],
|
|
|
|
[ 'color' => 'hsla(0,0%,0%,0%)' ],
|
|
|
|
[ 'color' => 'HSLA(40,78%,45%,.3)' ],
|
|
|
|
[ 'color' => 'hsla( 359, 38%,20% ,0.7)' ],
|
|
|
|
[ 'color' => 'HSLA(360,100%,100%,100%)' ],
|
|
|
|
[ 'color' => 'hsla( 360 , 100% , 100%,1)' ],
|
|
|
|
[ 'color' => 'white' ],
|
|
|
|
[ 'color' => 'White' ],
|
|
|
|
[ 'color' => 'WHITE' ],
|
2016-12-28 09:12:21 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $color
|
2017-03-15 18:07:51 +00:00
|
|
|
* @dataProvider failValidateColorValueDataProvider
|
2016-12-28 09:12:21 +00:00
|
|
|
*/
|
|
|
|
public function testFailValidateColorValue( $color ) {
|
2018-08-26 11:00:00 +00:00
|
|
|
$this->assertEquals( '', $this->InfoboxParamsValidator->validateColorValue( $color ) );
|
2016-12-28 09:12:21 +00:00
|
|
|
}
|
|
|
|
|
2017-03-15 18:07:51 +00:00
|
|
|
public function failValidateColorValueDataProvider() {
|
2016-12-28 09:12:21 +00:00
|
|
|
return [
|
2016-12-29 13:17:48 +00:00
|
|
|
[ 'color' => '' ],
|
|
|
|
[ 'color' => 'ggg' ],
|
|
|
|
[ 'color' => 'asd' ],
|
|
|
|
[ 'color' => '12g' ],
|
|
|
|
[ 'color' => '1k2' ],
|
|
|
|
[ 'color' => 'l34' ],
|
|
|
|
[ 'color' => 'aaag' ],
|
|
|
|
[ 'color' => '#ggg' ],
|
|
|
|
[ 'color' => '#asd' ],
|
|
|
|
[ 'color' => '#12g' ],
|
|
|
|
[ 'color' => '#1k2' ],
|
|
|
|
[ 'color' => '#l34' ],
|
|
|
|
[ 'color' => '#aaag' ],
|
|
|
|
[ 'color' => 'aaaaa' ],
|
2018-08-26 11:00:00 +00:00
|
|
|
[ 'color' => '12fl26' ],
|
|
|
|
[ 'color' => 'adfl29' ],
|
2016-12-29 13:17:48 +00:00
|
|
|
[ 'color' => 'aaaaaaa' ],
|
|
|
|
[ 'color' => '#aaaaaaa' ],
|
|
|
|
[ 'color' => '#aaaaa' ],
|
2018-08-26 11:00:00 +00:00
|
|
|
[ 'color' => 'fffffffff' ],
|
|
|
|
[ 'color' => '#fffffffff' ],
|
|
|
|
[ 'color' => 'rgb(0a,0a,0a)' ],
|
|
|
|
[ 'color' => 'rgb(20,3,265)' ],
|
|
|
|
[ 'color' => 'rgb( -20, 3, 255 )' ],
|
|
|
|
[ 'color' => 'rgb(256,355,67)' ],
|
|
|
|
[ 'color' => 'rgb(256,355)' ],
|
|
|
|
[ 'color' => 'rgb(256,355,)' ],
|
|
|
|
[ 'color' => 'rgb(256,355,,63)' ],
|
|
|
|
[ 'color' => 'rgb(552,355,,63)' ],
|
|
|
|
[ 'color' => 'rgb(0%,25%,102%)' ],
|
|
|
|
[ 'color' => 'rgba(255,255,255,1.)' ],
|
|
|
|
[ 'color' => 'rgba(100%,100%,100%)' ],
|
|
|
|
[ 'color' => 'rgba(100%,100%,100%,.)' ],
|
|
|
|
[ 'color' => 'hsl(0,0%,0%,0)' ],
|
|
|
|
[ 'color' => 'hsl(0,-78%,45%)' ],
|
|
|
|
[ 'color' => 'hsl(0%,85%,12%)' ],
|
|
|
|
[ 'color' => 'hsl(356,14%,100)' ],
|
|
|
|
[ 'color' => 'hsla(0,0%,0%)' ],
|
|
|
|
[ 'color' => 'hsla(0,0%,0%,.)' ],
|
|
|
|
[ 'color' => 'hsla(0,0%,0%,0.)' ],
|
2016-12-28 09:12:21 +00:00
|
|
|
];
|
|
|
|
}
|
2018-08-13 14:31:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $layout
|
|
|
|
* @dataProvider passValidateLayoutDataProvider
|
|
|
|
*/
|
|
|
|
public function testPassValidateLayout( $layout ) {
|
|
|
|
$this->assertTrue( $this->InfoboxParamsValidator->validateLayout( $layout ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function passValidateLayoutDataProvider() {
|
|
|
|
return [
|
|
|
|
[ 'layout' => 'default' ],
|
|
|
|
[ 'layout' => 'stacked' ]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $layout
|
|
|
|
* @dataProvider failValidateLayoutDataProvider
|
|
|
|
*/
|
|
|
|
public function testFailValidateLayout( $layout ) {
|
|
|
|
$this->assertFalse( $this->InfoboxParamsValidator->validateLayout( $layout ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function failValidateLayoutDataProvider() {
|
|
|
|
return [
|
|
|
|
[ 'layout' => '' ],
|
|
|
|
[ 'layout' => 'custom' ]
|
|
|
|
];
|
|
|
|
}
|
2015-06-11 10:54:10 +00:00
|
|
|
}
|