From d560f84b374fa1b3345dc582eddd6bb7b9138674 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Thu, 23 Jun 2016 20:26:19 -0400 Subject: Added models for tags --- tests/units/Model/TagModelTest.php | 120 +++++++++++++++++++++++++++++++++ tests/units/Model/TaskTagModelTest.php | 67 ++++++++++++++++++ 2 files changed, 187 insertions(+) create mode 100644 tests/units/Model/TagModelTest.php create mode 100644 tests/units/Model/TaskTagModelTest.php (limited to 'tests/units/Model') diff --git a/tests/units/Model/TagModelTest.php b/tests/units/Model/TagModelTest.php new file mode 100644 index 00000000..f090ab4a --- /dev/null +++ b/tests/units/Model/TagModelTest.php @@ -0,0 +1,120 @@ +container); + $projectModel = new ProjectModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + $this->assertEquals(1, $tagModel->create(0, 'Tag 1')); + $this->assertEquals(2, $tagModel->create(1, 'Tag 1')); + $this->assertEquals(3, $tagModel->create(1, 'Tag 2')); + $this->assertFalse($tagModel->create(0, 'Tag 1')); + $this->assertFalse($tagModel->create(1, 'Tag 2')); + } + + public function testGetById() + { + $tagModel = new TagModel($this->container); + $this->assertEquals(1, $tagModel->create(0, 'Tag 1')); + + $tag = $tagModel->getById(1); + $this->assertEquals(0, $tag['project_id']); + $this->assertEquals('Tag 1', $tag['name']); + + $tag = $tagModel->getById(3); + $this->assertEmpty($tag); + } + + public function testGetAll() + { + $tagModel = new TagModel($this->container); + $projectModel = new ProjectModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + $this->assertEquals(1, $tagModel->create(0, 'Tag 1')); + $this->assertEquals(2, $tagModel->create(1, 'Tag 2')); + + $tags = $tagModel->getAll(); + $this->assertCount(2, $tags); + $this->assertEquals(0, $tags[0]['project_id']); + $this->assertEquals('Tag 1', $tags[0]['name']); + + $this->assertEquals(1, $tags[1]['project_id']); + $this->assertEquals('Tag 2', $tags[1]['name']); + } + + public function testGetAllByProjectId() + { + $tagModel = new TagModel($this->container); + $projectModel = new ProjectModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + $this->assertEquals(1, $tagModel->create(0, 'Tag 1')); + $this->assertEquals(2, $tagModel->create(1, 'B')); + $this->assertEquals(3, $tagModel->create(1, 'A')); + + $tags = $tagModel->getAllByProject(1); + $this->assertCount(2, $tags); + $this->assertEquals(1, $tags[0]['project_id']); + $this->assertEquals('A', $tags[0]['name']); + + $this->assertEquals(1, $tags[1]['project_id']); + $this->assertEquals('B', $tags[1]['name']); + } + + public function testGetIdByName() + { + $tagModel = new TagModel($this->container); + $projectModel = new ProjectModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + $this->assertEquals(1, $tagModel->create(0, 'Tag 1')); + $this->assertEquals(2, $tagModel->create(1, 'Tag 1')); + $this->assertEquals(3, $tagModel->create(1, 'Tag 3')); + + $this->assertEquals(1, $tagModel->getIdByName(1, 'tag 1')); + $this->assertEquals(1, $tagModel->getIdByName(0, 'tag 1')); + $this->assertEquals(3, $tagModel->getIdByName(1, 'TaG 3')); + } + + public function testFindOrCreateTag() + { + $tagModel = new TagModel($this->container); + $projectModel = new ProjectModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + $this->assertEquals(1, $tagModel->create(0, 'Tag 1')); + + $this->assertEquals(2, $tagModel->findOrCreateTag(1, 'Tag 2')); + $this->assertEquals(2, $tagModel->findOrCreateTag(1, 'Tag 2')); + $this->assertEquals(1, $tagModel->findOrCreateTag(1, 'Tag 1')); + } + + public function testRemove() + { + $tagModel = new TagModel($this->container); + $this->assertEquals(1, $tagModel->create(0, 'Tag 1')); + + $this->assertTrue($tagModel->remove(1)); + $this->assertFalse($tagModel->remove(1)); + } + + public function testUpdate() + { + $tagModel = new TagModel($this->container); + $this->assertEquals(1, $tagModel->create(0, 'Tag 1')); + $this->assertTrue($tagModel->update(1, 'Tag Updated')); + + $tag = $tagModel->getById(1); + $this->assertEquals(0, $tag['project_id']); + $this->assertEquals('Tag Updated', $tag['name']); + } +} diff --git a/tests/units/Model/TaskTagModelTest.php b/tests/units/Model/TaskTagModelTest.php new file mode 100644 index 00000000..c08b571f --- /dev/null +++ b/tests/units/Model/TaskTagModelTest.php @@ -0,0 +1,67 @@ +container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskTagModel = new TaskTagModel($this->container); + $tagModel = new TagModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $this->assertEquals(1, $tagModel->create(0, 'My tag 1')); + $this->assertEquals(2, $tagModel->create(0, 'My tag 2')); + + $this->assertTrue($taskTagModel->save(1, 1, array('My tag 1', 'My tag 2', 'My tag 3'))); + + $tags = $taskTagModel->getAll(1); + $this->assertCount(3, $tags); + + $this->assertEquals(1, $tags[0]['id']); + $this->assertEquals('My tag 1', $tags[0]['name']); + + $this->assertEquals(2, $tags[1]['id']); + $this->assertEquals('My tag 2', $tags[1]['name']); + + $this->assertEquals(3, $tags[2]['id']); + $this->assertEquals('My tag 3', $tags[2]['name']); + + $this->assertTrue($taskTagModel->save(1, 1, array('My tag 3', 'My tag 1', 'My tag 4'))); + + $tags = $taskTagModel->getAll(1); + $this->assertCount(3, $tags); + + $this->assertEquals(1, $tags[0]['id']); + $this->assertEquals('My tag 1', $tags[0]['name']); + + $this->assertEquals(3, $tags[1]['id']); + $this->assertEquals('My tag 3', $tags[1]['name']); + + $this->assertEquals(4, $tags[2]['id']); + $this->assertEquals('My tag 4', $tags[2]['name']); + + $tags = $tagModel->getAll(); + $this->assertCount(4, $tags); + $this->assertEquals('My tag 1', $tags[0]['name']); + $this->assertEquals(0, $tags[0]['project_id']); + + $this->assertEquals('My tag 2', $tags[1]['name']); + $this->assertEquals(0, $tags[1]['project_id']); + + $this->assertEquals('My tag 3', $tags[2]['name']); + $this->assertEquals(1, $tags[2]['project_id']); + + $this->assertEquals('My tag 4', $tags[3]['name']); + $this->assertEquals(1, $tags[3]['project_id']); + } +} -- cgit v1.2.3