| 1 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
require_once(dirname(__FILE__).'/BaseTestCase.php');
|
|
|
4 |
|
|
|
5 |
class ProjectDaoTestCase extends BaseTestCase
|
|
|
6 |
{
|
|
|
7 |
protected $projectDao;
|
|
|
8 |
|
|
|
9 |
function setup()
|
|
|
10 |
{
|
|
|
11 |
parent::setup();
|
|
|
12 |
$app = Prado::getApplication();
|
|
|
13 |
$this->projectDao = $app->getModule('daos')->getDao('ProjectDao');
|
|
|
14 |
$this->flushDatabase();
|
|
|
15 |
}
|
|
|
16 |
|
|
|
17 |
|
|
|
18 |
function createNewProject()
|
|
|
19 |
{
|
|
|
20 |
$project = new ProjectRecord;
|
|
|
21 |
$project->CreatorUserName = "admin";
|
|
|
22 |
$project->DateCreated = time();
|
|
|
23 |
$project->CompletionDate = strtotime('+1 month');
|
|
|
24 |
$project->Description = 'Test project 1';
|
|
|
25 |
$project->EstimateDuration = 100.5;
|
|
|
26 |
$project->ManagerUserName = 'manager';
|
|
|
27 |
$project->Name = 'Project 1';
|
|
|
28 |
|
|
|
29 |
return $project;
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
function createNewProject2()
|
|
|
33 |
{
|
|
|
34 |
$project = new ProjectRecord;
|
|
|
35 |
$project->CreatorUserName = "manager";
|
|
|
36 |
$project->DateCreated = time();
|
|
|
37 |
$project->CompletionDate = strtotime('+1 week');
|
|
|
38 |
$project->Description = 'Test project 2';
|
|
|
39 |
$project->EstimateDuration = 30.5;
|
|
|
40 |
$project->ManagerUserName = 'manager';
|
|
|
41 |
$project->Name = 'Project 2';
|
|
|
42 |
|
|
|
43 |
return $project;
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
function createNewProject3()
|
|
|
47 |
{
|
|
|
48 |
$project = new ProjectRecord;
|
|
|
49 |
$project->CreatorUserName = "manager";
|
|
|
50 |
$project->DateCreated = time();
|
|
|
51 |
$project->CompletionDate = strtotime('+1 day');
|
|
|
52 |
$project->Description = 'Test project 3';
|
|
|
53 |
$project->EstimateDuration = 5.0;
|
|
|
54 |
$project->ManagerUserName = 'admin';
|
|
|
55 |
$project->Name = 'Project 3';
|
|
|
56 |
|
|
|
57 |
return $project;
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
function add3Projects()
|
|
|
61 |
{
|
|
|
62 |
$project1 = $this->createNewProject();
|
|
|
63 |
$project2 = $this->createNewProject2();
|
|
|
64 |
$project3 = $this->createNewProject3();
|
|
|
65 |
|
|
|
66 |
$this->projectDao->addNewProject($project1);
|
|
|
67 |
$this->projectDao->addNewProject($project2);
|
|
|
68 |
$this->projectDao->addNewProject($project3);
|
|
|
69 |
return array($project1,$project2,$project3);
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
function testCreateNewProject()
|
|
|
73 |
{
|
|
|
74 |
$newProject = $this->createNewProject();
|
|
|
75 |
$this->projectDao->addNewProject($newProject);
|
|
|
76 |
|
|
|
77 |
$check = $this->projectDao->getProjectByID(1);
|
|
|
78 |
$this->assertEqual($newProject, $check);
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
function testDeleteProject()
|
|
|
82 |
{
|
|
|
83 |
$newProject = $this->createNewProject();
|
|
|
84 |
$this->projectDao->addNewProject($newProject);
|
|
|
85 |
|
|
|
86 |
$check = $this->projectDao->getProjectByID(1);
|
|
|
87 |
$this->assertEqual($newProject, $check);
|
|
|
88 |
|
|
|
89 |
$this->projectDao->deleteProject(1);
|
|
|
90 |
$verify = $this->projectDao->getProjectByID(1);
|
|
|
91 |
$this->assertNull($verify);
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
function testAddUserToProject()
|
|
|
95 |
{
|
|
|
96 |
$project = $this->createNewProject();
|
|
|
97 |
$this->projectDao->addNewProject($project);
|
|
|
98 |
|
|
|
99 |
$this->projectDao->addUserToProject($project->ID, 'admin');
|
|
|
100 |
$this->projectDao->addUserToProject($project->ID, 'manager');
|
|
|
101 |
|
|
|
102 |
$members = $this->projectDao->getProjectMembers($project->ID);
|
|
|
103 |
|
|
|
104 |
$this->assertEqual(count($members), 2);
|
|
|
105 |
$this->assertEqual($members[0], 'admin');
|
|
|
106 |
$this->assertEqual($members[1], 'manager');
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
function testAddNullUserToProject()
|
|
|
110 |
{
|
|
|
111 |
$project = $this->createNewProject();
|
|
|
112 |
$this->projectDao->addNewProject($project);
|
|
|
113 |
try
|
|
|
114 |
{
|
|
|
115 |
$this->projectDao->addUserToProject($project->ID, 'asd');
|
|
|
116 |
$this->fail();
|
|
|
117 |
}
|
|
|
118 |
catch(TDbException $e)
|
|
|
119 |
{
|
|
|
120 |
$this->pass();
|
|
|
121 |
}
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
function testGetAllProjects()
|
|
|
125 |
{
|
|
|
126 |
$added = $this->add3Projects();
|
|
|
127 |
|
|
|
128 |
$projects = $this->projectDao->getAllProjects();
|
|
|
129 |
|
|
|
130 |
$this->assertEqual(count($projects),3);
|
|
|
131 |
$this->assertEqual($added[0],$projects[0]);
|
|
|
132 |
$this->assertEqual($added[1],$projects[1]);
|
|
|
133 |
$this->assertEqual($added[2],$projects[2]);
|
|
|
134 |
}
|
|
|
135 |
|
|
|
136 |
function testGetProjectsByManagerName()
|
|
|
137 |
{
|
|
|
138 |
$added = $this->add3Projects();
|
|
|
139 |
|
|
|
140 |
$projects = $this->projectDao->getProjectsByManagerName('manager');
|
|
|
141 |
|
|
|
142 |
$this->assertEqual(count($projects),2);
|
|
|
143 |
$this->assertEqual($added[0],$projects[0]);
|
|
|
144 |
$this->assertEqual($added[1],$projects[1]);
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
function testGetProjectsByUserName()
|
|
|
148 |
{
|
|
|
149 |
$added = $this->add3Projects();
|
|
|
150 |
|
|
|
151 |
$username = 'consultant';
|
|
|
152 |
|
|
|
153 |
$this->projectDao->addUserToProject(1, $username);
|
|
|
154 |
$this->projectDao->addUserToProject(3, $username);
|
|
|
155 |
|
|
|
156 |
$projects = $this->projectDao->getProjectsByUserName($username);
|
|
|
157 |
|
|
|
158 |
$this->assertEqual(count($projects),2);
|
|
|
159 |
$this->assertEqual($added[0],$projects[0]);
|
|
|
160 |
$this->assertEqual($added[2],$projects[1]);
|
|
|
161 |
}
|
|
|
162 |
|
|
|
163 |
function testRemoveUserFromProject()
|
|
|
164 |
{
|
|
|
165 |
$added = $this->add3Projects();
|
|
|
166 |
$this->projectDao->addUserToProject(1, 'admin');
|
|
|
167 |
$this->projectDao->addUserToProject(1, 'manager');
|
|
|
168 |
$this->projectDao->addUserToProject(1, 'consultant');
|
|
|
169 |
|
|
|
170 |
$members = $this->projectDao->getProjectMembers(1);
|
|
|
171 |
|
|
|
172 |
$this->assertEqual(count($members), 3);
|
|
|
173 |
$this->assertEqual($members[0], 'admin');
|
|
|
174 |
$this->assertEqual($members[2], 'manager');
|
|
|
175 |
$this->assertEqual($members[1], 'consultant');
|
|
|
176 |
|
|
|
177 |
$this->projectDao->removeUserFromProject(1,'admin');
|
|
|
178 |
|
|
|
179 |
$list = $this->projectDao->getProjectMembers(1);
|
|
|
180 |
|
|
|
181 |
$this->assertEqual(count($list), 2);
|
|
|
182 |
$this->assertEqual($list[1], 'manager');
|
|
|
183 |
$this->assertEqual($list[0], 'consultant');
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
function testUpdateProject()
|
|
|
187 |
{
|
|
|
188 |
$project = $this->createNewProject();
|
|
|
189 |
$this->projectDao->addNewProject($project);
|
|
|
190 |
|
|
|
191 |
$project->Description = "Project Testing 123";
|
|
|
192 |
|
|
|
193 |
$this->projectDao->updateProject($project);
|
|
|
194 |
|
|
|
195 |
$check = $this->projectDao->getProjectByID(1);
|
|
|
196 |
$this->assertEqual($check, $project);
|
|
|
197 |
}
|
|
|
198 |
}
|
|
|
199 |
|
|
|
200 |
?>
|