mirror of
https://github.com/Universal-Omega/PortableInfobox.git
synced 2024-11-15 11:59:56 +00:00
add unit tests for params validator
This commit is contained in:
parent
462a8fbc07
commit
96ced03f8a
|
@ -13,13 +13,16 @@ class InfoboParamsValidator {
|
|||
* @param array $params
|
||||
* @throws InvalidInfoboxParamsException
|
||||
* @todo: consider using hashmap instead of array ones validator grows
|
||||
* @returns boolean
|
||||
*/
|
||||
public function validateParams( $params ) {
|
||||
foreach ( array_keys( $params ) as $param ) {
|
||||
if ( !in_array( $param, $this->$supportedParams ) ) {
|
||||
if ( !in_array( $param, $this->supportedParams ) ) {
|
||||
throw new InvalidInfoboxParamsException( $param );
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
68
tests/InfoboxParamsValidatorTest.php
Normal file
68
tests/InfoboxParamsValidatorTest.php
Normal file
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
class InfoboxParamsValidatorTest extends WikiaBaseTest {
|
||||
private $InfoboxParamsValidator;
|
||||
private $invalidParamsExpectionNname =
|
||||
'Wikia\PortableInfobox\Helpers\InvalidInfoboxParamsException';
|
||||
|
||||
protected function setUp() {
|
||||
$this->setupFile = dirname( __FILE__ ) . '/../PortableInfobox.setup.php';
|
||||
parent::setUp();
|
||||
|
||||
$this->InfoboxParamsValidator = new \Wikia\PortableInfobox\Helpers\InfoboParamsValidator();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $params
|
||||
* @dataProvider testInfoboxParamsFailValidationDataProvider
|
||||
*/
|
||||
public function testInfoboxParamsFailValidation ( $params ) {
|
||||
$this->setExpectedException( $this->invalidParamsExpectionNname );
|
||||
$this->InfoboxParamsValidator->validateParams( $params );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $params
|
||||
* @dataProvider testInfoboxParamsPassValidationDataProvider
|
||||
*/
|
||||
public function testInfoboxParamsPassValidation ( $params ) {
|
||||
$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 [
|
||||
[
|
||||
'params' => [],
|
||||
],
|
||||
[
|
||||
'params' => [
|
||||
'theme' => 'test',
|
||||
'theme-source' => 'loremIpsum',
|
||||
'layout' => 'myLayout'
|
||||
]
|
||||
],
|
||||
[
|
||||
'params' => [
|
||||
'theme' => 'test',
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue