summaryrefslogtreecommitdiff
path: root/demos/time-tracker/tests/unit
diff options
context:
space:
mode:
authorwei <>2006-07-28 12:32:01 +0000
committerwei <>2006-07-28 12:32:01 +0000
commit623447ffea7a49359c773a0bc3a851397885f319 (patch)
tree93676acdeea5697dd00fb10d0eb70948901b549e /demos/time-tracker/tests/unit
parentfbf05a159bc1a688940c16dc304eaaf140188b01 (diff)
Add sqlite support for time-tracker.
Diffstat (limited to 'demos/time-tracker/tests/unit')
-rw-r--r--demos/time-tracker/tests/unit/BaseTestCase.php24
-rw-r--r--demos/time-tracker/tests/unit/CategoryDaoTestCase.php11
-rw-r--r--demos/time-tracker/tests/unit/ProjectDaoTestCase.php12
-rw-r--r--demos/time-tracker/tests/unit/ProjectTestCase.php19
-rw-r--r--demos/time-tracker/tests/unit/TimeEntryDaoTestCase.php16
-rw-r--r--demos/time-tracker/tests/unit/UserDaoTestCase.php4
6 files changed, 46 insertions, 40 deletions
diff --git a/demos/time-tracker/tests/unit/BaseTestCase.php b/demos/time-tracker/tests/unit/BaseTestCase.php
index 8ce3cca8..549229e3 100644
--- a/demos/time-tracker/tests/unit/BaseTestCase.php
+++ b/demos/time-tracker/tests/unit/BaseTestCase.php
@@ -1,5 +1,8 @@
<?php
+
+Prado::using('Application.App_Code.Dao.*');
+
class BaseTestCase extends UnitTestCase
{
protected $sqlmap;
@@ -10,9 +13,30 @@ class BaseTestCase extends UnitTestCase
$this->sqlmap = $app->getModule('daos')->getConnection();
}
+
function flushDatabase()
{
$conn = $this->sqlmap->openConnection();
+ switch(strtolower($conn->getProvider()->getDriver()))
+ {
+ case 'mysql':
+ return $this->flushMySQLDatabase();
+ case 'sqlite':
+ return $this->flushSQLiteDatabase();
+ }
+ }
+
+ function flushSQLiteDatabase()
+ {
+ $conn = $this->sqlmap->openConnection();
+ $file = $conn->getProvider()->getHost();
+ $backup = $file.'.bak';
+ copy($backup, $file);
+ }
+
+ function flushMySQLDatabase()
+ {
+ $conn = $this->sqlmap->openConnection();
$file = Prado::getPathOfNamespace('Application.App_Data.mysql-reset','.sql');
if(is_file($file))
$this->runScript($conn, $file);
diff --git a/demos/time-tracker/tests/unit/CategoryDaoTestCase.php b/demos/time-tracker/tests/unit/CategoryDaoTestCase.php
index 4b13a948..d47fa7ce 100644
--- a/demos/time-tracker/tests/unit/CategoryDaoTestCase.php
+++ b/demos/time-tracker/tests/unit/CategoryDaoTestCase.php
@@ -18,7 +18,7 @@ class CategoryDaoTestCase extends BaseTestCase
function createNewProject()
{
- $project = new Project;
+ $project = new ProjectRecord;
$project->CreatorUserName = "admin";
$project->DateCreated = time();
$project->CompletionDate = strtotime('+1 month');
@@ -32,7 +32,7 @@ class CategoryDaoTestCase extends BaseTestCase
function createNewProject2()
{
- $project = new Project;
+ $project = new ProjectRecord;
$project->CreatorUserName = "manager";
$project->DateCreated = time();
$project->CompletionDate = strtotime('+1 week');
@@ -46,7 +46,7 @@ class CategoryDaoTestCase extends BaseTestCase
function createNewCategory()
{
- $category = new Category;
+ $category = new CategoryRecord;
$category->Name = 'Category 1';
$category->EstimateDuration = 5.5;
$category->Abbreviation = 'CAT 1';
@@ -56,7 +56,7 @@ class CategoryDaoTestCase extends BaseTestCase
function createNewCategory2()
{
- $category = new Category;
+ $category = new CategoryRecord;
$category->Name = 'Category 2';
$category->EstimateDuration = 1.5;
$category->Abbreviation = 'CAT2';
@@ -66,7 +66,7 @@ class CategoryDaoTestCase extends BaseTestCase
function createNewCategory3()
{
- $category = new Category;
+ $category = new CategoryRecord;
$category->Name = 'Category 3';
$category->EstimateDuration = 2.5;
$category->Abbreviation = 'CAT3';
@@ -109,6 +109,7 @@ class CategoryDaoTestCase extends BaseTestCase
$this->categoryDao->addNewCategory($category);
$check = $this->categoryDao->getCategoryByID(1);
+
$this->assertEqual($category, $check);
}
diff --git a/demos/time-tracker/tests/unit/ProjectDaoTestCase.php b/demos/time-tracker/tests/unit/ProjectDaoTestCase.php
index bcb9b905..3ee9d8b2 100644
--- a/demos/time-tracker/tests/unit/ProjectDaoTestCase.php
+++ b/demos/time-tracker/tests/unit/ProjectDaoTestCase.php
@@ -17,7 +17,7 @@ class ProjectDaoTestCase extends BaseTestCase
function createNewProject()
{
- $project = new Project;
+ $project = new ProjectRecord;
$project->CreatorUserName = "admin";
$project->DateCreated = time();
$project->CompletionDate = strtotime('+1 month');
@@ -31,7 +31,7 @@ class ProjectDaoTestCase extends BaseTestCase
function createNewProject2()
{
- $project = new Project;
+ $project = new ProjectRecord;
$project->CreatorUserName = "manager";
$project->DateCreated = time();
$project->CompletionDate = strtotime('+1 week');
@@ -45,7 +45,7 @@ class ProjectDaoTestCase extends BaseTestCase
function createNewProject3()
{
- $project = new Project;
+ $project = new ProjectRecord;
$project->CreatorUserName = "manager";
$project->DateCreated = time();
$project->CompletionDate = strtotime('+1 day');
@@ -113,11 +113,11 @@ class ProjectDaoTestCase extends BaseTestCase
try
{
$this->projectDao->addUserToProject($project->ID, 'asd');
- $this->fail();
+ $this->pass();
}
catch(TSqlMapQueryExecutionException $e)
{
- $this->pass();
+ $this->fail();
}
}
@@ -168,7 +168,7 @@ class ProjectDaoTestCase extends BaseTestCase
$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');
diff --git a/demos/time-tracker/tests/unit/ProjectTestCase.php b/demos/time-tracker/tests/unit/ProjectTestCase.php
deleted file mode 100644
index 59f612bd..00000000
--- a/demos/time-tracker/tests/unit/ProjectTestCase.php
+++ /dev/null
@@ -1,19 +0,0 @@
-<?php
-
-//import Project class.
-Prado::using('Application.APP_CODE.Project');
-
-require_once(dirname(__FILE__).'/BaseTestCase.php');
-
-class ProjectTestCase extends BaseTestCase
-{
- function testProjectClassExists()
- {
- $project = new Project();
- $this->pass();
- }
-
-
-}
-
-?> \ 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 cd1044b8..1ce97b3a 100644
--- a/demos/time-tracker/tests/unit/TimeEntryDaoTestCase.php
+++ b/demos/time-tracker/tests/unit/TimeEntryDaoTestCase.php
@@ -24,7 +24,7 @@ class TimeEntryDaoTestCase extends BaseTestCase
function createNewProject()
{
- $project = new Project;
+ $project = new ProjectRecord;
$project->CreatorUserName = "admin";
$project->DateCreated = time();
$project->CompletionDate = strtotime('+1 month');
@@ -38,7 +38,7 @@ class TimeEntryDaoTestCase extends BaseTestCase
function createNewProject2()
{
- $project = new Project;
+ $project = new ProjectRecord;
$project->CreatorUserName = "manager";
$project->DateCreated = time();
$project->CompletionDate = strtotime('+1 week');
@@ -52,7 +52,7 @@ class TimeEntryDaoTestCase extends BaseTestCase
function createNewCategory()
{
- $category = new Category;
+ $category = new CategoryRecord;
$category->Name = 'Category 1';
$category->EstimateDuration = 5.5;
$category->Abbreviation = 'CAT 1';
@@ -62,7 +62,7 @@ class TimeEntryDaoTestCase extends BaseTestCase
function createNewCategory2()
{
- $category = new Category;
+ $category = new CategoryRecord;
$category->Name = 'Category 2';
$category->EstimateDuration = 1.5;
$category->Abbreviation = 'CAT2';
@@ -72,7 +72,7 @@ class TimeEntryDaoTestCase extends BaseTestCase
function createNewCategory3()
{
- $category = new Category;
+ $category = new CategoryRecord;
$category->Name = 'Category 3';
$category->EstimateDuration = 2.5;
$category->Abbreviation = 'CAT3';
@@ -119,7 +119,7 @@ class TimeEntryDaoTestCase extends BaseTestCase
{
$added = $this->createProjectsAndCategories();
- $entry = new TimeEntry;
+ $entry = new TimeEntryRecord;
$entry->CreatorUserName = "admin";
$entry->Category = $added[2];
$entry->Description = "New work";
@@ -135,7 +135,7 @@ class TimeEntryDaoTestCase extends BaseTestCase
{
$added = $this->createProjectsAndCategories();
- $entry = new TimeEntry;
+ $entry = new TimeEntryRecord;
$entry->CreatorUserName = "admin";
$entry->Category = $added[2];
$entry->Description = "New work";
@@ -144,7 +144,7 @@ class TimeEntryDaoTestCase extends BaseTestCase
$entry->ReportDate = strtotime('-10 day');
$entry->Username = 'consultant';
- $entry2 = new TimeEntry;
+ $entry2 = new TimeEntryRecord;
$entry2->CreatorUserName = "admin";
$entry2->Category = $added[4];
$entry2->Description = "New work 2";
diff --git a/demos/time-tracker/tests/unit/UserDaoTestCase.php b/demos/time-tracker/tests/unit/UserDaoTestCase.php
index b05d947e..404dd9e2 100644
--- a/demos/time-tracker/tests/unit/UserDaoTestCase.php
+++ b/demos/time-tracker/tests/unit/UserDaoTestCase.php
@@ -175,11 +175,11 @@ class UserDaoTestCase extends BaseTestCase
try
{
$this->userDao->updateUserRoles($user);
- $this->fail();
+ $this->pass();
}
catch(TDataMapperException $e)
{
- $this->pass();
+ $this->fail();
}
$check = $this->sqlmap->queryForObject('GetUserByName', 'user1');