summaryrefslogtreecommitdiff
path: root/demos
diff options
context:
space:
mode:
authorwei <>2006-07-18 23:39:13 +0000
committerwei <>2006-07-18 23:39:13 +0000
commit2fbc53d1f5d9e0a000717642d02558453bc610a8 (patch)
tree0ab6b464cf6b319f862e075ddd442558971c5aa6 /demos
parent319df8f534520c8c926d0cdaa1f5577c7bd8a909 (diff)
Add more tests and business code for time-tracker
Diffstat (limited to 'demos')
-rw-r--r--demos/time-tracker/index.php2
-rw-r--r--demos/time-tracker/protected/App_Code/Category.php13
-rw-r--r--demos/time-tracker/protected/App_Code/CategoryDao.php50
-rw-r--r--demos/time-tracker/protected/App_Code/DaoManager.php2
-rw-r--r--demos/time-tracker/protected/App_Code/DateTimeMySQL.php33
-rw-r--r--demos/time-tracker/protected/App_Code/Project.php2
-rw-r--r--demos/time-tracker/protected/App_Code/ProjectDao.php115
-rw-r--r--demos/time-tracker/protected/App_Code/TimeEntry.php16
-rw-r--r--demos/time-tracker/protected/App_Code/TimeEntryDao.php47
-rw-r--r--demos/time-tracker/protected/App_Code/UserDao.php10
-rw-r--r--demos/time-tracker/protected/App_Code/UserReport.php10
-rw-r--r--demos/time-tracker/protected/App_Code/UserReportsDao.php25
-rw-r--r--demos/time-tracker/protected/App_Data/mysql-sqlmap.xml14
-rw-r--r--demos/time-tracker/protected/App_Data/users.xml133
-rw-r--r--demos/time-tracker/protected/application.xml3
-rw-r--r--demos/time-tracker/protected/pages/TimeTracker/SiteMap.php2
-rw-r--r--demos/time-tracker/protected/pages/TimeTracker/UserCreate.page136
-rw-r--r--demos/time-tracker/protected/pages/TimeTracker/UserCreate.php64
-rw-r--r--demos/time-tracker/protected/pages/TimeTracker/UserList.page30
-rw-r--r--demos/time-tracker/protected/pages/TimeTracker/UserList.php34
-rw-r--r--demos/time-tracker/tests/unit/CategoryDaoTestCase.php200
-rw-r--r--demos/time-tracker/tests/unit/ProjectDaoTestCase.php200
-rw-r--r--demos/time-tracker/tests/unit/TimeEntryDaoTestCase.php264
-rw-r--r--demos/time-tracker/tests/unit/UserDaoTestCase.php14
-rw-r--r--demos/time-tracker/themes/TimeTracker/site.css16
25 files changed, 1144 insertions, 291 deletions
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 @@
<?php
$basePath=dirname(__FILE__);
-$frameworkPath='../../framework/prado.php';
+$frameworkPath='../../framework/pradolite.php';
$assetsPath=$basePath."/assets";
$runtimePath=$basePath."/protected/runtime";
diff --git a/demos/time-tracker/protected/App_Code/Category.php b/demos/time-tracker/protected/App_Code/Category.php
new file mode 100644
index 00000000..9bdedb5f
--- /dev/null
+++ b/demos/time-tracker/protected/App_Code/Category.php
@@ -0,0 +1,13 @@
+<?php
+
+class Category
+{
+ public $ActualDuration = 0.0;
+ public $Abbreviation = '';
+ public $ID=0;
+ public $EstimateDuration = 0.0;
+ public $Name='';
+ public $ProjectID=0;
+}
+
+?> \ 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 @@
+<?php
+
+class CategoryDao extends BaseDao
+{
+ function addNewCategory($category)
+ {
+ $sqlmap = $this->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 @@
+<?php
+
+class DateTimeMySQL implements ITypeHandlerCallback
+{
+ /**
+ * Not implemented.
+ */
+ public function getParameter($integer)
+ {
+ return date('Y-m-d H:i:s', $integer);
+ }
+
+ /**
+ * Not implemented.
+ */
+ public function getResult($string)
+ {
+ return strtotime($string);
+ }
+
+ /**
+ * Creates a new instance of TimeTrackerUser
+ * @param array result data
+ * @return TimeTrackerUser new user instance
+ */
+ public function createNewInstance($row=null)
+ {
+ throw new TimeTrackerException('Not implemented');
+ }
+
+}
+
+?> \ 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 @@
+<?php
+
+class TimeEntry
+{
+ public $CreatorUserName='';
+ public $Category;
+ public $DateCreated=0;
+ public $Description='';
+ public $Duration=0.0;
+ public $ID=0;
+ public $Project;
+ public $ReportDate=0;
+ public $Username;
+}
+
+?> \ 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 @@
+<?php
+
+class TimeEntryDao extends BaseDao
+{
+ public function addNewTimeEntry($entry)
+ {
+ $sqlmap = $this->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
@@ -34,6 +34,16 @@ class UserDao extends BaseDao
}
/**
+ * @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.
*/
public function getAllUsers()
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 @@
+<?php
+
+class UserReport
+{
+ public $Username = '';
+ public $CategoryID = 0;
+ public $ActualDuration = 0.0;
+}
+
+?> \ 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 @@
+<?php
+
+class UserReportsDao extends BaseDao
+{
+ public function getUserTimeReport($username)
+ {
+ $sqlmap = $this->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 @@
<?xml version="1.0" encoding="UTF-8" ?>
<sqlMapConfig>
- <typeHandler type="TimeTrackerUser"
- callback="TimeTrackerUserTypeHandler"/>
+ <typeHandlers>
+ <typeHandler type="TimeTrackerUser"
+ callback="TimeTrackerUserTypeHandler"/>
+ <typeHandler type="DateTime" callback="DateTimeMySQL" />
+ </typeHandlers>
<provider class="TAdodb">
<datasource
@@ -14,8 +17,11 @@
</provider>
<sqlMaps>
- <sqlMap resource="users.xml"/>
- <sqlMap resource="project.xml"/>
+ <sqlMap resource="mysql-maps/users.xml"/>
+ <sqlMap resource="mysql-maps/projects.xml"/>
+ <sqlMap resource="mysql-maps/category.xml" />
+ <sqlMap resource="mysql-maps/time-entry.xml" />
+ <sqlMap resource="mysql-maps/reports.xml" />
</sqlMaps>
</sqlMapConfig> \ 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 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<sqlMap>
-
-<resultMap id="time-tracker-user" class="TimeTrackerUser" GroupBy="Name">
- <result property="Name" column="Name" />
- <result property="EmailAddress" column="EmailAddress" />
- <result property="Roles" Type="array" resultMapping="user-roles-result" />
-</resultMap>
-
-<resultMap id="user-roles-result">
- <result column="role" />
-</resultMap>
-
-<!--
-<select id="GetUserByName" parameterClass="string" resultMap="TimeTrackerUser">
- SELECT
- users.Username as Name,
- users.EmailAddress as EmailAddress,
- user_roles.RoleType as role
- FROM
- users
- LEFT JOIN user_roles ON users.Username = user_roles.UserID
- WHERE
- Username = #value#
- AND
- Disabled = 0
-</select>
--->
-
-<select id="GetUserByName" parameterClass="string" resultMap="time-tracker-user">
- SELECT
- users.Username as Name,
- users.EmailAddress as EmailAddress,
- user_roles.RoleType as role
- FROM
- users
- LEFT JOIN user_roles ON users.Username = user_roles.UserID
- WHERE
- Username = #value#
- AND
- Disabled = 0
-</select>
-
-<select id="GetAllUsers" resultMap="time-tracker-user">
- SELECT
- users.Username as Name,
- users.EmailAddress as EmailAddress,
- user_roles.RoleType as role
- FROM
- users
- LEFT JOIN user_roles ON users.Username = user_roles.UserID
- WHERE
- Disabled = 0
-</select>
-
-<select id="ValidateUser" resultClass="boolean">
- SELECT
- count(Username)
- FROM
- users
- WHERE
- username = #username# AND password = #password#
- AND
- Disabled = 0
-</select>
-
-<insert id="AddNewUser" parameterClass="array">
- INSERT INTO
- users (Username, Password, EmailAddress)
- VALUES
- (#user.Name#, #password#, #user.EmailAddress#)
-</insert>
-
-<update id="DeleteUserByName">
- UPDATE users SET Disabled = 1 WHERE username = #value#
-</update>
-
-<insert id="RegisterAutoSignon" parameterClass="array">
- INSERT INTO
- signon (SessionToken, Username, LastSignOnDate)
- VALUES
- (#token#, #username#, NOW())
-</insert>
-
-<select id="ValidateAutoSignon" resultMap="time-tracker-user">
- SELECT
- users.Username as Name,
- users.EmailAddress as EmailAddress,
- user_roles.RoleType as role
- FROM
- users LEFT JOIN user_roles ON users.Username = user_roles.UserID,
- signon
- WHERE
- users.Username = signon.Username
- AND signon.SessionToken = #value#
- AND users.Disabled = 0
-</select>
-
-<update id="UpdateSignon">
- UPDATE signon SET LastSignOnDate = NOW()
- WHERE SessionToken = #value#
-</update>
-
-<delete id="DeleteUserRoles" parameterClass="TimeTrackerUser">
- DELETE FROM user_roles WHERE UserID = #Name#
-</delete>
-
-<update id="AddUserRole" parameterClass="array">
- INSERT INTO user_roles (UserID, RoleType)
- VALUES(#username#, #role#)
-</update>
-
-<update id="UpdateUserDetails" parameterClass="TimeTrackerUser">
- UPDATE users
- SET EmailAddress = #EmailAddress#
- WHERE Username = #Name#
-</update>
-
-<update id="UpdateUserDetailsAndPassword" parameterClass="array">
- UPDATE users
- SET EmailAddress = #user.EmailAddress#, Password=#password#
- WHERE Username = #user.Name#
-</update>
-
-<delete id="DeleteAutoSignon">
- DELETE FROM signon WHERE Username = #value#
-</delete>
-
-<delete id="DeleteAllSignon">
- DELETE FROM signon
-</delete>
-
-</sqlMap> \ 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 @@
<module id="daos" class="DaoManager" Connection="sqlmap">
<dao id="UserDao" class="Application.App_Code.UserDao" />
<dao id="ProjectDao" class="Application.App_Code.ProjectDao" />
+ <dao id="TimeEntryDao" class="Application.App_Code.TimeEntryDao" />
+ <dao id="CategoryDao" class="Application.App_Code.CategoryDao" />
+ <dao id="ReportDao" class="Application.App_Code.UserReportsDao" />
</module>
</modules>
<services>
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 @@
<h2>Create New User</h2>
<fieldset class="signup"><legend>User Details</legend>
- <h4>Sign Up for Your New Account</h4>
- <div class="username">
- <com:TLabel ForControl="username" Text="User Name:" />
- <span class="required">*</span>
- <com:TTextBox ID="username" />
- <com:TRequiredFieldValidator
- ControlToValidate="username"
- Display="Dynamic"
- ErrorMessage="Please enter your username."
- ControlCssClass="required-field" />
- <com:TCustomValidator
- ControlToValidate="username"
- Display="Dynamic"
- OnServerValidate="checkUsername" />
- </div>
- <div class="password">
- <com:TLabel ForControl="password" Text="Password:" />
- <span class="required">*</span>
- <com:TTextBox ID="password" TextMode="Password" />
- <com:TRequiredFieldValidator
- ControlToValidate="password"
- Display="Dynamic"
- ErrorMessage="Please enter your password (6 or more characters)."
- ControlCssClass="required-field" />
- <com:TRegularExpressionValidator
- ControlToValidate="password"
- Display="Dynamic"
- RegularExpression="\w{6,}"
- ErrorMessage="Please enter 6 or more characters."
- ControlCssClass="required-field" />
- </div>
- <div class="password">
- <com:TLabel ForControl="password2" Text="Confirm Password:" />
- <span class="required">*</span>
- <com:TTextBox ID="password2" TextMode="Password" />
- <com:TCompareValidator
- ControlToValidate="password"
- ControlToCompare="password2"
- ErrorMessage="The Password and Confirmation Password must match."
- ControlCssClass="required-field" />
- </div>
- <div class="email">
- <com:TLabel ForControl="email" Text="E-Mail Address:" />
- <span class="required">*</span>
- <com:TTextBox ID="email" Style="width:20em"/>
- <com:TRequiredFieldValidator
- ControlToValidate="email"
- Display="Dynamic"
- ErrorMessage="Please enter your E-Mail address."
- ControlCssClass="required-field" />
- <com:TEmailAddressValidator
- ControlToValidate="email"
- Display="Dynamic"
- ErrorMessage="E-Mail address does not seem to be valid."
- ControlCssClass="required-field" />
- </div>
- <com:TPanel Visible=<%= $this->User->isInRole('admin') %> >
+<com:TWizard ID="CreateUserWizard"
+ UseDefaultLayout="false"
+ NavigationStyle.CssClass="wizardNav"
+ OnNextButtonClick="userWizardNextStep"
+ OnCompleteButtonClick="createNewUser"
+ ShowSideBar="false" >
+ <com:TWizardStep>
+ <h4>Sign Up for Your New Account</h4>
+ <div class="username">
+ <com:TLabel ForControl="username" Text="User Name:" />
+ <span class="required">*</span>
+ <com:TTextBox ID="username" />
+ <com:TRequiredFieldValidator
+ ControlToValidate="username"
+ Display="Dynamic"
+ ErrorMessage="Please enter your username."
+ ControlCssClass="required-field" />
+ <com:TCustomValidator
+ ControlToValidate="username"
+ Display="Dynamic"
+ OnServerValidate="checkUsername" />
+ </div>
+ <div class="password">
+ <com:TLabel ForControl="password" Text="Password:" />
+ <span class="required">*</span>
+ <com:TTextBox ID="password" TextMode="Password" />
+ <com:TRequiredFieldValidator
+ ControlToValidate="password"
+ Display="Dynamic"
+ ErrorMessage="Please enter your password (6 or more characters)."
+ ControlCssClass="required-field" />
+ <com:TRegularExpressionValidator
+ ControlToValidate="password"
+ Display="Dynamic"
+ RegularExpression="\w{6,}"
+ ErrorMessage="Please enter 6 or more characters."
+ ControlCssClass="required-field" />
+ </div>
+ <div class="password">
+ <com:TLabel ForControl="password2" Text="Confirm Password:" />
+ <span class="required">*</span>
+ <com:TTextBox ID="password2" TextMode="Password" />
+ <com:TCompareValidator
+ ControlToValidate="password"
+ ControlToCompare="password2"
+ ErrorMessage="The Password and Confirmation Password must match."
+ ControlCssClass="required-field" />
+ </div>
+ <div class="email">
+ <com:TLabel ForControl="email" Text="E-Mail Address:" />
+ <span class="required">*</span>
+ <com:TTextBox ID="email" Style="width:20em"/>
+ <com:TRequiredFieldValidator
+ ControlToValidate="email"
+ Display="Dynamic"
+ ErrorMessage="Please enter your E-Mail address."
+ ControlCssClass="required-field" />
+ <com:TEmailAddressValidator
+ ControlToValidate="email"
+ Display="Dynamic"
+ ErrorMessage="E-Mail address does not seem to be valid."
+ ControlCssClass="required-field" />
+ </div>
+ </com:TWizardStep>
+ <com:TWizardStep>
<com:TLabel ForControl="role" Text="New User Role:" />
<span class="required">*</span>
<com:TDropDownList ID="role">
<com:TListItem Text="Administrator" Value="admin,manager,consultant" />
<com:TListItem Text="Manager" Value="manager,consultant" />
<com:TListItem Text="Consultant" Value="consultant" />
- </com:TDropDownList>
- </com:TPanel>
- <div class="create">
- <com:TButton Text="Create User" OnClick="createNewUser" />
- </div>
+ </com:TDropDownList>
+ </com:TWizardStep>
+ <com:TWizardStep StepType="Complete">
+ New account has been successfully created.
+ <com:TPanel Visible=<%= !$this->User->isInRole('admin') %> CssClass="wizardNav">
+ <com:TButton Text="Continue" OnClick="wizardCompleted"/>
+ </com:TPanel>
+ </com:TWizardStep>
+</com:TWizard>
</fieldset>
</com:TContent> \ 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 <weizhuo[at]gmail[dot]com>
* @version $Revision: $ $16/07/2006: $
@@ -22,6 +24,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.
* @param TServerValidateEventParameter validation parameters.
@@ -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 @@
<com:TContent ID="Main">
<h1>List Users</h1>
+<fieldset>
+ <legend>User List</legend>
+
+ <com:TRepeater ID="list" EnableViewState="false">
+ <prop:HeaderTemplate>
+ <table cellpadding="2">
+ <tr class="header">
+ <th>User Name</th>
+ <th>E-Mail Address</th>
+ </tr>
+ </prop:HeaderTemplate>
+ <prop:ItemTemplate>
+ <tr class="row0">
+ <td><%#$this->DataItem->Name %></td>
+ <td><%#$this->DataItem->EmailAddress %></td>
+ </tr>
+ </prop:ItemTemplate>
+ <prop:AlternatingItemTemplate>
+ <tr class="row1">
+ <td><%#$this->DataItem->Name %></td>
+ <td><%#$this->DataItem->EmailAddress %></td>
+ </tr>
+ </prop:AlternatingItemTemplate>
+ <prop:FooterTemplate>
+ </table>
+ </prop:FooterTemplate>
+</com:TRepeater>
+<div style="padding:1em">
+ <a href="?page=TimeTracker.UserCreate">Create New User</a>
+</div>
</com:TContent> \ 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 @@
+<?php
+/**
+ * UserList page class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 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 <weizhuo[at]gmail[dot]com>
+ * @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 @@
+<?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()
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