* * For the full copyright and license information, please view the "LICENSE.md" * file that was distributed with this source code. */ namespace Respect\Validation\Rules; use Respect\Validation\TestCase; /** * @group rule * @covers Respect\Validation\Rules\Graph * @covers Respect\Validation\Exceptions\GraphException */ class GraphTest extends TestCase { /** * @dataProvider providerForValidGraph */ public function testValidDataWithGraphCharsShouldReturnTrue($validGraph, $additional = '') { $validator = new Graph($additional); $this->assertTrue($validator->validate($validGraph)); } /** * @dataProvider providerForInvalidGraph * @expectedException Respect\Validation\Exceptions\GraphException */ public function testInvalidGraphShouldFailAndThrowGraphException($invalidGraph, $additional = '') { $validator = new Graph($additional); $this->assertFalse($validator->validate($invalidGraph)); $this->assertFalse($validator->assert($invalidGraph)); } /** * @dataProvider providerForInvalidParams * @expectedException Respect\Validation\Exceptions\ComponentException */ public function testInvalidConstructorParamsShouldThrowComponentExceptionUponInstantiation($additional) { $validator = new Graph($additional); } /** * @dataProvider providerAdditionalChars */ public function testAdditionalCharsShouldBeRespected($additional, $query) { $validator = new Graph($additional); $this->assertTrue($validator->validate($query)); } public function providerAdditionalChars() { return [ [' ', '!@#$%^&*(){} abc 123'], [" \t\n", "[]?+=/\\-_|\"',<>. \t \n abc 123"], ]; } public function providerForInvalidParams() { return [ [new \stdClass()], [[]], [0x2], ]; } public function providerForValidGraph() { return [ ['LKA#@%.54'], ['foobar'], ['16-50'], ['123'], ['#$%&*_'], ]; } public function providerForInvalidGraph() { return [ [''], [null], ["foo\nbar"], ["foo\tbar"], ['foo bar'], [' '], ]; } }