summaryrefslogtreecommitdiff
path: root/demos/time-tracker/tests/unit
diff options
context:
space:
mode:
authorctrlaltca <>2012-07-12 11:21:01 +0000
committerctrlaltca <>2012-07-12 11:21:01 +0000
commit903ae8a581fac1e6917fc3e31d2ad8fb91df80c3 (patch)
treee08bf04f0823650a231227ac3499121270172a23 /demos/time-tracker/tests/unit
parent3e4e6e66aeb3f8fea4e1eb4237498ef9d2358f63 (diff)
standardize the use of unix eol; use svn properties to enforce native eol
Diffstat (limited to 'demos/time-tracker/tests/unit')
-rw-r--r--demos/time-tracker/tests/unit/BaseTestCase.php126
-rw-r--r--demos/time-tracker/tests/unit/CategoryDaoTestCase.php400
-rw-r--r--demos/time-tracker/tests/unit/ProjectDaoTestCase.php398
-rw-r--r--demos/time-tracker/tests/unit/TimeEntryDaoTestCase.php426
-rw-r--r--demos/time-tracker/tests/unit/UserDaoTestCase.php540
5 files changed, 945 insertions, 945 deletions
diff --git a/demos/time-tracker/tests/unit/BaseTestCase.php b/demos/time-tracker/tests/unit/BaseTestCase.php
index d72cbc5c..10df400f 100644
--- a/demos/time-tracker/tests/unit/BaseTestCase.php
+++ b/demos/time-tracker/tests/unit/BaseTestCase.php
@@ -1,64 +1,64 @@
-<?php
-
-
-Prado::using('Application.App_Code.Dao.*');
-
-class BaseTestCase extends UnitTestCase
-{
- protected $sqlmap;
-
- function setup()
- {
- $app = Prado::getApplication();
- $this->sqlmap = $app->getModule('daos')->getClient();
- }
-
-
- function flushDatabase()
- {
- $conn = $this->sqlmap->getDbConnection();
- $find = 'sqlite:protected';
- if(is_int(strpos($conn->getConnectionString(),$find)))
- $conn->ConnectionString = str_replace($find, 'sqlite:../protected', $conn->ConnectionString);
- $conn->setActive(false);
- $conn->setActive(true);
- switch(strtolower($conn->getDriverName()))
- {
- case 'mysql':
- return $this->flushMySQLDatabase();
- case 'sqlite':
- return $this->flushSQLiteDatabase();
- }
- }
-
- function flushSQLiteDatabase()
- {
- $conn = $this->sqlmap->getDbConnection();
- $file = str_replace('sqlite:','',$conn->getConnectionString());
- $backup = $file.'.bak';
- copy($backup, $file);
- }
-
- function flushMySQLDatabase()
- {
- $conn = $this->sqlmap->getDbConnection();
- $file = Prado::getPathOfNamespace('Application.App_Data.MySQL4.mysql-reset','.sql');
- if(is_file($file))
- $this->runScript($conn, $file);
- else
- throw new Exception('unable to find script file '.$file);
- }
-
- protected function runScript($connection, $script)
- {
- $sql = file_get_contents($script);
- $lines = explode(';', $sql);
- foreach($lines as $line)
- {
- $line = trim($line);
- if(strlen($line) > 0)
- $connection->createCommand($line)->execute();
- }
- }
-}
+<?php
+
+
+Prado::using('Application.App_Code.Dao.*');
+
+class BaseTestCase extends UnitTestCase
+{
+ protected $sqlmap;
+
+ function setup()
+ {
+ $app = Prado::getApplication();
+ $this->sqlmap = $app->getModule('daos')->getClient();
+ }
+
+
+ function flushDatabase()
+ {
+ $conn = $this->sqlmap->getDbConnection();
+ $find = 'sqlite:protected';
+ if(is_int(strpos($conn->getConnectionString(),$find)))
+ $conn->ConnectionString = str_replace($find, 'sqlite:../protected', $conn->ConnectionString);
+ $conn->setActive(false);
+ $conn->setActive(true);
+ switch(strtolower($conn->getDriverName()))
+ {
+ case 'mysql':
+ return $this->flushMySQLDatabase();
+ case 'sqlite':
+ return $this->flushSQLiteDatabase();
+ }
+ }
+
+ function flushSQLiteDatabase()
+ {
+ $conn = $this->sqlmap->getDbConnection();
+ $file = str_replace('sqlite:','',$conn->getConnectionString());
+ $backup = $file.'.bak';
+ copy($backup, $file);
+ }
+
+ function flushMySQLDatabase()
+ {
+ $conn = $this->sqlmap->getDbConnection();
+ $file = Prado::getPathOfNamespace('Application.App_Data.MySQL4.mysql-reset','.sql');
+ if(is_file($file))
+ $this->runScript($conn, $file);
+ else
+ throw new Exception('unable to find script file '.$file);
+ }
+
+ protected function runScript($connection, $script)
+ {
+ $sql = file_get_contents($script);
+ $lines = explode(';', $sql);
+ foreach($lines as $line)
+ {
+ $line = trim($line);
+ if(strlen($line) > 0)
+ $connection->createCommand($line)->execute();
+ }
+ }
+}
?> \ No newline at end of file
diff --git a/demos/time-tracker/tests/unit/CategoryDaoTestCase.php b/demos/time-tracker/tests/unit/CategoryDaoTestCase.php
index d47fa7ce..e018b0b0 100644
--- a/demos/time-tracker/tests/unit/CategoryDaoTestCase.php
+++ b/demos/time-tracker/tests/unit/CategoryDaoTestCase.php
@@ -1,201 +1,201 @@
-<?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 ProjectRecord;
- $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 ProjectRecord;
- $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 CategoryRecord;
- $category->Name = 'Category 1';
- $category->EstimateDuration = 5.5;
- $category->Abbreviation = 'CAT 1';
-
- return $category;
- }
-
- function createNewCategory2()
- {
- $category = new CategoryRecord;
- $category->Name = 'Category 2';
- $category->EstimateDuration = 1.5;
- $category->Abbreviation = 'CAT2';
-
- return $category;
- }
-
- function createNewCategory3()
- {
- $category = new CategoryRecord;
- $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->pass();
- }
- catch(TSqlMapQueryExecutionException $e)
- {
- $this->fail();
- }
- $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);
- }
-}
-
+<?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 ProjectRecord;
+ $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 ProjectRecord;
+ $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 CategoryRecord;
+ $category->Name = 'Category 1';
+ $category->EstimateDuration = 5.5;
+ $category->Abbreviation = 'CAT 1';
+
+ return $category;
+ }
+
+ function createNewCategory2()
+ {
+ $category = new CategoryRecord;
+ $category->Name = 'Category 2';
+ $category->EstimateDuration = 1.5;
+ $category->Abbreviation = 'CAT2';
+
+ return $category;
+ }
+
+ function createNewCategory3()
+ {
+ $category = new CategoryRecord;
+ $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->pass();
+ }
+ catch(TSqlMapQueryExecutionException $e)
+ {
+ $this->fail();
+ }
+ $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
index 22a01fca..1790f4d0 100644
--- a/demos/time-tracker/tests/unit/ProjectDaoTestCase.php
+++ b/demos/time-tracker/tests/unit/ProjectDaoTestCase.php
@@ -1,200 +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 ProjectRecord;
- $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 ProjectRecord;
- $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 ProjectRecord;
- $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(TDbException $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);
- }
-}
-
+<?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 ProjectRecord;
+ $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 ProjectRecord;
+ $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 ProjectRecord;
+ $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(TDbException $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
index 1ce97b3a..cead9fba 100644
--- a/demos/time-tracker/tests/unit/TimeEntryDaoTestCase.php
+++ b/demos/time-tracker/tests/unit/TimeEntryDaoTestCase.php
@@ -1,214 +1,214 @@
-<?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 ProjectRecord;
- $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 ProjectRecord;
- $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 CategoryRecord;
- $category->Name = 'Category 1';
- $category->EstimateDuration = 5.5;
- $category->Abbreviation = 'CAT 1';
-
- return $category;
- }
-
- function createNewCategory2()
- {
- $category = new CategoryRecord;
- $category->Name = 'Category 2';
- $category->EstimateDuration = 1.5;
- $category->Abbreviation = 'CAT2';
-
- return $category;
- }
-
- function createNewCategory3()
- {
- $category = new CategoryRecord;
- $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 TimeEntryRecord;
- $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 TimeEntryRecord;
- $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 TimeEntryRecord;
- $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);
- }
-}
-
+<?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 ProjectRecord;
+ $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 ProjectRecord;
+ $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 CategoryRecord;
+ $category->Name = 'Category 1';
+ $category->EstimateDuration = 5.5;
+ $category->Abbreviation = 'CAT 1';
+
+ return $category;
+ }
+
+ function createNewCategory2()
+ {
+ $category = new CategoryRecord;
+ $category->Name = 'Category 2';
+ $category->EstimateDuration = 1.5;
+ $category->Abbreviation = 'CAT2';
+
+ return $category;
+ }
+
+ function createNewCategory3()
+ {
+ $category = new CategoryRecord;
+ $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 TimeEntryRecord;
+ $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 TimeEntryRecord;
+ $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 TimeEntryRecord;
+ $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);
+ }
+}
+
?> \ 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 d216dbe6..ce40092e 100644
--- a/demos/time-tracker/tests/unit/UserDaoTestCase.php
+++ b/demos/time-tracker/tests/unit/UserDaoTestCase.php
@@ -1,271 +1,271 @@
-<?php
-
-require_once(dirname(__FILE__).'/BaseTestCase.php');
-
-class UserDaoTestCase extends BaseTestCase
-{
- protected $userDao;
-
- function setup()
- {
- parent::setup();
- $app = Prado::getApplication();
- $this->userDao = $app->getModule('daos')->getDao('UserDao');
- $this->flushDatabase();
- }
-
- function assertIsAdmin($user)
- {
- if(!$user)
- return $this->fail();
- $this->assertEqual($user->getName(), 'admin');
- $this->assertEqual($user->getEmailAddress(), 'admin@pradosoft.com');
- }
-
- function assertSameUser($user1, $user2)
- {
- if(is_null($user1) || is_null($user2))
- return $this->fail();
-
- $this->assertEqual($user1->getName(), $user2->getName());
- $this->assertEqual($user1->getEmailAddress(), $user2->getEmailAddress());
- }
-
- function assertIsAdminRole($user)
- {
- if(is_null($user))
- return $this->fail();
-
- $this->assertTrue($user->isInRole('admin'));
- }
-
- function assertIsManagerRole($user)
- {
- if(is_null($user))
- return $this->fail();
-
- $this->assertTrue($user->isInRole('manager'));
- }
-
- function assertIsConsultantRole($user)
- {
- if(is_null($user))
- return $this->fail();
-
- $this->assertTrue($user->isInRole('consultant'));
- }
-
- function assertNotConsultantRole($user)
- {
- if(is_null($user))
- return $this->fail();
-
- $this->assertFalse($user->isInRole('consultant'));
- }
-
- function testGetUserByName()
- {
- $user = $this->userDao->getUserByName('admin');
- $this->assertNotNull($user);
- $this->assertIsAdmin($user);
- }
-
- function testGetNonExistentUser()
- {
- $user = $this->userDao->getUserByName('none');
- $this->assertNull($user);
- }
-
- function testGetUsers()
- {
- $users = $this->userDao->getAllUsers();
- $this->assertEqual(count($users), 3);
- }
-
- function testUserLogon()
- {
- $success = $this->userDao->validateUser('admin', 'admin');
- $this->assertTrue($success);
- }
-
- function testBadLogin()
- {
- $success = $this->userDao->validateUser('admin', 'hahah');
- $this->assertFalse($success);
- }
-
-
- function testAddNewUser()
- {
- $user = new TimeTrackerUser(new UserManager());
- $user->Name = "user1";
- $user->EmailAddress = 'user1@pradosoft.com';
-
- $this->userDao->addNewUser($user, 'password');
-
- $check = $this->userDao->getUserByName($user->Name);
-
- $this->assertSameUser($check, $user);
- }
-
- function testDeleteUserByName()
- {
- $this->userDao->deleteUserByName('admin');
-
- $admin = $this->userDao->getUserByName('admin');
- $this->assertNull($admin);
-
- $users = $this->userDao->getAllUsers();
- $this->assertEqual(count($users), 2);
- }
-
- function testAutoSignon()
- {
- $user = new TimeTrackerUser(new UserManager());
- $user->Name = "admin";
-
- $token = $this->userDao->createSignonToken($user);
-
- $check = $this->userDao->validateSignon($token);
-
- $this->assertIsAdmin($check);
- }
-
-
- function testBadAutoSignon()
- {
- $user = new TimeTrackerUser(new UserManager());
- $user->Name = "admin";
-
- $token = $this->userDao->createSignonToken($user);
-
- $check = $this->userDao->validateSignon('adasd');
- $this->assertNull($check);
- }
-
- function testAdminRoles()
- {
- $user = $this->userDao->getUserByName('admin');
- $this->assertIsAdminRole($user);
- $this->assertIsManagerRole($user);
- $this->assertIsConsultantRole($user);
- }
-
- function testSetUserRoles()
- {
- $user = new TimeTrackerUser(new UserManager());
- $user->Name = "user1";
- $user->EmailAddress = 'user1@pradosoft.com';
- $user->Roles = array("manager", "consultant");
-
- $this->userDao->addNewUser($user, 'password');
- $check = $this->userDao->getUserByName('user1');
-
- $this->assertIsManagerRole($check);
- $this->assertIsConsultantRole($check);
- }
-
- function testSetUserRoleNoNullUser()
- {
- $user = new TimeTrackerUser(new UserManager());
- $user->Name = "user1";
- $user->EmailAddress = 'user1@pradosoft.com';
- $user->Roles = array("manager", "consultant");
-
- try
- {
- $this->userDao->updateUserRoles($user);
- $this->fail();
- }
- catch(TDbException $e)
- {
- $this->pass();
- }
-
- $check = $this->sqlmap->queryForObject('GetUserByName', 'user1');
- $this->assertNull($check);
- }
-
- function testUpdateUser()
- {
- $user = $this->userDao->getUserByName('admin');
- $user->EmailAddress = 'something@pradosoft.com';
- $user->Roles = array('manager', 'admin');
-
- $this->userDao->updateUser($user);
-
- $check = $this->userDao->getUserByName('admin');
- $this->assertIsAdminRole($check);
- $this->assertIsManagerRole($check);
- $this->assertNotConsultantRole($check);
- }
-
- function testUpdateUserPassword()
- {
- $user = $this->userDao->getUserByName('admin');
- $user->EmailAddress = 'something@pradosoft.com';
- $user->Roles = array('manager', 'admin');
-
- $pass = 'newpasword';
-
- $this->userDao->updateUser($user, $pass);
-
- $success = $this->userDao->validateUser('admin', $pass);
-
- $this->assertTrue($success);
- }
-
- function testClearSignonTokens()
- {
- $user = new TimeTrackerUser(new UserManager());
- $user->Name = "admin";
-
- $token1 = $this->userDao->createSignonToken($user);
- sleep(1);
- $token2 = $this->userDao->createSignonToken($user);
- $this->assertNotEqual($token1, $token2);
-
- $check1 = $this->userDao->validateSignon($token1);
- $check2 = $this->userDao->validateSignon($token2);
-
- $this->assertIsAdmin($check1);
- $this->assertIsAdmin($check2);
-
- $this->userDao->clearSignonTokens($user);
-
- $check3 = $this->userDao->validateSignon($token1);
- $check4 = $this->userDao->validateSignon($token2);
-
- $this->assertNull($check3);
- $this->assertNull($check4);
- }
-
- function testClearAllSigonTokens()
- {
- $user1 = new TimeTrackerUser(new UserManager());
- $user1->Name = "admin";
-
- $user2 = new TimeTrackerUser(new UserManager());
- $user2->Name = "manager";
-
- $token1 = $this->userDao->createSignonToken($user1);
- $token2 = $this->userDao->createSignonToken($user2);
-
- $check1 = $this->userDao->validateSignon($token1);
- $check2 = $this->userDao->validateSignon($token2);
-
- $this->assertIsAdmin($check1);
- $this->assertNotNull($check2);
- $this->assertEqual($check2->Name, $user2->Name);
-
- $this->userDao->clearSignonTokens();
-
- $check3 = $this->userDao->validateSignon($token1);
- $check4 = $this->userDao->validateSignon($token2);
-
- $this->assertNull($check3);
- $this->assertNull($check4);
- }
-}
-
+<?php
+
+require_once(dirname(__FILE__).'/BaseTestCase.php');
+
+class UserDaoTestCase extends BaseTestCase
+{
+ protected $userDao;
+
+ function setup()
+ {
+ parent::setup();
+ $app = Prado::getApplication();
+ $this->userDao = $app->getModule('daos')->getDao('UserDao');
+ $this->flushDatabase();
+ }
+
+ function assertIsAdmin($user)
+ {
+ if(!$user)
+ return $this->fail();
+ $this->assertEqual($user->getName(), 'admin');
+ $this->assertEqual($user->getEmailAddress(), 'admin@pradosoft.com');
+ }
+
+ function assertSameUser($user1, $user2)
+ {
+ if(is_null($user1) || is_null($user2))
+ return $this->fail();
+
+ $this->assertEqual($user1->getName(), $user2->getName());
+ $this->assertEqual($user1->getEmailAddress(), $user2->getEmailAddress());
+ }
+
+ function assertIsAdminRole($user)
+ {
+ if(is_null($user))
+ return $this->fail();
+
+ $this->assertTrue($user->isInRole('admin'));
+ }
+
+ function assertIsManagerRole($user)
+ {
+ if(is_null($user))
+ return $this->fail();
+
+ $this->assertTrue($user->isInRole('manager'));
+ }
+
+ function assertIsConsultantRole($user)
+ {
+ if(is_null($user))
+ return $this->fail();
+
+ $this->assertTrue($user->isInRole('consultant'));
+ }
+
+ function assertNotConsultantRole($user)
+ {
+ if(is_null($user))
+ return $this->fail();
+
+ $this->assertFalse($user->isInRole('consultant'));
+ }
+
+ function testGetUserByName()
+ {
+ $user = $this->userDao->getUserByName('admin');
+ $this->assertNotNull($user);
+ $this->assertIsAdmin($user);
+ }
+
+ function testGetNonExistentUser()
+ {
+ $user = $this->userDao->getUserByName('none');
+ $this->assertNull($user);
+ }
+
+ function testGetUsers()
+ {
+ $users = $this->userDao->getAllUsers();
+ $this->assertEqual(count($users), 3);
+ }
+
+ function testUserLogon()
+ {
+ $success = $this->userDao->validateUser('admin', 'admin');
+ $this->assertTrue($success);
+ }
+
+ function testBadLogin()
+ {
+ $success = $this->userDao->validateUser('admin', 'hahah');
+ $this->assertFalse($success);
+ }
+
+
+ function testAddNewUser()
+ {
+ $user = new TimeTrackerUser(new UserManager());
+ $user->Name = "user1";
+ $user->EmailAddress = 'user1@pradosoft.com';
+
+ $this->userDao->addNewUser($user, 'password');
+
+ $check = $this->userDao->getUserByName($user->Name);
+
+ $this->assertSameUser($check, $user);
+ }
+
+ function testDeleteUserByName()
+ {
+ $this->userDao->deleteUserByName('admin');
+
+ $admin = $this->userDao->getUserByName('admin');
+ $this->assertNull($admin);
+
+ $users = $this->userDao->getAllUsers();
+ $this->assertEqual(count($users), 2);
+ }
+
+ function testAutoSignon()
+ {
+ $user = new TimeTrackerUser(new UserManager());
+ $user->Name = "admin";
+
+ $token = $this->userDao->createSignonToken($user);
+
+ $check = $this->userDao->validateSignon($token);
+
+ $this->assertIsAdmin($check);
+ }
+
+
+ function testBadAutoSignon()
+ {
+ $user = new TimeTrackerUser(new UserManager());
+ $user->Name = "admin";
+
+ $token = $this->userDao->createSignonToken($user);
+
+ $check = $this->userDao->validateSignon('adasd');
+ $this->assertNull($check);
+ }
+
+ function testAdminRoles()
+ {
+ $user = $this->userDao->getUserByName('admin');
+ $this->assertIsAdminRole($user);
+ $this->assertIsManagerRole($user);
+ $this->assertIsConsultantRole($user);
+ }
+
+ function testSetUserRoles()
+ {
+ $user = new TimeTrackerUser(new UserManager());
+ $user->Name = "user1";
+ $user->EmailAddress = 'user1@pradosoft.com';
+ $user->Roles = array("manager", "consultant");
+
+ $this->userDao->addNewUser($user, 'password');
+ $check = $this->userDao->getUserByName('user1');
+
+ $this->assertIsManagerRole($check);
+ $this->assertIsConsultantRole($check);
+ }
+
+ function testSetUserRoleNoNullUser()
+ {
+ $user = new TimeTrackerUser(new UserManager());
+ $user->Name = "user1";
+ $user->EmailAddress = 'user1@pradosoft.com';
+ $user->Roles = array("manager", "consultant");
+
+ try
+ {
+ $this->userDao->updateUserRoles($user);
+ $this->fail();
+ }
+ catch(TDbException $e)
+ {
+ $this->pass();
+ }
+
+ $check = $this->sqlmap->queryForObject('GetUserByName', 'user1');
+ $this->assertNull($check);
+ }
+
+ function testUpdateUser()
+ {
+ $user = $this->userDao->getUserByName('admin');
+ $user->EmailAddress = 'something@pradosoft.com';
+ $user->Roles = array('manager', 'admin');
+
+ $this->userDao->updateUser($user);
+
+ $check = $this->userDao->getUserByName('admin');
+ $this->assertIsAdminRole($check);
+ $this->assertIsManagerRole($check);
+ $this->assertNotConsultantRole($check);
+ }
+
+ function testUpdateUserPassword()
+ {
+ $user = $this->userDao->getUserByName('admin');
+ $user->EmailAddress = 'something@pradosoft.com';
+ $user->Roles = array('manager', 'admin');
+
+ $pass = 'newpasword';
+
+ $this->userDao->updateUser($user, $pass);
+
+ $success = $this->userDao->validateUser('admin', $pass);
+
+ $this->assertTrue($success);
+ }
+
+ function testClearSignonTokens()
+ {
+ $user = new TimeTrackerUser(new UserManager());
+ $user->Name = "admin";
+
+ $token1 = $this->userDao->createSignonToken($user);
+ sleep(1);
+ $token2 = $this->userDao->createSignonToken($user);
+ $this->assertNotEqual($token1, $token2);
+
+ $check1 = $this->userDao->validateSignon($token1);
+ $check2 = $this->userDao->validateSignon($token2);
+
+ $this->assertIsAdmin($check1);
+ $this->assertIsAdmin($check2);
+
+ $this->userDao->clearSignonTokens($user);
+
+ $check3 = $this->userDao->validateSignon($token1);
+ $check4 = $this->userDao->validateSignon($token2);
+
+ $this->assertNull($check3);
+ $this->assertNull($check4);
+ }
+
+ function testClearAllSigonTokens()
+ {
+ $user1 = new TimeTrackerUser(new UserManager());
+ $user1->Name = "admin";
+
+ $user2 = new TimeTrackerUser(new UserManager());
+ $user2->Name = "manager";
+
+ $token1 = $this->userDao->createSignonToken($user1);
+ $token2 = $this->userDao->createSignonToken($user2);
+
+ $check1 = $this->userDao->validateSignon($token1);
+ $check2 = $this->userDao->validateSignon($token2);
+
+ $this->assertIsAdmin($check1);
+ $this->assertNotNull($check2);
+ $this->assertEqual($check2->Name, $user2->Name);
+
+ $this->userDao->clearSignonTokens();
+
+ $check3 = $this->userDao->validateSignon($token1);
+ $check4 = $this->userDao->validateSignon($token2);
+
+ $this->assertNull($check3);
+ $this->assertNull($check4);
+ }
+}
+
?> \ No newline at end of file