From 2fbc53d1f5d9e0a000717642d02558453bc610a8 Mon Sep 17 00:00:00 2001 From: wei <> Date: Tue, 18 Jul 2006 23:39:13 +0000 Subject: Add more tests and business code for time-tracker --- demos/time-tracker/index.php | 2 +- demos/time-tracker/protected/App_Code/Category.php | 13 + .../protected/App_Code/CategoryDao.php | 50 ++++ .../time-tracker/protected/App_Code/DaoManager.php | 2 +- .../protected/App_Code/DateTimeMySQL.php | 33 +++ demos/time-tracker/protected/App_Code/Project.php | 2 +- .../time-tracker/protected/App_Code/ProjectDao.php | 115 ++++----- .../time-tracker/protected/App_Code/TimeEntry.php | 16 ++ .../protected/App_Code/TimeEntryDao.php | 47 ++++ demos/time-tracker/protected/App_Code/UserDao.php | 10 + .../time-tracker/protected/App_Code/UserReport.php | 10 + .../protected/App_Code/UserReportsDao.php | 25 ++ .../protected/App_Data/mysql-sqlmap.xml | 14 +- demos/time-tracker/protected/App_Data/users.xml | 133 ----------- demos/time-tracker/protected/application.xml | 3 + .../protected/pages/TimeTracker/SiteMap.php | 2 +- .../protected/pages/TimeTracker/UserCreate.page | 136 ++++++----- .../protected/pages/TimeTracker/UserCreate.php | 64 +++-- .../protected/pages/TimeTracker/UserList.page | 30 +++ .../protected/pages/TimeTracker/UserList.php | 34 +++ .../tests/unit/CategoryDaoTestCase.php | 200 ++++++++++++++++ .../time-tracker/tests/unit/ProjectDaoTestCase.php | 200 ++++++++++++++++ .../tests/unit/TimeEntryDaoTestCase.php | 264 +++++++++++++++++++++ demos/time-tracker/tests/unit/UserDaoTestCase.php | 14 +- demos/time-tracker/themes/TimeTracker/site.css | 16 +- 25 files changed, 1144 insertions(+), 291 deletions(-) create mode 100644 demos/time-tracker/protected/App_Code/Category.php create mode 100644 demos/time-tracker/protected/App_Code/CategoryDao.php create mode 100644 demos/time-tracker/protected/App_Code/DateTimeMySQL.php create mode 100644 demos/time-tracker/protected/App_Code/TimeEntry.php create mode 100644 demos/time-tracker/protected/App_Code/TimeEntryDao.php create mode 100644 demos/time-tracker/protected/App_Code/UserReport.php create mode 100644 demos/time-tracker/protected/App_Code/UserReportsDao.php delete mode 100644 demos/time-tracker/protected/App_Data/users.xml create mode 100644 demos/time-tracker/protected/pages/TimeTracker/UserList.php create mode 100644 demos/time-tracker/tests/unit/CategoryDaoTestCase.php create mode 100644 demos/time-tracker/tests/unit/ProjectDaoTestCase.php create mode 100644 demos/time-tracker/tests/unit/TimeEntryDaoTestCase.php (limited to 'demos') diff --git a/demos/time-tracker/index.php b/demos/time-tracker/index.php index afada2c1..0f8f412a 100644 --- a/demos/time-tracker/index.php +++ b/demos/time-tracker/index.php @@ -1,7 +1,7 @@ \ No newline at end of file diff --git a/demos/time-tracker/protected/App_Code/CategoryDao.php b/demos/time-tracker/protected/App_Code/CategoryDao.php new file mode 100644 index 00000000..f0149f0b --- /dev/null +++ b/demos/time-tracker/protected/App_Code/CategoryDao.php @@ -0,0 +1,50 @@ +getConnection(); + $sqlmap->insert('AddNewCategory', $category); + } + + function getCategoryByID($categoryID) + { + $sqlmap = $this->getConnection(); + return $sqlmap->queryForObject('GetCategoryByID', $categoryID); + } + + function getAllCategories() + { + $sqlmap = $this->getConnection(); + return $sqlmap->queryForList('GetAllCategories'); + } + + function deleteCategory($categoryID) + { + $sqlmap = $this->getConnection(); + $sqlmap->delete('DeleteCategory', $categoryID); + } + + function getCategoriesByProjectID($projectID) + { + $sqlmap = $this->getConnection(); + return $sqlmap->queryForList('GetCategoriesByProjectID', $projectID); + } + + function getCategoryByNameInProject($name, $projectID) + { + $sqlmap = $this->getConnection(); + $param['project'] = $projectID; + $param['category'] = $name; + return $sqlmap->queryForObject('GetCategoryByNameInProject', $param); + } + + function updateCategory($category) + { + $sqlmap = $this->getConnection(); + $sqlmap->update('UpdateCategory', $category); + } +} + +?> \ No newline at end of file diff --git a/demos/time-tracker/protected/App_Code/DaoManager.php b/demos/time-tracker/protected/App_Code/DaoManager.php index b8ac55af..ac546054 100644 --- a/demos/time-tracker/protected/App_Code/DaoManager.php +++ b/demos/time-tracker/protected/App_Code/DaoManager.php @@ -98,7 +98,7 @@ class DaoManager extends TModule return $this->_dao[$class]['instance']; } else - throw TimeTrackerException('daomanager_undefined_dao', $class); + throw new TimeTrackerException('daomanager_undefined_dao', $class); } /** diff --git a/demos/time-tracker/protected/App_Code/DateTimeMySQL.php b/demos/time-tracker/protected/App_Code/DateTimeMySQL.php new file mode 100644 index 00000000..19f41c03 --- /dev/null +++ b/demos/time-tracker/protected/App_Code/DateTimeMySQL.php @@ -0,0 +1,33 @@ + \ No newline at end of file diff --git a/demos/time-tracker/protected/App_Code/Project.php b/demos/time-tracker/protected/App_Code/Project.php index 660fad04..bd9c858b 100644 --- a/demos/time-tracker/protected/App_Code/Project.php +++ b/demos/time-tracker/protected/App_Code/Project.php @@ -25,7 +25,7 @@ class Project public $CompletionDate = 0; public $DateCreated = 0; public $Description = ''; - public $EstimateDuration = 0; + public $EstimateDuration = 0.0; public $ID = 0; public $ManagerUserName = ''; public $Name = ''; diff --git a/demos/time-tracker/protected/App_Code/ProjectDao.php b/demos/time-tracker/protected/App_Code/ProjectDao.php index 81902e0c..416c6540 100644 --- a/demos/time-tracker/protected/App_Code/ProjectDao.php +++ b/demos/time-tracker/protected/App_Code/ProjectDao.php @@ -20,32 +20,17 @@ */ class ProjectDao extends BaseDao { -/* public function createNewProject($project) + public function projectNameExists($projectName) { $sqlmap = $this->getConnection(); - $creator = $sqlmap->queryForObject('GetUserByName', $project->CreatorUserName); - $manager = $sqlmap->queryForObject('GetUserByName', $project->ManagerUserName); - $exists = $sqlmap->queryForObject('GetProjectByName', $project->Name); - if($exists) - { - throw new TimeTrackerException( - 'project_exists', $project->Name); - } - else if(!$creator || !$manager) - { - throw new TimeTrackerException( - 'invalid_creator_and_manager', - $project->Name, $project->CreatorUserName, - $project->ManagerUserName); - } - else - { - $param['project'] = $project; - $param['creator'] = $creator->ID; - $param['manager'] = $manager->ID; - return $sqlmap->insert('CreateNewProject', $param); - } - } + return $sqlmap->queryForObject('ProjectNameExists', $projectName); + } + + public function addNewProject($project) + { + $sqlmap = $this->getConnection(); + $sqlmap->insert('CreateNewProject', $project); + } public function getProjectByID($projectID) { @@ -53,41 +38,61 @@ class ProjectDao extends BaseDao return $sqlmap->queryForObject('GetProjectByID', $projectID); } - public function addUserToProject($project, $user) + public function deleteProject($projectID) { $sqlmap = $this->getConnection(); - $project = $this->getProjectByID($project->ID); - $user = $sqlmap->queryForObject('GetUserByName', $user->Name); - $list = $sqlmap->queryForList('GetProjectMembers', $project); - $userExists = false; - foreach($list as $k) - { - if($k->ID == $user->ID) - $userExists = true; - } - if(!$project) - { - throw new TimeTrackerException( - 'invalid_project', $project->Name); - } - else if(!$user) - { - throw new TimeTrackerException( - 'invalid_user', $user->Name); - } - else if($userExists) - { - throw new TimeTrackerException( - 'project_member_exists', $projet->Name, $user->Name); - } - else + $sqlmap->update('DeleteProject',$projectID); + } + + public function addUserToProject($projectID, $username) + { + $sqlmap = $this->getConnection(); + $members = $this->getProjectMembers($projectID); + if(!in_array($username, $members)) { - $param['project'] = $project; - $param['user'] = $user; - return $sqlmap->insert('AddUserToProject', $param); - } + $param['username'] = $username; + $param['project'] = $projectID; + $sqlmap->insert('AddUserToProject',$param); + } + } + + public function getProjectMembers($projectID) + { + $sqlmap = $this->getConnection(); + return $sqlmap->queryForList('GetProjectMembers', $projectID); + } + + public function getAllProjects() + { + $sqlmap = $this->getConnection(); + return $sqlmap->queryForList('GetAllProjects'); + } + + public function getProjectsByManagerName($manager) + { + $sqlmap = $this->getConnection(); + return $sqlmap->queryForList('GetProjectsByManagerName', $manager); + } + + public function getProjectsByUserName($username) + { + $sqlmap = $this->getConnection(); + return $sqlmap->queryForList('GetProjectsByUserName', $username); + } + + public function removeUserFromProject($projectID, $username) + { + $sqlmap = $this->getConnection(); + $param['username'] = $username; + $param['project'] = $projectID; + $sqlmap->delete('RemoveUserFromProject', $param); + } + + public function updateProject($project) + { + $sqlmap = $this->getConnection(); + $sqlmap->update('UpdateProject', $project); } -*/ } ?> \ No newline at end of file diff --git a/demos/time-tracker/protected/App_Code/TimeEntry.php b/demos/time-tracker/protected/App_Code/TimeEntry.php new file mode 100644 index 00000000..e250d67f --- /dev/null +++ b/demos/time-tracker/protected/App_Code/TimeEntry.php @@ -0,0 +1,16 @@ + \ No newline at end of file diff --git a/demos/time-tracker/protected/App_Code/TimeEntryDao.php b/demos/time-tracker/protected/App_Code/TimeEntryDao.php new file mode 100644 index 00000000..60301f3b --- /dev/null +++ b/demos/time-tracker/protected/App_Code/TimeEntryDao.php @@ -0,0 +1,47 @@ +getConnection(); + $sqlmap->insert('AddNewTimeEntry', $entry); + } + + public function getTimeEntryByID($entryID) + { + $sqlmap = $this->getConnection(); + return $sqlmap->queryForObject('GetTimeEntryByID', $entryID); + } + + public function deleteTimeEntry($entryID) + { + $sqlmap = $this->getConnection(); + $sqlmap->delete('DeleteTimeEntry', $entryID); + } + + public function getTimeEntriesInProject($username, $projectID) + { + $sqlmap = $this->getConnection(); + $param['username'] = $username; + $param['project'] = $projectID; + return $sqlmap->queryForList('GetAllTimeEntriesByProjectIdAndUser', $param); + } + + public function updateTimeEntry($entry) + { + $sqlmap = $this->getConnection(); + $sqlmap->update('UpdateTimeEntry', $entry); + } + + public function getTimeEntriesByDate($username, $start, $end) + { + $sqlmap = $this->getConnection(); + $param['username'] = $username; + $param['startDate'] = $start; + $param['endDate'] = $end; + return $sqlmap->queryForList('GetTimeEntriesByDate', $param); + } +} + +?> \ No newline at end of file diff --git a/demos/time-tracker/protected/App_Code/UserDao.php b/demos/time-tracker/protected/App_Code/UserDao.php index 4dc39b2b..6064be7e 100644 --- a/demos/time-tracker/protected/App_Code/UserDao.php +++ b/demos/time-tracker/protected/App_Code/UserDao.php @@ -33,6 +33,16 @@ class UserDao extends BaseDao return $sqlmap->queryForObject('GetUserByName', $username); } + /** + * @param string username + * @return boolean true if username already exists, false otherwise. + */ + public function usernameExists($username) + { + $sqlmap = $this->getConnection(); + return $sqlmap->queryForObject('UsernameExists', $username); + } + /** * @return array list of all enabled users. */ diff --git a/demos/time-tracker/protected/App_Code/UserReport.php b/demos/time-tracker/protected/App_Code/UserReport.php new file mode 100644 index 00000000..e7529120 --- /dev/null +++ b/demos/time-tracker/protected/App_Code/UserReport.php @@ -0,0 +1,10 @@ + \ No newline at end of file diff --git a/demos/time-tracker/protected/App_Code/UserReportsDao.php b/demos/time-tracker/protected/App_Code/UserReportsDao.php new file mode 100644 index 00000000..3cf943af --- /dev/null +++ b/demos/time-tracker/protected/App_Code/UserReportsDao.php @@ -0,0 +1,25 @@ +getConnection(); + return $sqlmap->queryForObject('GetTimeReportByUsername', $username); + } + + public function getTimeReportsByCategoryID($categoryID) + { + $sqlmap = $this->getConnection(); + return $sqlmap->queryForList('GetTimeReportByCategoryID', $categoryID); + } + + public function getTimeReportsByProjectID($projectID) + { + $sqlmap = $this->getConnection(); + return $sqlmap->queryForList('GetTimeReportByProjectID', $projectID); + } + +} + +?> \ No newline at end of file diff --git a/demos/time-tracker/protected/App_Data/mysql-sqlmap.xml b/demos/time-tracker/protected/App_Data/mysql-sqlmap.xml index fe4ebedc..3f850955 100644 --- a/demos/time-tracker/protected/App_Data/mysql-sqlmap.xml +++ b/demos/time-tracker/protected/App_Data/mysql-sqlmap.xml @@ -1,8 +1,11 @@ - + + + + - - + + + + + \ No newline at end of file diff --git a/demos/time-tracker/protected/App_Data/users.xml b/demos/time-tracker/protected/App_Data/users.xml deleted file mode 100644 index f4151c30..00000000 --- a/demos/time-tracker/protected/App_Data/users.xml +++ /dev/null @@ -1,133 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - INSERT INTO - users (Username, Password, EmailAddress) - VALUES - (#user.Name#, #password#, #user.EmailAddress#) - - - - UPDATE users SET Disabled = 1 WHERE username = #value# - - - - INSERT INTO - signon (SessionToken, Username, LastSignOnDate) - VALUES - (#token#, #username#, NOW()) - - - - - - UPDATE signon SET LastSignOnDate = NOW() - WHERE SessionToken = #value# - - - - DELETE FROM user_roles WHERE UserID = #Name# - - - - INSERT INTO user_roles (UserID, RoleType) - VALUES(#username#, #role#) - - - - UPDATE users - SET EmailAddress = #EmailAddress# - WHERE Username = #Name# - - - - UPDATE users - SET EmailAddress = #user.EmailAddress#, Password=#password# - WHERE Username = #user.Name# - - - - DELETE FROM signon WHERE Username = #value# - - - - DELETE FROM signon - - - \ No newline at end of file diff --git a/demos/time-tracker/protected/application.xml b/demos/time-tracker/protected/application.xml index 801b6eb3..e7d3b330 100644 --- a/demos/time-tracker/protected/application.xml +++ b/demos/time-tracker/protected/application.xml @@ -15,6 +15,9 @@ + + + diff --git a/demos/time-tracker/protected/pages/TimeTracker/SiteMap.php b/demos/time-tracker/protected/pages/TimeTracker/SiteMap.php index 1f452894..1beed757 100644 --- a/demos/time-tracker/protected/pages/TimeTracker/SiteMap.php +++ b/demos/time-tracker/protected/pages/TimeTracker/SiteMap.php @@ -43,7 +43,7 @@ class SiteMap extends TTemplateControl case 'ReportResource': $active = $this->ReportMenu; break; - case 'TimeEntry': + default: $active = $this->LogMenu; break; } diff --git a/demos/time-tracker/protected/pages/TimeTracker/UserCreate.page b/demos/time-tracker/protected/pages/TimeTracker/UserCreate.page index 41d97391..edc22bcd 100644 --- a/demos/time-tracker/protected/pages/TimeTracker/UserCreate.page +++ b/demos/time-tracker/protected/pages/TimeTracker/UserCreate.page @@ -2,74 +2,86 @@

Create New User

User Details -

Sign Up for Your New Account

-
- - * - - - -
-
- - * - - - -
-
- - * - - -
- - User->isInRole('admin') %> > + + +

Sign Up for Your New Account

+
+ + * + + + +
+
+ + * + + + +
+
+ + * + + +
+ +
+ * - -
-
- -
+ + + + New account has been successfully created. + User->isInRole('admin') %> CssClass="wizardNav"> + + + +
\ No newline at end of file diff --git a/demos/time-tracker/protected/pages/TimeTracker/UserCreate.php b/demos/time-tracker/protected/pages/TimeTracker/UserCreate.php index f163ecd6..ed8ea4f1 100644 --- a/demos/time-tracker/protected/pages/TimeTracker/UserCreate.php +++ b/demos/time-tracker/protected/pages/TimeTracker/UserCreate.php @@ -11,8 +11,10 @@ */ /** - * Create new user page class. Validate that the usernames are unique - * and set the new user credentials as the current application credentials. + * Create new user wizard page class. Validate that the usernames are unique and + * set the new user credentials as the current application credentials. + * + * If logged in as admin, the user role can be change during creation. * * @author Wei Zhuo * @version $Revision: $ $16/07/2006: $ @@ -21,6 +23,18 @@ */ class UserCreate extends TPage { + /** + * Sets the default new user roles, default role is set in config.xml + */ + public function onLoad($param) + { + if(!$this->IsPostBack) + { + $this->role->SelectedValue = + $this->Application->Parameters['NewUserRoles']; + } + } + /** * Verify that the username is not taken. * @param TControl custom validator that created the event. @@ -29,12 +43,27 @@ class UserCreate extends TPage public function checkUsername($sender, $param) { $userDao = $this->Application->Modules['daos']->getDao('UserDao'); - $user = $userDao->getUserByName($this->username->Text); - if(!is_null($user)) + if($userDao->usernameExists($this->username->Text)) { $param->IsValid = false; $sender->ErrorMessage = - "The user name is already taken, try '{$user->Name}01'"; + "The user name is already taken, try '{$this->username->Text}01'"; + } + } + + /** + * Skip the role assignment step if not admin. + */ + public function userWizardNextStep($sender, $param) + { + if($param->CurrentStepIndex == 0) + { + //create user with admin credentials + if(!$this->User->isInRole('admin')) + { + $this->createNewUser($sender, $param); + $param->NextStepIndex = 2; + } } } @@ -54,31 +83,30 @@ class UserCreate extends TPage $newUser->EmailAddress = $this->email->Text; $newUser->Name = $this->username->Text; $newUser->IsGuest = false; - if($this->User->isInRole('admin')) - $newUser->Roles = $this->role->SelectedValue; - else - $newUser->Roles = $this->Application->Parameters['NewUserRoles']; + $newUser->Roles = $this->role->SelectedValue; //save the user $userDao = $this->Application->Modules['daos']->getDao('UserDao'); $userDao->addNewUser($newUser, $this->password->Text); - //update the user + //update the user credentials if not admin if(!$this->User->isInRole('admin')) { $auth = $this->Application->getModule('auth'); $auth->updateCredential($newUser); - - //return to requested page - $this->Response->redirect($auth->getReturnUrl()); } - else - $this->Response->reload(); - //goto default page. - //$url = $this->Service->constructUrl($this->Service->DefaultPage); - //$this->Response->redirect($url); } } + + /** + * Continue with requested page. + */ + public function wizardCompleted($sender, $param) + { + //return to requested page + $auth = $this->Application->getModule('auth'); + $this->Response->redirect($auth->getReturnUrl()); + } } ?> \ No newline at end of file diff --git a/demos/time-tracker/protected/pages/TimeTracker/UserList.page b/demos/time-tracker/protected/pages/TimeTracker/UserList.page index 48b2bbc7..f0c88112 100644 --- a/demos/time-tracker/protected/pages/TimeTracker/UserList.page +++ b/demos/time-tracker/protected/pages/TimeTracker/UserList.page @@ -1,3 +1,33 @@

List Users

+
+ User List + + + + + + + + + + + + + + + + + + + + + + +
User NameE-Mail Address
<%#$this->DataItem->Name %><%#$this->DataItem->EmailAddress %>
<%#$this->DataItem->Name %><%#$this->DataItem->EmailAddress %>
+ +
+
+ Create New User +
\ No newline at end of file diff --git a/demos/time-tracker/protected/pages/TimeTracker/UserList.php b/demos/time-tracker/protected/pages/TimeTracker/UserList.php new file mode 100644 index 00000000..175a731a --- /dev/null +++ b/demos/time-tracker/protected/pages/TimeTracker/UserList.php @@ -0,0 +1,34 @@ + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Revision: $ $18/07/2006: $ + * @package Demos + */ + +/** + * List all users in a repeater. + * + * @author Wei Zhuo + * @version $Revision: $ $18/07/2006: $ + * @package Demos + * @since 3.1 + */ +class UserList extends TPage +{ + /** + * Load all the users and display them in a repeater. + */ + function onLoad($param) + { + $userDao = $this->Application->Modules['daos']->getDao('UserDao'); + $this->list->DataSource = $userDao->getAllUsers(); + $this->list->dataBind(); + } +} + +?> \ No newline at end of file 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 @@ +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 @@ +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 @@ +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() diff --git a/demos/time-tracker/themes/TimeTracker/site.css b/demos/time-tracker/themes/TimeTracker/site.css index f426243e..386260a6 100644 --- a/demos/time-tracker/themes/TimeTracker/site.css +++ b/demos/time-tracker/themes/TimeTracker/site.css @@ -155,7 +155,7 @@ li.active ul.level2 li a:hover /** forms **/ -fieldset.login, fieldset.signup +fieldset { margin: 0; border: 1px solid #6495ED; @@ -210,8 +210,20 @@ fieldset.login .signin input margin-left: 133px; } -fieldset.signup .create +fieldset.signup .wizardNav { margin: 1em; padding-left: 9em; +} + +/** list */ + +.row0 +{ + background-color: #cdf; +} + +.row1 +{ + background-color: #eef; } \ No newline at end of file -- cgit v1.2.3