container); foreach ($this->container['languageModel']->getLanguages() as $locale => $language) { Translator::unload(); Translator::load($locale); $this->assertNotFalse($projectModel->create(array('name' => 'UnitTest '.$locale)), 'Unable to create project with '.$locale.':'.$language); } Translator::unload(); } public function testCreation() { $projectModel = new ProjectModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); $project = $projectModel->getById(1); $this->assertNotEmpty($project); $this->assertEquals(1, $project['is_active']); $this->assertEquals(0, $project['is_public']); $this->assertEquals(0, $project['is_private']); $this->assertEquals(time(), $project['last_modified'], '', 1); $this->assertEmpty($project['token']); } public function testCreationWithDuplicateName() { $projectModel = new ProjectModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); $this->assertEquals(2, $projectModel->create(array('name' => 'UnitTest'))); } public function testCreationWithStartAndDate() { $projectModel = new ProjectModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest', 'start_date' => '2015-01-01', 'end_date' => '2015-12-31'))); $project = $projectModel->getById(1); $this->assertNotEmpty($project); $this->assertEquals('2015-01-01', $project['start_date']); $this->assertEquals('2015-12-31', $project['end_date']); } public function testCreationWithDefaultCategories() { $projectModel = new ProjectModel($this->container); $configModel = new ConfigModel($this->container); $categoryModel = new CategoryModel($this->container); // Multiple categories correctly formatted $this->assertTrue($configModel->save(array('project_categories' => 'Test1, Test2'))); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest1'))); $project = $projectModel->getById(1); $this->assertNotEmpty($project); $categories = $categoryModel->getAll(1); $this->assertNotEmpty($categories); $this->assertEquals(2, count($categories)); $this->assertEquals('Test1', $categories[0]['name']); $this->assertEquals('Test2', $categories[1]['name']); // Single category $this->assertTrue($configModel->save(array('project_categories' => 'Test1'))); $this->container['memoryCache']->flush(); $this->assertEquals(2, $projectModel->create(array('name' => 'UnitTest2'))); $project = $projectModel->getById(2); $this->assertNotEmpty($project); $categories = $categoryModel->getAll(2); $this->assertNotEmpty($categories); $this->assertEquals(1, count($categories)); $this->assertEquals('Test1', $categories[0]['name']); // Multiple categories badly formatted $this->assertTrue($configModel->save(array('project_categories' => 'ABC, , DEF 3, '))); $this->container['memoryCache']->flush(); $this->assertEquals(3, $projectModel->create(array('name' => 'UnitTest3'))); $project = $projectModel->getById(3); $this->assertNotEmpty($project); $categories = $categoryModel->getAll(3); $this->assertNotEmpty($categories); $this->assertEquals(2, count($categories)); $this->assertEquals('ABC', $categories[0]['name']); $this->assertEquals('DEF 3', $categories[1]['name']); // No default categories $this->assertTrue($configModel->save(array('project_categories' => ' '))); $this->container['memoryCache']->flush(); $this->assertEquals(4, $projectModel->create(array('name' => 'UnitTest4'))); $project = $projectModel->getById(4); $this->assertNotEmpty($project); $categories = $categoryModel->getAll(4); $this->assertEmpty($categories); } public function testUpdateLastModifiedDate() { $projectModel = new ProjectModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); $now = time(); $project = $projectModel->getById(1); $this->assertNotEmpty($project); $this->assertEquals($now, $project['last_modified'], 'Wrong Timestamp', 1); sleep(1); $this->assertTrue($projectModel->updateModificationDate(1)); $project = $projectModel->getById(1); $this->assertNotEmpty($project); $this->assertGreaterThan($now, $project['last_modified']); } public function testGetAllIds() { $projectModel = new ProjectModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); $this->assertEmpty($projectModel->getAllByIds(array())); $this->assertNotEmpty($projectModel->getAllByIds(array(1, 2))); $this->assertCount(1, $projectModel->getAllByIds(array(1))); } public function testIsLastModified() { $projectModel = new ProjectModel($this->container); $taskCreationModel = new TaskCreationModel($this->container); $now = time(); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); $project = $projectModel->getById(1); $this->assertNotEmpty($project); $this->assertEquals($now, $project['last_modified']); sleep(1); $listener = new ProjectModificationDateSubscriber($this->container); $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, array($listener, 'execute')); $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1))); $called = $this->container['dispatcher']->getCalledListeners(); $this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.Kanboard\Subscriber\ProjectModificationDateSubscriber::execute', $called); $project = $projectModel->getById(1); $this->assertNotEmpty($project); $this->assertTrue($projectModel->isModifiedSince(1, $now)); } public function testRemove() { $projectModel = new ProjectModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); $this->assertTrue($projectModel->remove(1)); $this->assertFalse($projectModel->remove(1234)); } public function testEnable() { $projectModel = new ProjectModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); $this->assertTrue($projectModel->disable(1)); $project = $projectModel->getById(1); $this->assertNotEmpty($project); $this->assertEquals(0, $project['is_active']); $this->assertFalse($projectModel->disable(1111)); } public function testDisable() { $projectModel = new ProjectModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); $this->assertTrue($projectModel->disable(1)); $this->assertTrue($projectModel->enable(1)); $project = $projectModel->getById(1); $this->assertNotEmpty($project); $this->assertEquals(1, $project['is_active']); $this->assertFalse($projectModel->enable(1234567)); } public function testEnablePublicAccess() { $projectModel = new ProjectModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); $this->assertTrue($projectModel->enablePublicAccess(1)); $project = $projectModel->getById(1); $this->assertNotEmpty($project); $this->assertEquals(1, $project['is_public']); $this->assertNotEmpty($project['token']); $this->assertFalse($projectModel->enablePublicAccess(123)); } public function testDisablePublicAccess() { $projectModel = new ProjectModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); $this->assertTrue($projectModel->enablePublicAccess(1)); $this->assertTrue($projectModel->disablePublicAccess(1)); $project = $projectModel->getById(1); $this->assertNotEmpty($project); $this->assertEquals(0, $project['is_public']); $this->assertEmpty($project['token']); $this->assertFalse($projectModel->disablePublicAccess(123)); } public function testIdentifier() { $projectModel = new ProjectModel($this->container); // Creation $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest1', 'identifier' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'UnitTest2'))); $project = $projectModel->getById(1); $this->assertNotEmpty($project); $this->assertEquals('TEST1', $project['identifier']); $project = $projectModel->getById(2); $this->assertNotEmpty($project); $this->assertEquals('', $project['identifier']); // Update $this->assertTrue($projectModel->update(array('id' => '2', 'identifier' => 'test2'))); $project = $projectModel->getById(2); $this->assertNotEmpty($project); $this->assertEquals('TEST2', $project['identifier']); $project = $projectModel->getByIdentifier('test1'); $this->assertNotEmpty($project); $this->assertEquals('TEST1', $project['identifier']); $project = $projectModel->getByIdentifier(''); $this->assertFalse($project); } public function testThatProjectCreatorAreAlsoOwner() { $projectModel = new ProjectModel($this->container); $userModel = new UserModel($this->container); $this->assertEquals(2, $userModel->create(array('username' => 'user1', 'name' => 'Me'))); $this->assertEquals(1, $projectModel->create(array('name' => 'My project 1'), 2)); $this->assertEquals(2, $projectModel->create(array('name' => 'My project 2'))); $project = $projectModel->getByIdWithOwner(1); $this->assertNotEmpty($project); $this->assertSame('My project 1', $project['name']); $this->assertSame('Me', $project['owner_name']); $this->assertSame('user1', $project['owner_username']); $this->assertEquals(2, $project['owner_id']); $project = $projectModel->getByIdWithOwner(2); $this->assertNotEmpty($project); $this->assertSame('My project 2', $project['name']); $this->assertEquals('', $project['owner_name']); $this->assertEquals('', $project['owner_username']); $this->assertEquals(0, $project['owner_id']); } }