| 1 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
require_once(dirname(__FILE__).'/BaseTestCase.php');
|
|
|
4 |
|
|
|
5 |
class TimeEntryDaoTestCase extends BaseTestCase
|
|
|
6 |
{
|
|
|
7 |
protected $entryDao;
|
|
|
8 |
protected $projectDao;
|
|
|
9 |
protected $userDao;
|
|
|
10 |
protected $categoryDao;
|
|
|
11 |
protected $reportDao;
|
|
|
12 |
|
|
|
13 |
function setup()
|
|
|
14 |
{
|
|
|
15 |
parent::setup();
|
|
|
16 |
$app = Prado::getApplication();
|
|
|
17 |
$this->entryDao = $app->getModule('daos')->getDao('TimeEntryDao');
|
|
|
18 |
$this->projectDao = $app->getModule('daos')->getDao('ProjectDao');
|
|
|
19 |
$this->userDao = $app->getModule('daos')->getDao('UserDao');
|
|
|
20 |
$this->categoryDao = $app->getModule('daos')->getDao('CategoryDao');
|
|
|
21 |
$this->reportDao = $app->getModule('daos')->getDao('ReportDao');
|
|
|
22 |
$this->flushDatabase();
|
|
|
23 |
}
|
|
|
24 |
|
|
|
25 |
function createNewProject()
|
|
|
26 |
{
|
|
|
27 |
$project = new ProjectRecord;
|
|
|
28 |
$project->CreatorUserName = "admin";
|
|
|
29 |
$project->DateCreated = time();
|
|
|
30 |
$project->CompletionDate = strtotime('+1 month');
|
|
|
31 |
$project->Description = 'Test project 1';
|
|
|
32 |
$project->EstimateDuration = 100.5;
|
|
|
33 |
$project->ManagerUserName = 'manager';
|
|
|
34 |
$project->Name = 'Project 1';
|
|
|
35 |
|
|
|
36 |
return $project;
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
function createNewProject2()
|
|
|
40 |
{
|
|
|
41 |
$project = new ProjectRecord;
|
|
|
42 |
$project->CreatorUserName = "manager";
|
|
|
43 |
$project->DateCreated = time();
|
|
|
44 |
$project->CompletionDate = strtotime('+1 week');
|
|
|
45 |
$project->Description = 'Test project 2';
|
|
|
46 |
$project->EstimateDuration = 30.5;
|
|
|
47 |
$project->ManagerUserName = 'manager';
|
|
|
48 |
$project->Name = 'Project 2';
|
|
|
49 |
|
|
|
50 |
return $project;
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
function createNewCategory()
|
|
|
54 |
{
|
|
|
55 |
$category = new CategoryRecord;
|
|
|
56 |
$category->Name = 'Category 1';
|
|
|
57 |
$category->EstimateDuration = 5.5;
|
|
|
58 |
$category->Abbreviation = 'CAT 1';
|
|
|
59 |
|
|
|
60 |
return $category;
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
function createNewCategory2()
|
|
|
64 |
{
|
|
|
65 |
$category = new CategoryRecord;
|
|
|
66 |
$category->Name = 'Category 2';
|
|
|
67 |
$category->EstimateDuration = 1.5;
|
|
|
68 |
$category->Abbreviation = 'CAT2';
|
|
|
69 |
|
|
|
70 |
return $category;
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
function createNewCategory3()
|
|
|
74 |
{
|
|
|
75 |
$category = new CategoryRecord;
|
|
|
76 |
$category->Name = 'Category 3';
|
|
|
77 |
$category->EstimateDuration = 2.5;
|
|
|
78 |
$category->Abbreviation = 'CAT3';
|
|
|
79 |
|
|
|
80 |
return $category;
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
function createProjectsAndCategories()
|
|
|
84 |
{
|
|
|
85 |
$project1 = $this->createNewProject();
|
|
|
86 |
$this->projectDao->addNewProject($project1);
|
|
|
87 |
|
|
|
88 |
$project2 = $this->createNewProject2();
|
|
|
89 |
$this->projectDao->addNewProject($project2);
|
|
|
90 |
|
|
|
91 |
$category1 = $this->createNewCategory();
|
|
|
92 |
$category1->ProjectID = $project1->ID;
|
|
|
93 |
|
|
|
94 |
$category2 = $this->createNewCategory2();
|
|
|
95 |
$category2->ProjectID = $project2->ID;
|
|
|
96 |
|
|
|
97 |
$category3 = $this->createNewCategory3();
|
|
|
98 |
$category3->ProjectID = $project1->ID;
|
|
|
99 |
|
|
|
100 |
$this->categoryDao->addNewCategory($category1);
|
|
|
101 |
$this->categoryDao->addNewCategory($category2);
|
|
|
102 |
$this->categoryDao->addNewCategory($category3);
|
|
|
103 |
|
|
|
104 |
return array($project1, $project2, $category1, $category2, $category3);
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
function assertSameEntry($entry1, $entry2)
|
|
|
108 |
{
|
|
|
109 |
$this->assertEqual($entry1->CreatorUserName, $entry2->CreatorUserName);
|
|
|
110 |
$this->assertEqual($entry1->Description, $entry2->Description);
|
|
|
111 |
$this->assertEqual($entry1->Duration, $entry2->Duration);
|
|
|
112 |
$this->assertEqual($entry1->ID, $entry2->ID);
|
|
|
113 |
$this->assertEqual($entry1->ReportDate, $entry2->ReportDate);
|
|
|
114 |
$this->assertEqual($entry1->Username, $entry2->Username);
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
|
|
|
118 |
function createTimeEntry1()
|
|
|
119 |
{
|
|
|
120 |
$added = $this->createProjectsAndCategories();
|
|
|
121 |
|
|
|
122 |
$entry = new TimeEntryRecord;
|
|
|
123 |
$entry->CreatorUserName = "admin";
|
|
|
124 |
$entry->Category = $added[2];
|
|
|
125 |
$entry->Description = "New work";
|
|
|
126 |
$entry->Duration = 1.5;
|
|
|
127 |
$entry->Project = $added[0];
|
|
|
128 |
$entry->ReportDate = strtotime('-1 day');
|
|
|
129 |
$entry->Username = 'consultant';
|
|
|
130 |
|
|
|
131 |
return array($entry, $added);
|
|
|
132 |
}
|
|
|
133 |
|
|
|
134 |
function createTimeEntries2()
|
|
|
135 |
{
|
|
|
136 |
$added = $this->createProjectsAndCategories();
|
|
|
137 |
|
|
|
138 |
$entry = new TimeEntryRecord;
|
|
|
139 |
$entry->CreatorUserName = "admin";
|
|
|
140 |
$entry->Category = $added[2];
|
|
|
141 |
$entry->Description = "New work";
|
|
|
142 |
$entry->Duration = 1.2;
|
|
|
143 |
$entry->Project = $added[0];
|
|
|
144 |
$entry->ReportDate = strtotime('-10 day');
|
|
|
145 |
$entry->Username = 'consultant';
|
|
|
146 |
|
|
|
147 |
$entry2 = new TimeEntryRecord;
|
|
|
148 |
$entry2->CreatorUserName = "admin";
|
|
|
149 |
$entry2->Category = $added[4];
|
|
|
150 |
$entry2->Description = "New work 2";
|
|
|
151 |
$entry2->Duration = 5.5;
|
|
|
152 |
$entry2->Project = $added[0];
|
|
|
153 |
$entry2->ReportDate = strtotime('-4 day');
|
|
|
154 |
$entry2->Username = 'consultant';
|
|
|
155 |
|
|
|
156 |
return array($entry, $entry2, $added);
|
|
|
157 |
}
|
|
|
158 |
|
|
|
159 |
function testCreateNewTimeEntry()
|
|
|
160 |
{
|
|
|
161 |
$added = $this->createTimeEntry1();
|
|
|
162 |
$entry = $added[0];
|
|
|
163 |
$this->entryDao->addNewTimeEntry($entry);
|
|
|
164 |
|
|
|
165 |
$check = $this->entryDao->getTimeEntryByID(1);
|
|
|
166 |
|
|
|
167 |
$this->assertSameEntry($entry, $check);
|
|
|
168 |
}
|
|
|
169 |
|
|
|
170 |
function testDeleteTimeEntry()
|
|
|
171 |
{
|
|
|
172 |
$this->testCreateNewTimeEntry();
|
|
|
173 |
$this->entryDao->deleteTimeEntry(1);
|
|
|
174 |
|
|
|
175 |
$check = $this->entryDao->getTimeEntryByID(1);
|
|
|
176 |
$this->assertNull($check);
|
|
|
177 |
}
|
|
|
178 |
|
|
|
179 |
function testGetEntriesInProject()
|
|
|
180 |
{
|
|
|
181 |
$added = $this->createTimeEntries2();
|
|
|
182 |
$this->entryDao->addNewTimeEntry($added[0]);
|
|
|
183 |
$this->entryDao->addNewTimeEntry($added[1]);
|
|
|
184 |
|
|
|
185 |
$list = $this->entryDao->getTimeEntriesInProject('consultant', 1);
|
|
|
186 |
|
|
|
187 |
$this->assertEqual(count($list), 2);
|
|
|
188 |
|
|
|
189 |
$this->assertSameEntry($list[0], $added[0]);
|
|
|
190 |
$this->assertSameEntry($list[1], $added[1]);
|
|
|
191 |
}
|
|
|
192 |
|
|
|
193 |
function testUpdateEntry()
|
|
|
194 |
{
|
|
|
195 |
$added = $this->createTimeEntry1();
|
|
|
196 |
$entry = $added[0];
|
|
|
197 |
$this->entryDao->addNewTimeEntry($entry);
|
|
|
198 |
|
|
|
199 |
$check = $this->entryDao->getTimeEntryByID(1);
|
|
|
200 |
|
|
|
201 |
$this->assertSameEntry($entry, $check);
|
|
|
202 |
|
|
|
203 |
$entry->Description = "asdasd";
|
|
|
204 |
$entry->Duration = 200;
|
|
|
205 |
|
|
|
206 |
$this->entryDao->updateTimeEntry($entry);
|
|
|
207 |
|
|
|
208 |
$verify = $this->entryDao->getTimeEntryByID(1);
|
|
|
209 |
|
|
|
210 |
$this->assertSameEntry($entry, $verify);
|
|
|
211 |
}
|
|
|
212 |
}
|
|
|
213 |
|
|
|
214 |
?>
|