PortableInfobox/tests/InfoboxParamsValidatorTest.php

146 lines
3.4 KiB
PHP
Raw Normal View History

2015-06-11 10:54:10 +00:00
<?php
class InfoboxParamsValidatorTest extends WikiaBaseTest {
private $InfoboxParamsValidator;
2015-06-11 11:19:05 +00:00
private $invalidParamsExpectionName =
2015-06-11 10:54:10 +00:00
'Wikia\PortableInfobox\Helpers\InvalidInfoboxParamsException';
protected function setUp() {
$this->setupFile = dirname( __FILE__ ) . '/../PortableInfobox.setup.php';
parent::setUp();
2016-02-03 11:06:44 +00:00
$this->InfoboxParamsValidator = new \Wikia\PortableInfobox\Helpers\InfoboxParamsValidator();
2015-06-11 10:54:10 +00:00
}
/**
* @param array $params
* @dataProvider testInfoboxParamsFailValidationDataProvider
*/
2016-12-29 13:17:48 +00:00
public function testInfoboxParamsFailValidation( $params ) {
2015-06-11 11:19:05 +00:00
$this->setExpectedException( $this->invalidParamsExpectionName );
2015-06-11 10:54:10 +00:00
$this->InfoboxParamsValidator->validateParams( $params );
}
/**
* @param array $params
* @dataProvider testInfoboxParamsPassValidationDataProvider
*/
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 ) );
}
public function testInfoboxParamsFailValidationDataProvider() {
return [
[
'params' => [
'theme' => 'test',
'abc' => 'def',
'layout' => 'myLayout'
]
],
[
'params' => [
'abc' => 'def',
]
],
];
}
public function testInfoboxParamsPassValidationDataProvider() {
return [
[
2016-12-29 13:17:48 +00:00
'params' => [ ],
2015-06-11 10:54:10 +00:00
],
[
'params' => [
'theme' => 'test',
'theme-source' => 'loremIpsum',
'layout' => 'myLayout'
]
],
[
'params' => [
'theme' => 'test',
]
]
];
}
/**
* @param $color
* @dataProvider testPassValidateColorValueDataProvider
*/
public function testPassValidateColorValue( $color ) {
$this->assertTrue( $this->InfoboxParamsValidator->validateColorValue( $color ) );
}
public function testPassValidateColorValueDataProvider() {
return [
2016-12-29 13:17:48 +00:00
[ 'color' => '#aaa' ],
[ 'color' => '#abc' ],
[ 'color' => '#a12' ],
[ 'color' => '#12f' ],
[ 'color' => '#fff' ],
[ 'color' => '#000' ],
[ 'color' => '#999' ],
[ 'color' => '#aaaaaa' ],
[ 'color' => '#abcabc' ],
[ 'color' => '#a12acd' ],
[ 'color' => '#12f126' ],
[ 'color' => '#adf129' ],
[ 'color' => '#125fff' ],
[ 'color' => '#ffffff' ],
[ 'color' => '#000000' ],
[ 'color' => '#999999' ],
];
}
/**
* @param array $color
* @dataProvider testFailValidateColorValueDataProvider
*/
public function testFailValidateColorValue( $color ) {
$this->assertFalse( $this->InfoboxParamsValidator->validateColorValue( $color ) );
}
public function testFailValidateColorValueDataProvider() {
return [
2016-12-29 13:17:48 +00:00
[ 'color' => '' ],
[ 'color' => 'aaa' ],
[ 'color' => 'abc' ],
[ 'color' => 'a12' ],
[ 'color' => '12f' ],
[ 'color' => 'fff' ],
[ 'color' => '000' ],
[ 'color' => '999' ],
[ 'color' => 'ggg' ],
[ 'color' => 'asd' ],
[ 'color' => '12g' ],
[ 'color' => '1k2' ],
[ 'color' => 'l34' ],
[ 'color' => 'aaaa' ],
[ 'color' => 'aaag' ],
[ 'color' => '#ggg' ],
[ 'color' => '#asd' ],
[ 'color' => '#12g' ],
[ 'color' => '#1k2' ],
[ 'color' => '#l34' ],
[ 'color' => '#aaaa' ],
[ 'color' => '#aaag' ],
[ 'color' => 'aaaaa' ],
[ 'color' => 'aaaaaa' ],
[ 'color' => 'abcabc' ],
[ 'color' => 'a12acd' ],
[ 'color' => '12f126' ],
[ 'color' => 'adf129' ],
[ 'color' => '125fff' ],
[ 'color' => 'ffffff' ],
[ 'color' => '000000' ],
[ 'color' => '999999' ],
[ 'color' => 'aaaaaaa' ],
[ 'color' => '#aaaaaaa' ],
[ 'color' => '#aaaaa' ],
];
}
2015-06-11 10:54:10 +00:00
}