-
Notifications
You must be signed in to change notification settings - Fork 249
Expand file tree
/
Copy pathTaskUtilsTest.php
More file actions
253 lines (196 loc) · 7.49 KB
/
Copy pathTaskUtilsTest.php
File metadata and controls
253 lines (196 loc) · 7.49 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
<?php
namespace Hashtopolis\inc\utils;
use Exception;
use Hashtopolis\dba\Factory;
use Hashtopolis\dba\models\Task;
use Hashtopolis\dba\models\TaskWrapper;
use Hashtopolis\inc\defines\DTaskTypes;
use Hashtopolis\TestBase;
//TODO remove:
use Hashtopolis\dba\models\User;
require_once(dirname(__FILE__) . '/../../TestBase.php');
final class TaskUtilsTest extends TestBase {
protected function setUp(): void {
parent::setUp();
}
/**
* Test editing the notes of a task.
*
* @return void
* @throws Exception
*/
public function testEditNotes(): void {
$taskObjects = $this->createTaskHelper();
TaskUtils::editNotes($taskObjects["task"]->getId(), 'task note', $taskObjects["user"]);
$taskUpdated = Factory::getTaskFactory()->get($taskObjects["task"]->getId());
$this->assertEquals('task note', $taskUpdated->getNotes());
}
/**
* Test the status calculation of a task.
*
* @return void
* @throws Exception
*/
public function testGetStatus(): void {
$taskObjects = $this->createTaskHelper();
$this->assertEquals(2, TaskUtils::getStatus($taskObjects["task"]));
//TODO test status 1 (running) and 3 (completed) too
}
/**
* Test the deletion of archived tasks.
*
* @return void
* @throws Exception
*/
/*public function testDeleteArchived(): void {
$this->task1->setIsArchived(1);
//TODO filter for specific user too on $numberOfArchivedTasks and $numberOfArchivedTasksUpdated
$numberOfArchivedTasks = Factory::getTaskFactory()->filter(['isArchived' => true, ]);
TaskUtil::deleteArchived($this->user1);
$numberOfArchivedTasksUpdated = Factory::getTaskFactory()->filter(['isArchived' => true, ]);
$this->assertEquals(0, $numberOfArchivedTasksUpdated);
$this->assertNotEquals($numberOfArchivedTasks, $numberOfArchivedTasksUpdated);
}*/
/**
* Test changing the attack command.
*
* @return void
* @throws Exception
*/
public function testChangeAttackCmd(): void {
$taskObjects = $this->createTaskHelper();
TaskUtils::changeAttackCmd($taskObjects["task"]->getId(), '#HL# custom attack cmd', $taskObjects["user"]);
$taskUpdated = Factory::getTaskFactory()->get($taskObjects["task"]->getId());
$this->assertEquals('#HL# custom attack cmd', $taskUpdated->getAttackCmd());
}
/**
* Test archiving a supertask.
*
* @return void
* @throws Exception
*/
/*public function testArchiveSupertask(): void {
$supertask;
$supertaskWrapper;
$user;
TaskUtils::archiveSupertask($supertask->getId(), $user);
//TODO filter all task wrappers with the id of the $supertaskWrapper (using taskfactory?) and check if they're archived
$supertaskWrapperUpdated = Factory::getTaskWrapperFactory()->get($supertaskWrapper);
$this->assertEquals(1, $supertaskWrapperUpdated->getIsArchived());
}*/
/**
* Test archiving a task.
*
* @return void
* @throws Exception
*/
public function testArchiveTask(): void {
$taskObjects = $this->createTaskHelper();
TaskUtils::archiveTask($taskObjects["task"]->getId(), $taskObjects["user"]);
$taskWrapperUpdated = TaskUtils::getTaskWrapper($taskObjects["task"]->getTaskWrapperId(), $taskObjects["user"]);
$this->assertEquals(1, $taskWrapperUpdated->getIsArchived());
$taskUpdated = Factory::getTaskFactory()->get($taskObjects["task"]->getId());
$this->assertEquals(1, $taskUpdated->getIsArchived());
}
/**
* Test toggle of archiving a normal task and a supertask.
*
* @return void
* @throws Exception
*/
/*public function testToggleArchiveTask(): void {
$task;
$taskTaskWrapper;
$supertask;
$supertaskWrapper;
$user;
//Archive task
TaskUtils::toggleArchiveTask($task->getId(), 1, $user);
$taskWrapperUpdated = TaskUtils::getTaskWrapper($task->getTaskWrapperId(), $user);
$this->assertEquals(1, $taskWrapperUpdated->getIsArchived());
$taskUpdated = Factory::getTaskFactory()->get($task->getId());
$this->assertEquals(1, $taskUpdated->getIsArchived());
//Un-archive task again
TaskUtils::toggleArchiveTask($task->getId(), 0, $user);
$taskWrapperUpdated = TaskUtils::getTaskWrapper($task->getTaskWrapperId(), $user);
$this->assertEquals(0, $taskWrapperUpdated->getIsArchived());
$taskUpdated = Factory::getTaskFactory()->get($task->getId());
$this->assertEquals(0, $taskUpdated->getIsArchived());
//Archive supertask
TaskUtils::toggleArchiveTask($supertask->getId(), 1, $user);
//TODO filter all task wrappers with the id of the $supertaskWrapper (using taskfactory?) and check if they're archived
$supertaskWrapperUpdated = Factory::getTaskWrapperFactory()->get($supertaskWrapper);
$this->assertEquals(1, $supertaskWrapperUpdated->getIsArchived());
//Un-archive supertask again
TaskUtils::toggleArchiveTask($supertask->getId(), 0, $user);
//TODO filter all task wrappers with the id of the $supertaskWrapper (using taskfactory?) and check if they're archived
$supertaskWrapperUpdated = Factory::getTaskWrapperFactory()->get($supertaskWrapper);
$this->assertEquals(0, $supertaskWrapperUpdated->getIsArchived());
}*/
/**
* Test renaming a running supertask.
*
* @return void
* @throws Exception
*/
/*public function testRenameSupertask(): void {
$supertask;
$supertaskWrapper;
$user;
TaskUtils::renameSupertask($supertaskWrapper->getId(), 'custom new supertask name', $user);
$supertaskWrapperUpdated = TaskUtils::getTaskWrapper($supertaskWrapper->getId(), $user);
$this->assertEquals('custom new supertask name', $supertaskWrapperUpdated->getTaskWrapperName());
}*/
/**
* Test getting the task of wrapper.
*
* @return void
* @throws Exception
*/
public function testGetTaskOfWrapper(): void {
$taskObjects = $this->createTaskHelper();
$this->assertEquals($taskObjects["task"]->getId(), TaskUtils::getTaskOfWrapper($taskObjects["taskWrapper"]->getId())->getId());
}
/**
* Test getting tasks of wrapper.
*
* @return void
* @throws Exception
*/
/*public function testGetTasksOfWrapper(): void {
//TODO create supertask
$this->assertEquals(2, count(TaskUtils::getTasksOfWrapper($this->taskWrapper1->getId())));
}*/
/**
* Test getting task wrappers for a user.
*
* @return void
* @throws Exception
*/
/*public function testGetTaskWrappersForUser(): void {
$taskObjects = $this->createTaskHelper();
$taskObjects2 = $this->createTaskHelper();
$taskObjects2["taskWrapper"]->setAccessGroupId($taskObjects["accessGroup"]->getId());
//$this->createAccessGroupUser($taskObjects2["user"], $taskObjects["accessGroup"]);
//var_dump($taskObjects);
//var_dump($taskObjects2);
$this->assertEquals(2, count(TaskUtils::getTaskWrappersForUser($taskObjects["user"])));
}*/
/**
* Test setting the CPU only flag for a task.
*
* @return void
* @throws Exception
*/
public function testSetCpuTask(): void {
$taskObjects = $this->createTaskHelper();
//Set to CPU-only
TaskUtils::setCpuTask($taskObjects["task"]->getId(), 1, $taskObjects["user"]);
$taskUpdated = Factory::getTaskFactory()->get($taskObjects["task"]->getId());
$this->assertEquals(1, $taskUpdated->getIsCpuTask());
//Set to use GPU and CPU
TaskUtils::setCpuTask($taskObjects["task"]->getId(), 0, $taskObjects["user"]);
$taskUpdated = Factory::getTaskFactory()->get($taskObjects["task"]->getId());
$this->assertEquals(0, $taskUpdated->getIsCpuTask());
}
}