ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ilStudyProgrammeAssignmentRepositoryTest Class Reference

@group needsInstalledILIAS More...

+ Inheritance diagram for ilStudyProgrammeAssignmentRepositoryTest:
+ Collaboration diagram for ilStudyProgrammeAssignmentRepositoryTest:

Public Member Functions

 test_init ()
 
 test_create ($repo)
 @depends test_init More...
 
 test_save_and_load ()
 @depends test_create More...
 
 test_read_by_prg_id ()
 @depends test_save_and_load More...
 
 test_read_by_usr_id ()
 @depends test_save_and_load More...
 
 test_read_by_usr_and_prg_ids ()
 @depends test_save_and_load More...
 
 test_create_error_user ($repo)
 @depends test_init @expectedException ilException More...
 
 test_create_error_prg ($repo)
 @depends test_init @expectedException ilException More...
 
 test_read_due_to_restart ()
 @depends test_save_and_load More...
 

Static Public Member Functions

static setUpBeforeClass ()
 
static tearDownAfterClass ()
 

Protected Member Functions

 setUp ()
 

Protected Attributes

 $backupGlobals = false
 

Static Protected Attributes

static $created = []
 
static $prg_1
 
static $prg_2
 
static $usr_1
 
static $usr_2
 

Detailed Description

@group needsInstalledILIAS

Definition at line 6 of file ilStudyProgrammeAssignmentRepositoryTest.php.

Member Function Documentation

◆ setUp()

ilStudyProgrammeAssignmentRepositoryTest::setUp ( )
protected

Definition at line 36 of file ilStudyProgrammeAssignmentRepositoryTest.php.

36 : void
37 {
38 PHPUnit_Framework_Error_Deprecated::$enabled = false;
39
40
41 global $DIC;
42 $this->db = $DIC['ilDB'];
43 }
$DIC
Definition: xapitoken.php:46

References $DIC.

◆ setUpBeforeClass()

static ilStudyProgrammeAssignmentRepositoryTest::setUpBeforeClass ( )
static

Definition at line 15 of file ilStudyProgrammeAssignmentRepositoryTest.php.

15 : void
16 {
17 global $DIC;
18 if (!$DIC) {
19 include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
20 try {
21 ilUnitUtil::performInitialisation();
22 } catch (Exception $e) {
23 }
24 }
26 self::$prg_1->putInTree(ROOT_FOLDER_ID);
28 self::$prg_2->putInTree(ROOT_FOLDER_ID);
29 self::$usr_1 = new ilObjUser();
30 self::$usr_1->create();
31 self::$usr_2 = new ilObjUser();
32 self::$usr_2->create();
33 }
static createInstance()
Create an instance of ilObjStudyProgramme, put in cache.

References $DIC, Vendor\Package\$e, and ilObjStudyProgramme\createInstance().

+ Here is the call graph for this function:

◆ tearDownAfterClass()

static ilStudyProgrammeAssignmentRepositoryTest::tearDownAfterClass ( )
static

Definition at line 263 of file ilStudyProgrammeAssignmentRepositoryTest.php.

263 : void
264 {
265 global $DIC;
266 if (!$DIC) {
267 include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
268 ilUnitUtil::performInitialisation();
269 }
270 global $DIC;
271 $db = $DIC['ilDB'];
272 try {
273 self::$prg_1->delete();
274 } catch (Exception $e) {
275 }
276
277 try {
278 self::$prg_2->delete();
279 } catch (Exception $e) {
280 }
281 self::$usr_1->delete();
282 self::$usr_2->delete();
283 if (count(self::$created) > 0) {
284 $db->manipulate(
286 . ' WHERE'
287 . ' ' . $db->in(
289 array_keys(self::$created),
290 false,
291 'integer'
292 )
293
294 );
295 }
296 }

References $DIC, Vendor\Package\$e, ilStudyProgrammeAssignmentDBRepository\FIELD_ID, and ilStudyProgrammeAssignmentDBRepository\TABLE.

◆ test_create()

ilStudyProgrammeAssignmentRepositoryTest::test_create (   $repo)

@depends test_init

Definition at line 55 of file ilStudyProgrammeAssignmentRepositoryTest.php.

56 {
57 $ass_1 = $repo->createFor(self::$prg_2->getId(), self::$usr_1->getId(), 6);
58 self::$created[$ass_1->getID()] = $ass_1;
59 $ass_2 = $repo->createFor(self::$prg_2->getId(), self::$usr_1->getId(), 6);
60 self::$created[$ass_2->getID()] = $ass_2;
61 $ass_3 = $repo->createFor(self::$prg_2->getId(), self::$usr_2->getId(), 6);
62 self::$created[$ass_3->getID()] = $ass_3;
63 $ass_4 = $repo->createFor(self::$prg_2->getId(), self::$usr_2->getId(), 6);
64 self::$created[$ass_4->getId()] = $ass_4;
65 $this->assertEquals($ass_1->getRootId(), self::$prg_2->getId());
66 $this->assertEquals($ass_1->getUserId(), self::$usr_1->getId());
67 $this->assertEquals($ass_1->getLastChangeBy(), 6);
68 $this->assertNull($ass_1->getRestartDate());
69 $this->assertEquals(
70 $ass_1->getRestartedAssignmentId(),
72 );
73 }

