summaryrefslogtreecommitdiff
path: root/demos/time-tracker/tests/unit/ProjectDaoTestCase.php
blob: bc576630d314567b17fd68e2cc4d4064729368a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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);
	}
	
}
?>