Commit d49b9ae3 authored by Tino Goratsch's avatar Tino Goratsch

- added unit tests for the NotEmptyValidationRule,...

- added unit tests for the NotEmptyValidationRule, NumberGreaterThanValidationRule and TimeExistsValidationRule class
- added one more Test case to thr AbstractValidationRuleTest
parent 2da7ec5f
<?php
namespace ACP3\Core\Validation\ValidationRules;
/**
* Class NumberGreaterThanValidationRule
* @package ACP3\Core\Validation\ValidationRules
......
......@@ -3,9 +3,24 @@
abstract class AbstractValidationRuleTest extends PHPUnit_Framework_TestCase
{
/**
* @var \ACP3\Core\Validation\ValidationRules\ValidationRuleInterface|PHPUnit_Framework_MockObject_MockObject
* @var \ACP3\Core\Validation\ValidationRules\ValidationRuleInterface
*/
protected $validationRule;
/**
* @var \ACP3\Core\Validation\Validator|PHPUnit_Framework_MockObject_MockObject
*/
protected $validator;
protected function setUp()
{
$this->validationRule->setMessage('Invalid value.');
$this->validator = $this
->getMockBuilder(\ACP3\Core\Validation\Validator::class)
->getMock();
$this->validator->registerValidationRule($this->validationRule);
}
/**
* @return array
......@@ -33,4 +48,31 @@ abstract class AbstractValidationRuleTest extends PHPUnit_Framework_TestCase
$className = get_class($this->validationRule);
$this->assertEquals($className::NAME, $this->validationRule->getName());
}
/**
* @dataProvider validationRuleProvider
*
* @param mixed $data
* @param array|string $field
* @param array $extra
* @param bool $expected
*/
public function testValidate($data, $field, $extra, $expected)
{
if ($expected === true) {
$this->validator->expects($this->never())
->method('addError');
} else {
$this->validator->expects($this->once())
->method('addError')
->with('Invalid value.', $field);
}
$this->validationRule->validate(
$this->validator,
$data,
$field,
$extra
);
}
}
\ No newline at end of file
......@@ -6,6 +6,8 @@ class BirthdayValidationRuleTest extends AbstractValidationRuleTest
protected function setUp()
{
$this->validationRule = new \ACP3\Core\Validation\ValidationRules\BirthdayValidationRule();
parent::setUp();
}
/**
......
......@@ -6,6 +6,8 @@ class ChangePasswordValidationRuleTest extends AbstractValidationRuleTest
protected function setUp()
{
$this->validationRule = new \ACP3\Core\Validation\ValidationRules\ChangePasswordValidationRule();
parent::setUp();
}
/**
......
......@@ -6,6 +6,8 @@ class DateValidationRuleTest extends AbstractValidationRuleTest
protected function setUp()
{
$this->validationRule = new \ACP3\Core\Validation\ValidationRules\DateValidationRule();
parent::setUp();
}
/**
......
......@@ -6,6 +6,8 @@ class EmailValidationRuleTest extends AbstractValidationRuleTest
protected function setUp()
{
$this->validationRule = new \ACP3\Core\Validation\ValidationRules\EmailValidationRule();
parent::setUp();
}
/**
......
......@@ -5,6 +5,8 @@ class InArrayValidationRuleTest extends AbstractValidationRuleTest
protected function setUp()
{
$this->validationRule = new \ACP3\Core\Validation\ValidationRules\InArrayValidationRule();
parent::setUp();
}
/**
......
......@@ -6,6 +6,8 @@ class IntegerValidationRuleTest extends AbstractValidationRuleTest
protected function setUp()
{
$this->validationRule = new \ACP3\Core\Validation\ValidationRules\IntegerValidationRule();
parent::setUp();
}
/**
......
......@@ -6,6 +6,8 @@ class InternalUriValidationRuleTest extends AbstractValidationRuleTest
protected function setUp()
{
$this->validationRule = new \ACP3\Core\Validation\ValidationRules\InternalUriValidationRule();
parent::setUp();
}
/**
......
......@@ -5,6 +5,8 @@ class MinLengthValidationRuleTest extends AbstractValidationRuleTest
protected function setUp()
{
$this->validationRule = new \ACP3\Core\Validation\ValidationRules\MinLengthValidationRule();
parent::setUp();
}
/**
......
<?php
class NotEmptyValidationRuleTest extends AbstractValidationRuleTest
{
protected function setUp()
{
$this->validationRule = new \ACP3\Core\Validation\ValidationRules\NotEmptyValidationRule();
parent::setUp();
}
/**
* @return array
*/
public function validationRuleProvider()
{
return [
'valid-data-string' => ['foobar', '', [], true],
'valid-data-array' => [['foo' => 'bar'], 'foo', [], true],
'valid-data-not-empty-array' => [['foo' => ['foobar']], 'foo', [], true],
'valid-data-not-empty-array-two' => [['foobar'], '', [], true],
'invalid-data-string' => ['', '', [], false],
'invalid-data-string-whitespace' => [' ', '', [], false],
'invalid-data-string-whitespaces-newlines' => [" \r\n", '', [], false],
'invalid-data-empty-array' => [['foo' => []], 'foo', [], false],
'invalid-data-empty-array-2' => [[], '', [], false],
'invalid-data-array' => [['foo' => ''], 'foo', [], false],
'invalid-data-array-whitespace' => [['foo' => ' '], 'foo', [], false],
'invalid-data-array-whitespaces-newlines' => [['foo' => " \r\n"], 'foo', [], false],
];
}
}
<?php
class NumberGreaterThanValidationRuleTest extends AbstractValidationRuleTest
{
protected function setUp()
{
$this->validationRule = new \ACP3\Core\Validation\ValidationRules\NumberGreaterThanValidationRule();
parent::setUp();
}
/**
* @return array
*/
public function validationRuleProvider()
{
return [
'valid-data-string' => ['2', '', ['value' => 1], true],
'valid-data-array' => [['foo' => '2'], 'foo', ['value' => 1], true],
'valid-data-integer' => [2, '', ['value' => 1], true],
'valid-data-integer-array' => [['foo' => 2], 'foo', ['value' => 1], true],
'invalid-data-string' => ['fhdskhjk', '', ['value' => 1], false],
'invalid-data-integer' => [20, '', ['value' => 21], false],
];
}
}
\ No newline at end of file
......@@ -6,6 +6,8 @@ class PasswordValidationRuleTest extends AbstractValidationRuleTest
protected function setUp()
{
$this->validationRule = new \ACP3\Core\Validation\ValidationRules\PasswordValidationRule();
parent::setUp();
}
/**
......
<?php
class TimeZoneExistsValidationRuleTest extends AbstractValidationRuleTest
{
protected function setUp()
{
$this->validationRule = new \ACP3\Core\Validation\ValidationRules\TimeZoneExistsValidationRule();
parent::setUp();
}
/**
* @return array
*/
public function validationRuleProvider()
{
return [
'valid-data-string' => ['Europe/Berlin', '', [], true],
'valid-data-array' => [['foo' => 'Europe/Berlin'], 'foo', [], true],
'invalid-data-string' => ['baz', '', [], false],
'invalid-data-array' => [['foo' => 'baz'], 'foo', [], false],
];
}
}
\ No newline at end of file
......@@ -6,6 +6,8 @@ class UriSafeValidationRuleTest extends AbstractValidationRuleTest
protected function setUp()
{
$this->validationRule = new \ACP3\Core\Validation\ValidationRules\UriSafeValidationRule();
parent::setUp();
}
/**
......@@ -15,6 +17,7 @@ class UriSafeValidationRuleTest extends AbstractValidationRuleTest
{
return [
'valid-data-string' => ['abc/1234', '', [], true],
'valid-data-array' => [['foo' => 'abc/1234'], 'foo', [], true],
'invalid-data-string-with-umlauts' => ['abüöc/1234', '', [], false],
'invalid-data-string-with-beginning-number' => ['12abc/1234', '', [], false],
'invalid-data-string-with-uppercase-letters' => ['A12abc/1234', '', [], false],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment