From 3699073371acc66ccacb56a89e87147a9c90d8c4 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Mon, 11 Jan 2016 22:07:39 -0500 Subject: Move project validator methods --- tests/units/Model/ProjectTest.php | 25 ---------- tests/units/Validator/ProjectValidatorTest.php | 67 ++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 25 deletions(-) create mode 100644 tests/units/Validator/ProjectValidatorTest.php (limited to 'tests/units') diff --git a/tests/units/Model/ProjectTest.php b/tests/units/Model/ProjectTest.php index 4d8e6fc7..990cee5a 100644 --- a/tests/units/Model/ProjectTest.php +++ b/tests/units/Model/ProjectTest.php @@ -277,30 +277,5 @@ class ProjectTest extends Base $project = $p->getByIdentifier(''); $this->assertFalse($project); - - // Validation rules - $r = $p->validateCreation(array('name' => 'test', 'identifier' => 'TEST1')); - $this->assertFalse($r[0]); - - $r = $p->validateCreation(array('name' => 'test', 'identifier' => 'test1')); - $this->assertFalse($r[0]); - - $r = $p->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'TEST1')); - $this->assertTrue($r[0]); - - $r = $p->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'test3')); - $this->assertTrue($r[0]); - - $r = $p->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => '')); - $this->assertTrue($r[0]); - - $r = $p->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'TEST2')); - $this->assertFalse($r[0]); - - $r = $p->validateCreation(array('name' => 'test', 'identifier' => 'a-b-c')); - $this->assertFalse($r[0]); - - $r = $p->validateCreation(array('name' => 'test', 'identifier' => 'test 123')); - $this->assertFalse($r[0]); } } diff --git a/tests/units/Validator/ProjectValidatorTest.php b/tests/units/Validator/ProjectValidatorTest.php new file mode 100644 index 00000000..a73e8247 --- /dev/null +++ b/tests/units/Validator/ProjectValidatorTest.php @@ -0,0 +1,67 @@ +container); + $p = new Project($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'identifier' => 'test1'))); + $this->assertEquals(2, $p->create(array('name' => 'UnitTest2'))); + + $project = $p->getById(1); + $this->assertNotEmpty($project); + $this->assertEquals('TEST1', $project['identifier']); + + $project = $p->getById(2); + $this->assertNotEmpty($project); + $this->assertEquals('', $project['identifier']); + + $r = $validator->validateCreation(array('name' => 'test', 'identifier' => 'TEST1')); + $this->assertFalse($r[0]); + + $r = $validator->validateCreation(array('name' => 'test', 'identifier' => 'test1')); + $this->assertFalse($r[0]); + + $r = $validator->validateCreation(array('name' => 'test', 'identifier' => 'a-b-c')); + $this->assertFalse($r[0]); + + $r = $validator->validateCreation(array('name' => 'test', 'identifier' => 'test 123')); + $this->assertFalse($r[0]); + } + + public function testValidateModification() + { + $validator = new ProjectValidator($this->container); + $p = new Project($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'identifier' => 'test1'))); + $this->assertEquals(2, $p->create(array('name' => 'UnitTest2', 'identifier' => 'TEST2'))); + + $project = $p->getById(1); + $this->assertNotEmpty($project); + $this->assertEquals('TEST1', $project['identifier']); + + $project = $p->getById(2); + $this->assertNotEmpty($project); + $this->assertEquals('TEST2', $project['identifier']); + + $r = $validator->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'TEST1')); + $this->assertTrue($r[0]); + + $r = $validator->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'test3')); + $this->assertTrue($r[0]); + + $r = $validator->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => '')); + $this->assertTrue($r[0]); + + $r = $validator->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'TEST2')); + $this->assertFalse($r[0]); + } +} -- cgit v1.2.3