References ilStudyProgrammeAssignment\NO_RESTARTED_ASSIGNMENT.

◆ test_create_error_prg()

ilStudyProgrammeAssignmentRepositoryTest::test_create_error_prg (   $repo)

@depends test_init @expectedException ilException

Definition at line 184 of file ilStudyProgrammeAssignmentRepositoryTest.php.

185 {
186 $repo->createFor(-1, 6, 6);
187 }

◆ test_create_error_user()

ilStudyProgrammeAssignmentRepositoryTest::test_create_error_user (   $repo)

@depends test_init @expectedException ilException

Definition at line 174 of file ilStudyProgrammeAssignmentRepositoryTest.php.

175 {
176 $repo->createFor(self::$prg_1->getId(), -1, 6);
177 }

◆ test_init()

ilStudyProgrammeAssignmentRepositoryTest::test_init ( )

Definition at line 45 of file ilStudyProgrammeAssignmentRepositoryTest.php.

46 {
47 $repo = new ilStudyProgrammeAssignmentDBRepository($this->db);
48 $this->assertInstanceOf(ilStudyProgrammeAssignmentRepository::class, $repo);
49 return $repo;
50 }

◆ test_read_by_prg_id()

ilStudyProgrammeAssignmentRepositoryTest::test_read_by_prg_id ( )

@depends test_save_and_load

Definition at line 105 of file ilStudyProgrammeAssignmentRepositoryTest.php.

106 {
107 $repo = new ilStudyProgrammeAssignmentDBRepository($this->db);
108 $this->assertCount(0, $repo->readByPrgId(-1));
109
110 $asss = $repo->readByPrgId(self::$prg_1->getId());
111 $this->assertCount(1, $asss);
112 $ass = array_shift($asss);
113 $this->assertEquals($ass->getRootId(), self::$prg_1->getId());
114 $this->assertEquals($ass->getUserId(), self::$usr_1->getId());
115
116 $asss = $repo->readByPrgId(self::$prg_2->getId());
117 $this->assertCount(3, $asss);
118 $this->assertEquals(
119 array_map(function ($ass) {
120 return $ass->getUserId();
121 }, $asss),
122 [self::$usr_1->getId(),self::$usr_2->getId(),self::$usr_2->getId()]
123 );
124 foreach ($asss as $ass) {
125 $this->assertEquals($ass->getRootId(), self::$prg_2->getId());
126 }
127 }

◆ test_read_by_usr_and_prg_ids()

ilStudyProgrammeAssignmentRepositoryTest::test_read_by_usr_and_prg_ids ( )

@depends test_save_and_load

Definition at line 157 of file ilStudyProgrammeAssignmentRepositoryTest.php.

158 {
159 $repo = new ilStudyProgrammeAssignmentDBRepository($this->db);
160 $this->assertCount(0, $repo->readByUsrIdAndPrgId(-1, -2));
161
162 $asss = $repo->readByUsrIdAndPrgId(self::$usr_2->getId(), self::$prg_2->getId());
163 $this->assertCount(2, $asss);
164 foreach ($asss as $ass) {
165 $this->assertEquals($ass->getRootId(), self::$prg_2->getId());
166 $this->assertEquals($ass->getUserId(), self::$usr_2->getId());
167 }
168 }

◆ test_read_by_usr_id()

ilStudyProgrammeAssignmentRepositoryTest::test_read_by_usr_id ( )

@depends test_save_and_load

Definition at line 133 of file ilStudyProgrammeAssignmentRepositoryTest.php.

134 {
135 $repo = new ilStudyProgrammeAssignmentDBRepository($this->db);
136 $this->assertCount(0, $repo->readByUsrId(-1));
137
138 $asss = $repo->readByUsrId(self::$usr_1->getId());
139 $this->assertCount(2, $asss);
140 $this->assertEquals(
141 array_map(function ($ass) {
142 return $ass->getRootId();
143 }, $asss),
144 [self::$prg_1->getId(),self::$prg_2->getId()]
145 );
146
147 $asss = $repo->readByUsrId(self::$usr_2->getId());
148 $this->assertCount(2, $asss);
149 foreach ($asss as $ass) {
150 $this->assertEquals($ass->getRootId(), self::$prg_2->getId());
151 }
152 }

◆ test_read_due_to_restart()

ilStudyProgrammeAssignmentRepositoryTest::test_read_due_to_restart ( )

@depends test_save_and_load

Definition at line 193 of file ilStudyProgrammeAssignmentRepositoryTest.php.

