diff options
Diffstat (limited to 'demos/time-tracker/tests/unit')
-rw-r--r-- | demos/time-tracker/tests/unit/CategoryDaoTestCase.php | 200 | ||||
-rw-r--r-- | demos/time-tracker/tests/unit/ProjectDaoTestCase.php | 200 | ||||
-rw-r--r-- | demos/time-tracker/tests/unit/TimeEntryDaoTestCase.php | 264 | ||||
-rw-r--r-- | demos/time-tracker/tests/unit/UserDaoTestCase.php | 14 |
4 files changed, 665 insertions, 13 deletions
diff --git a/demos/time-tracker/tests/unit/CategoryDaoTestCase.php b/demos/time-tracker/tests/unit/CategoryDaoTestCase.php new file mode 100644 index 00000000..53ed9c3e --- /dev/null +++ b/demos/time-tracker/tests/unit/CategoryDaoTestCase.php @@ -0,0 +1,200 @@ +<?php
+
+require_once(dirname(__FILE__).'/BaseTestCase.php');
+
+class CategoryDaoTestCase extends BaseTestCase
+{
+ protected $categoryDao;
+ protected $projectDao;
+
+ function setup()
+ {
+ parent::setup();
+ $app = Prado::getApplication();
+ $this->categoryDao = $app->getModule('daos')->getDao('CategoryDao');
+ $this->projectDao = $app->getModule('daos')->getDao('ProjectDao');
+ $this->flushDatabase();
+ }
+
+ function createNewProject()
+ {
+ $project = new Project;
+ $project->CreatorUserName = "admin";
+ $project->DateCreated = time();
+ $project->CompletionDate = strtotime('+1 month');
+ $project->Description = 'Test project 1';
+ $project->EstimateDuration = 100.5;
+ $project->ManagerUserName = 'manager';
+ $project->Name = 'Project 1';
+
+ return $project;
+ }
+
+ function createNewProject2()
+ {
+ $project = new Project;
+ $project->CreatorUserName = "manager";
+ $project->DateCreated = time();
+ $project->CompletionDate = strtotime('+1 week');
+ $project->Description = 'Test project 2';
+ $project->EstimateDuration = 30.5;
+ $project->ManagerUserName = 'manager';
+ $project->Name = 'Project 2';
+
+ return $project;
+ }
+
+ function createNewCategory()
+ {
+ $category = new Category;
+ $category->Name = 'Category 1';
+ $category->EstimateDuration = 5.5;
+ $category->Abbreviation = 'CAT 1';
+
+ return $category;
+ }
+
+ function createNewCategory2()
+ {
+ $category = new Category;
+ $category->Name = 'Category 2';
+ $category->EstimateDuration = 1.5;
+ $category->Abbreviation = 'CAT2';
+
+ return $category;
+ }
+
+ function createNewCategory3()
+ {
+ $category = new Category;
+ $category->Name = 'Category 3';
+ $category->EstimateDuration = 2.5;
+ $category->Abbreviation = 'CAT3';
+
+ return $category;
+ }
+
+ function create3Categories()
+ {
+ $project1 = $this->createNewProject();
+ $this->projectDao->addNewProject($project1);
+
+ $project2 = $this->createNewProject2();
+ $this->projectDao->addNewProject($project2);
+
+ $category1 = $this->createNewCategory();
+ $category1->ProjectID = $project1->ID;
+
+ $category2 = $this->createNewCategory2();
+ $category2->ProjectID = $project2->ID;
+
+ $category3 = $this->createNewCategory3();
+ $category3->ProjectID = $project1->ID;
+
+ $this->categoryDao->addNewCategory($category1);
+ $this->categoryDao->addNewCategory($category2);
+ $this->categoryDao->addNewCategory($category3);
+
+ return array($category1, $category2, $category3);
+ }
+
+ function testCreateNewCategory()
+ {
+ $project = $this->createNewProject();
+ $this->projectDao->addNewProject($project);
+
+ $category = $this->createNewCategory();
+ $category->ProjectID = $project->ID;
+
+ $this->categoryDao->addNewCategory($category);
+
+ $check = $this->categoryDao->getCategoryByID(1);
+ $this->assertEqual($category, $check);
+ }
+
+ function testCreateDuplicateCategory()
+ {
+ $project = $this->createNewProject();
+ $this->projectDao->addNewProject($project);
+
+ $category = $this->createNewCategory();
+ $category->ProjectID = $project->ID;
+
+ $this->categoryDao->addNewCategory($category);
+
+ try
+ {
+ $this->categoryDao->addNewCategory($category);
+ $this->fail();
+ }
+ catch(TSqlMapQueryExecutionException $e)
+ {
+ $this->pass();
+ }
+ $check = $this->categoryDao->getCategoryByID(1);
+ $this->assertEqual($category, $check);
+ }
+
+ function testGetAllCategories()
+ {
+ $added = $this->create3Categories();
+
+ $list = $this->categoryDao->getAllCategories();
+ $this->assertEqual(count($list), 3);
+ $this->assertEqual($added[0], $list[0]);
+ $this->assertEqual($added[1], $list[1]);
+ $this->assertEqual($added[2], $list[2]);
+ }
+
+ function testDeleteCategory()
+ {
+ $added = $this->create3Categories();
+
+ $this->categoryDao->deleteCategory(1);
+
+ $list = $this->categoryDao->getAllCategories();
+
+ $this->assertEqual(count($list), 2);
+ $this->assertEqual($added[1], $list[0]);
+ $this->assertEqual($added[2], $list[1]);
+ }
+
+ function testCategoriesInProject()
+ {
+ $added = $this->create3Categories();
+
+ $list = $this->categoryDao->getCategoriesByProjectID(1);
+
+ $this->assertEqual(count($list), 2);
+ $this->assertEqual($added[0], $list[0]);
+ $this->assertEqual($added[2], $list[1]);
+ }
+
+ function testGetCategoryByCategoryNameandProjectId()
+ {
+ $added = $this->create3Categories();
+ $cat = $this->categoryDao->getCategoryByNameInProject('Category 1', 1);
+
+ $this->assertEqual($cat, $added[0]);
+ }
+
+ function testUpdateCategory()
+ {
+ $project = $this->createNewProject();
+ $this->projectDao->addNewProject($project);
+
+ $category = $this->createNewCategory();
+ $category->ProjectID = $project->ID;
+
+ $this->categoryDao->addNewCategory($category);
+
+ $category->Name = "Test 2";
+ $this->categoryDao->updateCategory($category);
+
+ $check = $this->categoryDao->getCategoryByID($category->ID);
+
+ $this->assertEqual($category, $check);
+ }
+}
+
+?>
\ No newline at end of file diff --git a/demos/time-tracker/tests/unit/ProjectDaoTestCase.php b/demos/time-tracker/tests/unit/ProjectDaoTestCase.php new file mode 100644 index 00000000..bcb9b905 --- /dev/null +++ b/demos/time-tracker/tests/unit/ProjectDaoTestCase.php @@ -0,0 +1,200 @@ +<?php
+
+require_once(dirname(__FILE__).'/BaseTestCase.php');
+
+class ProjectDaoTestCase extends BaseTestCase
+{
+ protected $projectDao;
+
+ function setup()
+ {
+ parent::setup();
+ $app = Prado::getApplication();
+ $this->projectDao = $app->getModule('daos')->getDao('ProjectDao');
+ $this->flushDatabase();
+ }
+
+
+ function createNewProject()
+ {
+ $project = new Project;
+ $project->CreatorUserName = "admin";
+ $project->DateCreated = time();
+ $project->CompletionDate = strtotime('+1 month');
+ $project->Description = 'Test project 1';
+ $project->EstimateDuration = 100.5;
+ $project->ManagerUserName = 'manager';
+ $project->Name = 'Project 1';
+
+ return $project;
+ }
+
+ function createNewProject2()
+ {
+ $project = new Project;
+ $project->CreatorUserName = "manager";
+ $project->DateCreated = time();
+ $project->CompletionDate = strtotime('+1 week');
+ $project->Description = 'Test project 2';
+ $project->EstimateDuration = 30.5;
+ $project->ManagerUserName = 'manager';
+ $project->Name = 'Project 2';
+
+ return $project;
+ }
+
+ function createNewProject3()
+ {
+ $project = new Project;
+ $project->CreatorUserName = "manager";
+ $project->DateCreated = time();
+ $project->CompletionDate = strtotime('+1 day');
+ $project->Description = 'Test project 3';
+ $project->EstimateDuration = 5.0;
+ $project->ManagerUserName = 'admin';
+ $project->Name = 'Project 3';
+
+ return $project;
+ }
+
+ function add3Projects()
+ {
+ $project1 = $this->createNewProject();
+ $project2 = $this->createNewProject2();
+ $project3 = $this->createNewProject3();
+
+ $this->projectDao->addNewProject($project1);
+ $this->projectDao->addNewProject($project2);
+ $this->projectDao->addNewProject($project3);
+ return array($project1,$project2,$project3);
+ }
+
+ function testCreateNewProject()
+ {
+ $newProject = $this->createNewProject();
+ $this->projectDao->addNewProject($newProject);
+
+ $check = $this->projectDao->getProjectByID(1);
+ $this->assertEqual($newProject, $check);
+ }
+
+ function testDeleteProject()
+ {
+ $newProject = $this->createNewProject();
+ $this->projectDao->addNewProject($newProject);
+
+ $check = $this->projectDao->getProjectByID(1);
+ $this->assertEqual($newProject, $check);
+
+ $this->projectDao->deleteProject(1);
+ $verify = $this->projectDao->getProjectByID(1);
+ $this->assertNull($verify);
+ }
+
+ function testAddUserToProject()
+ {
+ $project = $this->createNewProject();
+ $this->projectDao->addNewProject($project);
+
+ $this->projectDao->addUserToProject($project->ID, 'admin');
+ $this->projectDao->addUserToProject($project->ID, 'manager');
+
+ $members = $this->projectDao->getProjectMembers($project->ID);
+
+ $this->assertEqual(count($members), 2);
+ $this->assertEqual($members[0], 'admin');
+ $this->assertEqual($members[1], 'manager');
+ }
+
+ function testAddNullUserToProject()
+ {
+ $project = $this->createNewProject();
+ $this->projectDao->addNewProject($project);
+ try
+ {
+ $this->projectDao->addUserToProject($project->ID, 'asd');
+ $this->fail();
+ }
+ catch(TSqlMapQueryExecutionException $e)
+ {
+ $this->pass();
+ }
+ }
+
+ function testGetAllProjects()
+ {
+ $added = $this->add3Projects();
+
+ $projects = $this->projectDao->getAllProjects();
+
+ $this->assertEqual(count($projects),3);
+ $this->assertEqual($added[0],$projects[0]);
+ $this->assertEqual($added[1],$projects[1]);
+ $this->assertEqual($added[2],$projects[2]);
+ }
+
+ function testGetProjectsByManagerName()
+ {
+ $added = $this->add3Projects();
+
+ $projects = $this->projectDao->getProjectsByManagerName('manager');
+
+ $this->assertEqual(count($projects),2);
+ $this->assertEqual($added[0],$projects[0]);
+ $this->assertEqual($added[1],$projects[1]);
+ }
+
+ function testGetProjectsByUserName()
+ {
+ $added = $this->add3Projects();
+
+ $username = 'consultant';
+
+ $this->projectDao->addUserToProject(1, $username);
+ $this->projectDao->addUserToProject(3, $username);
+
+ $projects = $this->projectDao->getProjectsByUserName($username);
+
+ $this->assertEqual(count($projects),2);
+ $this->assertEqual($added[0],$projects[0]);
+ $this->assertEqual($added[2],$projects[1]);
+ }
+
+ function testRemoveUserFromProject()
+ {
+ $added = $this->add3Projects();
+ $this->projectDao->addUserToProject(1, 'admin');
+ $this->projectDao->addUserToProject(1, 'manager');
+ $this->projectDao->addUserToProject(1, 'consultant');
+
+ $members = $this->projectDao->getProjectMembers(1);
+
+ $this->assertEqual(count($members), 3);
+ $this->assertEqual($members[0], 'admin');
+ $this->assertEqual($members[2], 'manager');
+ $this->assertEqual($members[1], 'consultant');
+
+ $this->projectDao->removeUserFromProject(1,'admin');
+
+ $list = $this->projectDao->getProjectMembers(1);
+
+ $this->assertEqual(count($list), 2);
+ $this->assertEqual($list[1], 'manager');
+ $this->assertEqual($list[0], 'consultant');
+ }
+
+ function testUpdateProject()
+ {
+ $project = $this->createNewProject();
+ $this->projectDao->addNewProject($project);
+
+ $project->Description = "Project Testing 123";
+
+ $this->projectDao->updateProject($project);
+
+ $check = $this->projectDao->getProjectByID(1);
+ $this->assertEqual($check, $project);
+ }
+}
+
+?>
\ No newline at end of file diff --git a/demos/time-tracker/tests/unit/TimeEntryDaoTestCase.php b/demos/time-tracker/tests/unit/TimeEntryDaoTestCase.php new file mode 100644 index 00000000..29e3ba67 --- /dev/null +++ b/demos/time-tracker/tests/unit/TimeEntryDaoTestCase.php @@ -0,0 +1,264 @@ +<?php
+
+require_once(dirname(__FILE__).'/BaseTestCase.php');
+
+class TimeEntryDaoTestCase extends BaseTestCase
+{
+ protected $entryDao;
+ protected $projectDao;
+ protected $userDao;
+ protected $categoryDao;
+ protected $reportDao;
+
+ function setup()
+ {
+ parent::setup();
+ $app = Prado::getApplication();
+ $this->entryDao = $app->getModule('daos')->getDao('TimeEntryDao');
+ $this->projectDao = $app->getModule('daos')->getDao('ProjectDao');
+ $this->userDao = $app->getModule('daos')->getDao('UserDao');
+ $this->categoryDao = $app->getModule('daos')->getDao('CategoryDao');
+ $this->reportDao = $app->getModule('daos')->getDao('ReportDao');
+ $this->flushDatabase();
+ }
+
+ function createNewProject()
+ {
+ $project = new Project;
+ $project->CreatorUserName = "admin";
+ $project->DateCreated = time();
+ $project->CompletionDate = strtotime('+1 month');
+ $project->Description = 'Test project 1';
+ $project->EstimateDuration = 100.5;
+ $project->ManagerUserName = 'manager';
+ $project->Name = 'Project 1';
+
+ return $project;
+ }
+
+ function createNewProject2()
+ {
+ $project = new Project;
+ $project->CreatorUserName = "manager";
+ $project->DateCreated = time();
+ $project->CompletionDate = strtotime('+1 week');
+ $project->Description = 'Test project 2';
+ $project->EstimateDuration = 30.5;
+ $project->ManagerUserName = 'manager';
+ $project->Name = 'Project 2';
+
+ return $project;
+ }
+
+ function createNewCategory()
+ {
+ $category = new Category;
+ $category->Name = 'Category 1';
+ $category->EstimateDuration = 5.5;
+ $category->Abbreviation = 'CAT 1';
+
+ return $category;
+ }
+
+ function createNewCategory2()
+ {
+ $category = new Category;
+ $category->Name = 'Category 2';
+ $category->EstimateDuration = 1.5;
+ $category->Abbreviation = 'CAT2';
+
+ return $category;
+ }
+
+ function createNewCategory3()
+ {
+ $category = new Category;
+ $category->Name = 'Category 3';
+ $category->EstimateDuration = 2.5;
+ $category->Abbreviation = 'CAT3';
+
+ return $category;
+ }
+
+ function createProjectsAndCategories()
+ {
+ $project1 = $this->createNewProject();
+ $this->projectDao->addNewProject($project1);
+
+ $project2 = $this->createNewProject2();
+ $this->projectDao->addNewProject($project2);
+
+ $category1 = $this->createNewCategory();
+ $category1->ProjectID = $project1->ID;
+
+ $category2 = $this->createNewCategory2();
+ $category2->ProjectID = $project2->ID;
+
+ $category3 = $this->createNewCategory3();
+ $category3->ProjectID = $project1->ID;
+
+ $this->categoryDao->addNewCategory($category1);
+ $this->categoryDao->addNewCategory($category2);
+ $this->categoryDao->addNewCategory($category3);
+
+ return array($project1, $project2, $category1, $category2, $category3);
+ }
+
+ function assertSameEntry($entry1, $entry2)
+ {
+ $this->assertEqual($entry1->CreatorUserName, $entry2->CreatorUserName);
+ $this->assertEqual($entry1->Description, $entry2->Description);
+ $this->assertEqual($entry1->Duration, $entry2->Duration);
+ $this->assertEqual($entry1->ID, $entry2->ID);
+ $this->assertEqual($entry1->ReportDate, $entry2->ReportDate);
+ $this->assertEqual($entry1->Username, $entry2->Username);
+ }
+
+
+ function createTimeEntry1()
+ {
+ $added = $this->createProjectsAndCategories();
+
+ $entry = new TimeEntry;
+ $entry->CreatorUserName = "admin";
+ $entry->Category = $added[2];
+ $entry->Description = "New work";
+ $entry->Duration = 1.5;
+ $entry->Project = $added[0];
+ $entry->ReportDate = strtotime('-1 day');
+ $entry->Username = 'consultant';
+
+ return array($entry, $added);
+ }
+
+ function createTimeEntries2()
+ {
+ $added = $this->createProjectsAndCategories();
+
+ $entry = new TimeEntry;
+ $entry->CreatorUserName = "admin";
+ $entry->Category = $added[2];
+ $entry->Description = "New work";
+ $entry->Duration = 1.2;
+ $entry->Project = $added[0];
+ $entry->ReportDate = strtotime('-10 day');
+ $entry->Username = 'consultant';
+
+ $entry2 = new TimeEntry;
+ $entry2->CreatorUserName = "admin";
+ $entry2->Category = $added[4];
+ $entry2->Description = "New work 2";
+ $entry2->Duration = 5.5;
+ $entry2->Project = $added[0];
+ $entry2->ReportDate = strtotime('-4 day');
+ $entry2->Username = 'consultant';
+
+ return array($entry, $entry2, $added);
+ }
+/*
+ function testCreateNewTimeEntry()
+ {
+ $added = $this->createTimeEntry1();
+ $entry = $added[0];
+ $this->entryDao->addNewTimeEntry($entry);
+
+ $check = $this->entryDao->getTimeEntryByID(1);
+
+ $this->assertSameEntry($entry, $check);
+ }
+
+ function testDeleteTimeEntry()
+ {
+ $this->testCreateNewTimeEntry();
+ $this->entryDao->deleteTimeEntry(1);
+
+ $check = $this->entryDao->getTimeEntryByID(1);
+ $this->assertNull($check);
+ }
+
+ function testGetEntriesInProject()
+ {
+ $added = $this->createTimeEntries2();
+ $this->entryDao->addNewTimeEntry($added[0]);
+ $this->entryDao->addNewTimeEntry($added[1]);
+
+ $list = $this->entryDao->getTimeEntriesInProject('consultant', 1);
+
+ $this->assertEqual(count($list), 2);
+
+ $this->assertSameEntry($list[0], $added[0]);
+ $this->assertSameEntry($list[1], $added[1]);
+ }
+
+ function testUpdateEntry()
+ {
+ $added = $this->createTimeEntry1();
+ $entry = $added[0];
+ $this->entryDao->addNewTimeEntry($entry);
+
+ $check = $this->entryDao->getTimeEntryByID(1);
+
+ $this->assertSameEntry($entry, $check);
+
+ $entry->Description = "asdasd";
+ $entry->Duration = 200;
+
+ $this->entryDao->updateTimeEntry($entry);
+
+ $verify = $this->entryDao->getTimeEntryByID(1);
+
+ $this->assertSameEntry($entry, $verify);
+ }
+
+ function testgetEntriesByDate()
+ {
+ $added = $this->createTimeEntries2();
+ $this->entryDao->addNewTimeEntry($added[0]);
+ $this->entryDao->addNewTimeEntry($added[1]);
+
+ $start = strtotime('-5 days');
+ $end = strtotime('-1 day');
+ $list = $this->entryDao->getTimeEntriesByDate('consultant', $start, $end);
+
+ $this->assertEqual(count($list),1);
+
+ $this->assertSameEntry($list[0], $added[1]);
+ }
+
+ function testUserTimeReports()
+ {
+ $added = $this->createTimeEntries2();
+ $this->entryDao->addNewTimeEntry($added[0]);
+ $this->entryDao->addNewTimeEntry($added[1]);
+
+ $time = $this->reportDao->getUserTimeReport('consultant');
+ $this->assertEqual($time, 6.7);
+ }
+
+
+ function testTimeReportsByCategory()
+ {
+ $added = $this->createTimeEntries2();
+ $this->entryDao->addNewTimeEntry($added[0]);
+ $this->entryDao->addNewTimeEntry($added[1]);
+
+ $list = $this->reportDao->getTimeReportsByCategoryID(1);
+ $this->assertEqual(count($list),1);
+ $this->assertEqual($list[0]->Username, 'consultant');
+ $this->assertEqual($list[0]->ActualDuration, 1.2);
+ }
+*/
+ function testTimeReportsByProject()
+ {
+ $added = $this->createTimeEntries2();
+ $this->entryDao->addNewTimeEntry($added[0]);
+ $this->entryDao->addNewTimeEntry($added[1]);
+
+ $list = $this->reportDao->getTimeReportsByProjectID(1);
+
+ var_dump($list);
+ }
+
+}
+
+?>
\ No newline at end of file diff --git a/demos/time-tracker/tests/unit/UserDaoTestCase.php b/demos/time-tracker/tests/unit/UserDaoTestCase.php index d1f3c728..b05d947e 100644 --- a/demos/time-tracker/tests/unit/UserDaoTestCase.php +++ b/demos/time-tracker/tests/unit/UserDaoTestCase.php @@ -11,6 +11,7 @@ class UserDaoTestCase extends BaseTestCase parent::setup();
$app = Prado::getApplication();
$this->userDao = $app->getModule('daos')->getDao('UserDao');
+ $this->flushDatabase();
}
function assertIsAdmin($user)
@@ -105,7 +106,6 @@ class UserDaoTestCase extends BaseTestCase $check = $this->userDao->getUserByName($user->Name);
$this->assertSameUser($check, $user);
- $this->flushDatabase();
}
function testDeleteUserByName()
@@ -117,8 +117,6 @@ class UserDaoTestCase extends BaseTestCase $users = $this->userDao->getAllUsers();
$this->assertEqual(count($users), 2);
-
- $this->flushDatabase();
}
function testAutoSignon()
@@ -131,8 +129,6 @@ class UserDaoTestCase extends BaseTestCase $check = $this->userDao->validateSignon($token);
$this->assertIsAdmin($check);
-
- $this->flushDatabase();
}
@@ -145,8 +141,6 @@ class UserDaoTestCase extends BaseTestCase $check = $this->userDao->validateSignon('adasd');
$this->assertNull($check);
-
- $this->flushDatabase();
}
function testAdminRoles()
@@ -169,8 +163,6 @@ class UserDaoTestCase extends BaseTestCase $this->assertIsManagerRole($check);
$this->assertIsConsultantRole($check);
-
- $this->flushDatabase();
}
function testSetUserRoleNoNullUser()
@@ -206,8 +198,6 @@ class UserDaoTestCase extends BaseTestCase $this->assertIsAdminRole($check);
$this->assertIsManagerRole($check);
$this->assertNotConsultantRole($check);
-
- $this->flushDatabase();
}
function testUpdateUserPassword()
@@ -223,8 +213,6 @@ class UserDaoTestCase extends BaseTestCase $success = $this->userDao->validateUser('admin', $pass);
$this->assertTrue($success);
-
- $this->flushDatabase();
}
function testClearSignonTokens()
|