summaryrefslogtreecommitdiff
path: root/demos/time-tracker/tests
diff options
context:
space:
mode:
authorwei <>2006-07-14 06:56:16 +0000
committerwei <>2006-07-14 06:56:16 +0000
commit143980b6dab8ad87c44518e5b7befb614fb83b85 (patch)
tree6afadfb80ca6e4d36443f83bd5a6cc2cfe73032d /demos/time-tracker/tests
parentc004bbdf4f0e824e5ccbaef8f98ca4a3d44d3b49 (diff)
Add time-tracker sample and docs. (Incomplete)
Diffstat (limited to 'demos/time-tracker/tests')
-rw-r--r--demos/time-tracker/tests/functional.php10
-rw-r--r--demos/time-tracker/tests/functional/HelloPradoTestCase.php14
-rw-r--r--demos/time-tracker/tests/unit.php11
-rw-r--r--demos/time-tracker/tests/unit/AddUserToProjectTestCase.php35
-rw-r--r--demos/time-tracker/tests/unit/CreateNewProjectTestCase.php90
-rw-r--r--demos/time-tracker/tests/unit/ProjectDaoTestCase.php92
-rw-r--r--demos/time-tracker/tests/unit/ProjectTestCase.php15
7 files changed, 267 insertions, 0 deletions
diff --git a/demos/time-tracker/tests/functional.php b/demos/time-tracker/tests/functional.php
new file mode 100644
index 00000000..c216ada8
--- /dev/null
+++ b/demos/time-tracker/tests/functional.php
@@ -0,0 +1,10 @@
+<?php
+
+include_once '../../prado-trunk\tests\test_tools\functional_tests.php';
+
+$test_cases = dirname(__FILE__)."/functional";
+
+$tester=new PradoFunctionalTester($test_cases);
+$tester->run(new SimpleReporter());
+
+?> \ No newline at end of file
diff --git a/demos/time-tracker/tests/functional/HelloPradoTestCase.php b/demos/time-tracker/tests/functional/HelloPradoTestCase.php
new file mode 100644
index 00000000..b9e4f1e3
--- /dev/null
+++ b/demos/time-tracker/tests/functional/HelloPradoTestCase.php
@@ -0,0 +1,14 @@
+<?php
+
+//web testing
+class HelloPradoTestCase extends SeleniumTestCase
+{
+ function testIndexPage()
+ {
+ $this->open('../index.php');
+ $this->assertTextPresent('Welcome to Prado!');
+ //add more test assertions...
+ }
+}
+
+?> \ No newline at end of file
diff --git a/demos/time-tracker/tests/unit.php b/demos/time-tracker/tests/unit.php
new file mode 100644
index 00000000..a920b205
--- /dev/null
+++ b/demos/time-tracker/tests/unit.php
@@ -0,0 +1,11 @@
+<?php
+
+include_once '../../prado-trunk/tests/test_tools/unit_tests.php';
+
+$app_directory = "../protected";
+$test_cases = dirname(__FILE__)."/unit";
+
+$tester = new PradoUnitTester($test_cases, $app_directory);
+$tester->run(new HtmlReporter());
+
+?> \ No newline at end of file
diff --git a/demos/time-tracker/tests/unit/AddUserToProjectTestCase.php b/demos/time-tracker/tests/unit/AddUserToProjectTestCase.php
new file mode 100644
index 00000000..36defc57
--- /dev/null
+++ b/demos/time-tracker/tests/unit/AddUserToProjectTestCase.php
@@ -0,0 +1,35 @@
+<?php
+
+require_once(dirname(__FILE__).'/ProjectDaoTestCase.php');
+
+class AddUserToProjectTestCase extends ProjectDaoTestCase
+{
+ function testCanAddNewUserToProject()
+ {
+ $project = $this->createNewTestProject();
+
+ $user = new TimeTrackerUser();
+ $user->ID = 3;
+ $user->Name = "test user 1";
+
+ if(($conn = $this->connection) instanceof MockTSqlMapper)
+ {
+ $this->setupMockConnectionFor($project);
+ $conn->setReturnReference('queryForObject', $user, array('GetUserByName', $user->Name));
+ $conn->setReturnValue('queryForList', array(), array('GetProjectMembers', $project));
+
+ $param['project'] = $project;
+ $param['user'] = $user;
+
+ $conn->setReturnValue('insert', true, array('AddNewUserToProject', $param));
+
+ $conn->expectAtLeastOnce('insert');
+ $conn->expectAtLeastOnce('queryForList');
+ }
+
+ $this->assertTrue($this->dao->createNewProject($project));
+ $this->assertTrue($this->dao->addUserToProject($project, $user));
+ }
+}
+
+?> \ No newline at end of file
diff --git a/demos/time-tracker/tests/unit/CreateNewProjectTestCase.php b/demos/time-tracker/tests/unit/CreateNewProjectTestCase.php
new file mode 100644
index 00000000..0aa67405
--- /dev/null
+++ b/demos/time-tracker/tests/unit/CreateNewProjectTestCase.php
@@ -0,0 +1,90 @@
+<?php
+
+require_once(dirname(__FILE__).'/ProjectDaoTestCase.php');
+
+class CreateNewProjectTestCase extends ProjectDaoTestCase
+{
+ function testProjectDaoCanCreateNewProject()
+ {
+ $project = $this->createNewTestProject();
+
+ if(($conn = $this->connection) instanceof MockTSqlMapper)
+ {
+ $this->setupMockConnectionFor($project);
+ $conn->expectMinimumCallCount('queryForObject', 3);
+ $conn->expectAtLeastOnce('insert');
+ }
+
+ $this->assertProjectCreated($project);
+ }
+
+ function testProjectExistsException()
+ {
+ $project = $this->createNewTestProject();
+
+ if(($conn = $this->connection) instanceof MockTSqlMapper)
+ {
+ //make the project exist
+ $conn->setReturnValue('queryForObject',
+ $project, array('GetProjectByName', 'Project 1'));
+ $this->setupMockConnectionFor($project);
+ }
+
+ try
+ {
+ $this->assertProjectCreated($project);
+ $this->fail();
+ }
+ catch(TimeTrackerException $e)
+ {
+ $this->pass();
+ }
+ }
+ function testProjectCustomerNotExistsException()
+ {
+ $project = $this->createNewTestProject();
+
+ if(($conn = $this->connection) instanceof MockTSqlMapper)
+ {
+ //customer does not exist
+ $conn->setReturnValue('queryForObject',
+ null, array('GetUserByName', 'Customer A'));
+ $this->setupMockConnectionFor($project);
+ }
+
+ try
+ {
+ $this->assertProjectCreated($project);
+ $this->fail();
+ }
+ catch(TimeTrackerException $e)
+ {
+ $this->pass();
+ }
+ }
+
+ function testProjectManagerNotExistsException()
+ {
+ $project = $this->createNewTestProject();
+
+ if(($conn = $this->connection) instanceof MockTSqlMapper)
+ {
+ //manager does not exist
+ $conn->setReturnValue('queryForObject',
+ null, array('GetUserByName', 'Manager A'));
+ $this->setupMockConnectionFor($project);
+ }
+
+ try
+ {
+ $this->assertProjectCreated($project);
+ $this->fail();
+ }
+ catch(TimeTrackerException $e)
+ {
+ $this->pass();
+ }
+ }
+}
+
+?> \ 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..bc576630
--- /dev/null
+++ b/demos/time-tracker/tests/unit/ProjectDaoTestCase.php
@@ -0,0 +1,92 @@
+<?php
+
+//formerly PradoDaoTestCase.php
+
+Prado::using('Application.APP_CODE.*');
+Prado::using('System.DataAccess.SQLMap.TSqlMapper');
+
+Mock::generate('TSqlMapper');
+
+class ProjectDaoTestCase extends UnitTestCase
+{
+ protected $dao;
+ protected $connection;
+
+ function setup()
+ {
+ $this->dao= new ProjectDao();
+ $this->connection = new MockTSqlMapper($this);
+ $this->dao->setConnection($this->connection);
+ }
+
+/*
+ //Simple test case, will not detect project existanc
+ //This case will clash with the more complete test case below.
+ function testProjectDaoCanCreateNewProject()
+ {
+ $project = new Project();
+ $project->Name = "Project 1";
+
+ if(($conn = $this->connection) instanceof MockTSqlMapper)
+ {
+ $conn->expectOnce('insert', array('CreateNewProject', $project));
+ $conn->setReturnValue('insert', true);
+
+ $conn->expectOnce('queryForObject', array('GetProjectByID', 1));
+ $conn->setReturnReference('queryForObject', $project);
+ }
+
+ $this->assertTrue($this->dao->createNewProject($project));
+ $this->assertEqual($this->dao->getProjectByID(1), $project);
+ }
+*/
+ function setupMockConnectionFor($project)
+ {
+ $customer = new TimeTrackerUser();
+ $customer->ID = 1;
+ $customer->Name = "Customer A";
+
+ $manager = new TimeTrackerUser();
+ $manager->ID = 2;
+ $manager->Name = "Manager A";
+
+ $conn = $this->connection;
+
+ //return the customer and manager
+ $conn->setReturnValue('queryForObject',
+ $customer, array('GetUserByName', 'Customer A'));
+ $conn->setReturnValue('queryForObject',
+ $manager, array('GetUserByName', 'Manager A'));
+
+ //project does not exist
+ $conn->setReturnValue('queryForObject',
+ null, array('GetProjectByName', 'Project 1'));
+
+ $param['project'] = $project;
+ $param['creator'] = $customer->ID;
+ $param['manager'] = $manager->ID;
+
+ $conn->setReturnValue('insert',
+ true, array('CreateNewProject', $param));
+ $conn->setReturnReference('queryForObject',
+ $project, array('GetProjectByID', 1));
+ }
+
+ function createNewTestProject()
+ {
+ $project = new Project();
+ $project->Name = "Project 1";
+ $project->CreatorUserName = "Customer A";
+ $project->ManagerUserName = "Manager A";
+
+ return $project;
+ }
+
+ function assertProjectCreated($project)
+ {
+ $this->assertTrue($this->dao->createNewProject($project));
+ $this->assertEqual($this->dao->getProjectByID(1), $project);
+ }
+
+}
+?> \ No newline at end of file
diff --git a/demos/time-tracker/tests/unit/ProjectTestCase.php b/demos/time-tracker/tests/unit/ProjectTestCase.php
new file mode 100644
index 00000000..a61c4f77
--- /dev/null
+++ b/demos/time-tracker/tests/unit/ProjectTestCase.php
@@ -0,0 +1,15 @@
+<?php
+
+//import Project class.
+Prado::using('Application.APP_CODE.Project');
+
+class ProjectTestCase extends UnitTestCase
+{
+ function testProjectClassExists()
+ {
+ $project = new Project();
+ $this->pass();
+ }
+}
+
+?> \ No newline at end of file