194 {
195 $one_day = new DateInterval('P1D');
196 $yesterday = new DateTime();
197 $yesterday->sub($one_day);
198 $today = new DateTime();
199 $tomorrow = new DateTime();
200 $tomorrow->add($one_day);
201 $repo = new ilStudyProgrammeAssignmentDBRepository($this->db);
202 $u_a_repo = ilStudyProgrammeDIC::dic()['ilStudyProgrammeUserAssignmentDB'];
204 $repo->update(array_shift($created)->setRestartDate($yesterday));
205 $repo->update(array_shift($created)->setRestartDate($today));
206 $repo->update(array_shift($created)->setRestartDate($tomorrow));
207 $repo->update(array_shift($created)->setRestartDate(null));
209 $ref = [array_shift($created)->getId(),array_shift($created)->getId()];
210 $this->assertEquals(
211 array_map(function ($ass) {
212 return $ass->getId();
213 }, $repo->readDueToRestart()),
214 $ref
215 );
216 $this->assertEquals(
217 array_map(function ($ass) {
218 return $ass->getId();
219 }, $u_a_repo->getDueToRestartInstances()),
220 $ref
221 );
222
223
225 $repo->update(array_shift($created)->setRestartDate($yesterday));
226 $repo->update(array_shift($created)->setRestartDate($today)->setRestartedAssignmentId(123));
227 $repo->update(array_shift($created)->setRestartDate($tomorrow)->setRestartedAssignmentId(223));
228 $repo->update(array_shift($created)->setRestartDate(null)->setRestartedAssignmentId(323));
230 $ref = [array_shift($created)->getId()];
231 $this->assertEquals(
232 array_map(function ($ass) {
233 return $ass->getId();
234 }, $repo->readDueToRestart()),
235 $ref
236 );
237 $this->assertEquals(
238 array_map(function ($ass) {
239 return $ass->getId();
240 }, $u_a_repo->getDueToRestartInstances()),
241 $ref
242 );
243
245 $repo->update(array_shift($created)->setRestartDate($yesterday)->setRestartedAssignmentId(23));
246 $repo->update(array_shift($created)->setRestartDate($today)->setRestartedAssignmentId(123));
247 $repo->update(array_shift($created)->setRestartDate($tomorrow)->setRestartedAssignmentId(223));
248 $repo->update(array_shift($created)->setRestartDate(null)->setRestartedAssignmentId(323));
249 $this->assertEquals(
250 array_map(function ($ass) {
251 return $ass->getId();
252 }, $repo->readDueToRestart()),
253 []
254 );
255 $this->assertEquals(
256 array_map(function ($ass) {
257 return $ass->getId();
258 }, $u_a_repo->getDueToRestartInstances()),
259 []
260 );
261 }

References $created, and ilStudyProgrammeDIC\dic().

+ Here is the call graph for this function:

◆ test_save_and_load()

ilStudyProgrammeAssignmentRepositoryTest::test_save_and_load ( )

@depends test_create

Definition at line 78 of file ilStudyProgrammeAssignmentRepositoryTest.php.

79 {
80 $repo = new ilStudyProgrammeAssignmentDBRepository($this->db);
81 $ass = $repo->read(current(self::$created)->getId());
82 $this->assertEquals($ass->getId(), current(self::$created)->getId());
83 $this->assertEquals($ass->getRootId(), self::$prg_2->getId());
84 $this->assertEquals($ass->getUserId(), self::$usr_1->getId());
85 $this->assertEquals($ass->getLastChangeBy(), 6);
86 $ass->setRootId(self::$prg_1->getId());
87 $ass->setLastChangeBy(self::$usr_2->getId());
88 $ass->setRestartDate(DateTime::createFromFormat('Ymd', '20210102'));
89 $ass->setRestartedAssignmentId(123);
90 $repo->update($ass);
91
92 $repo = new ilStudyProgrammeAssignmentDBRepository($this->db);
93 $ass = $repo->read(current(self::$created)->getId());
94 $this->assertEquals($ass->getId(), current(self::$created)->getId());
95 $this->assertEquals($ass->getRootId(), self::$prg_1->getId());
96 $this->assertEquals($ass->getUserId(), self::$usr_1->getId());
97 $this->assertEquals($ass->getLastChangeBy(), self::$usr_2->getId());
98 $this->assertEquals($ass->getRestartDate()->format('Ymd'), '20210102');
99 $this->assertEquals($ass->getRestartedAssignmentId(), 123);
100 }

Field Documentation

◆ $backupGlobals

ilStudyProgrammeAssignmentRepositoryTest::$backupGlobals = false
protected

Definition at line 8 of file ilStudyProgrammeAssignmentRepositoryTest.php.

◆ $created

ilStudyProgrammeAssignmentRepositoryTest::$created = []
staticprotected

◆ $prg_1

ilStudyProgrammeAssignmentRepositoryTest::$prg_1
staticprotected

Definition at line 10 of file ilStudyProgrammeAssignmentRepositoryTest.php.

◆ $prg_2

ilStudyProgrammeAssignmentRepositoryTest::$prg_2
staticprotected

Definition at line 11 of file ilStudyProgrammeAssignmentRepositoryTest.php.

◆ $usr_1

ilStudyProgrammeAssignmentRepositoryTest::$usr_1
staticprotected

Definition at line 12 of file ilStudyProgrammeAssignmentRepositoryTest.php.

◆ $usr_2

ilStudyProgrammeAssignmentRepositoryTest::$usr_2
staticprotected

Definition at line 13 of file ilStudyProgrammeAssignmentRepositoryTest.php.


The documentation for this class was generated from the following file: