summaryrefslogtreecommitdiff
path: root/demos/time-tracker/tests
diff options
context:
space:
mode:
authorwei <>2006-12-17 22:20:50 +0000
committerwei <>2006-12-17 22:20:50 +0000
commit2570226fbac3e26b1e94896b50d1db4bc1aa3308 (patch)
tree421108ccbdc0ef021e6af4fa35b1d6bcbc352b37 /demos/time-tracker/tests
parentddc0de38f64e5834ce04f0407a8416172b596655 (diff)
Add TDataSourceConfig, TSqlMapConfig, TActiveRecordConfig
Diffstat (limited to 'demos/time-tracker/tests')
-rw-r--r--demos/time-tracker/tests/unit/BaseTestCase.php33
-rw-r--r--demos/time-tracker/tests/unit/ProjectDaoTestCase.php66
2 files changed, 52 insertions, 47 deletions
diff --git a/demos/time-tracker/tests/unit/BaseTestCase.php b/demos/time-tracker/tests/unit/BaseTestCase.php
index 549229e3..7e4520f8 100644
--- a/demos/time-tracker/tests/unit/BaseTestCase.php
+++ b/demos/time-tracker/tests/unit/BaseTestCase.php
@@ -6,44 +6,49 @@ Prado::using('Application.App_Code.Dao.*');
class BaseTestCase extends UnitTestCase
{
protected $sqlmap;
-
+
function setup()
{
$app = Prado::getApplication();
- $this->sqlmap = $app->getModule('daos')->getConnection();
+ $this->sqlmap = $app->getModule('daos')->getClient();
}
-
-
+
+
function flushDatabase()
{
- $conn = $this->sqlmap->openConnection();
- switch(strtolower($conn->getProvider()->getDriver()))
+ $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();
- }
+ return $this->flushSQLiteDatabase();
+ }
}
-
+
function flushSQLiteDatabase()
{
- $conn = $this->sqlmap->openConnection();
- $file = $conn->getProvider()->getHost();
+ $conn = $this->sqlmap->getDbConnection();
+ $file = str_replace('sqlite:','',$conn->getConnectionString());
$backup = $file.'.bak';
copy($backup, $file);
}
-
+
function flushMySQLDatabase()
{
- $conn = $this->sqlmap->openConnection();
+ $conn = $this->sqlmap->getDbConnection();
$file = Prado::getPathOfNamespace('Application.App_Data.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);
diff --git a/demos/time-tracker/tests/unit/ProjectDaoTestCase.php b/demos/time-tracker/tests/unit/ProjectDaoTestCase.php
index 3ee9d8b2..3ccb28e2 100644
--- a/demos/time-tracker/tests/unit/ProjectDaoTestCase.php
+++ b/demos/time-tracker/tests/unit/ProjectDaoTestCase.php
@@ -5,7 +5,7 @@ require_once(dirname(__FILE__).'/BaseTestCase.php');
class ProjectDaoTestCase extends BaseTestCase
{
protected $projectDao;
-
+
function setup()
{
parent::setup();
@@ -13,8 +13,8 @@ class ProjectDaoTestCase extends BaseTestCase
$this->projectDao = $app->getModule('daos')->getDao('ProjectDao');
$this->flushDatabase();
}
-
-
+
+
function createNewProject()
{
$project = new ProjectRecord;
@@ -25,7 +25,7 @@ class ProjectDaoTestCase extends BaseTestCase
$project->EstimateDuration = 100.5;
$project->ManagerUserName = 'manager';
$project->Name = 'Project 1';
-
+
return $project;
}
@@ -39,7 +39,7 @@ class ProjectDaoTestCase extends BaseTestCase
$project->EstimateDuration = 30.5;
$project->ManagerUserName = 'manager';
$project->Name = 'Project 2';
-
+
return $project;
}
@@ -53,78 +53,78 @@ class ProjectDaoTestCase extends BaseTestCase
$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);
+ $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->pass();
}
catch(TSqlMapQueryExecutionException $e)
{
- $this->fail();
+ $this->fail();
}
}
function testGetAllProjects()
{
$added = $this->add3Projects();
-
+
$projects = $this->projectDao->getAllProjects();
$this->assertEqual(count($projects),3);
@@ -136,7 +136,7 @@ class ProjectDaoTestCase extends BaseTestCase
function testGetProjectsByManagerName()
{
$added = $this->add3Projects();
-
+
$projects = $this->projectDao->getProjectsByManagerName('manager');
$this->assertEqual(count($projects),2);
@@ -147,12 +147,12 @@ class ProjectDaoTestCase extends BaseTestCase
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);
@@ -166,16 +166,16 @@ class ProjectDaoTestCase extends BaseTestCase
$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);
@@ -187,13 +187,13 @@ class ProjectDaoTestCase extends BaseTestCase
{
$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);
+ $this->assertEqual($check, $project);
}
}