ILIAS  release_7 Revision v7.30-3-g800a261c036
ilPrgRestartAssignmentsCronJobTest.php
Go to the documentation of this file.
1<?php
2
6class ilPrgRestartAssignmentsCronJobTest extends \PHPUnit\Framework\TestCase
7{
8 protected $backupGlobals = false;
9
11
12 protected static $instances = [];
13 protected static $users = [];
14
15 public static function setUpBeforeClass() : void
16 {
17 PHPUnit_Framework_Error_Deprecated::$enabled = false;
18
19 global $DIC;
20 if (!$DIC) {
21 try {
22 include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
23 ilUnitUtil::performInitialisation();
24 } catch (Exception $e) {
25 }
26 }
27 }
28
29 public function setUp() : void
30 {
31 $this->assignment_repo =
32 ilStudyProgrammeDIC::dic()['model.Assignment.ilStudyProgrammeAssignmentRepository'];
33 }
34
35 public function test_init()
36 {
38 $this->assertInstanceOf(ilCronJob::class, $job);
39 return $job;
40 }
41
45 public function test_run($job)
46 {
47 $usr1 = $this->newUser();
48 $usr2 = $this->newUser();
49 $usr3 = $this->newUser();
50 $usr4 = $this->newUser();
51
52 $prg = $this->newPrg();
53 $prg->putInTree(ROOT_FOLDER_ID);
55 $prg->update();
56
57 $assignment1 = $prg->assignUser($usr1->getId(), 6);
58 $assignment2 = $prg->assignUser($usr2->getId(), 6);
59 $assignment2_r = $assignment2->restartAssignment();
60 $assignment3 = $prg->assignUser($usr3->getId(), 6);
61 $assignment4 = $prg->assignUser($usr4->getId(), 6);
62
63 $this->assertCount(1, $prg->getAssignmentsOf($usr1->getId()));
64 $this->assertCount(2, $prg->getAssignmentsOf($usr2->getId()));
65 $this->assertCount(1, $prg->getAssignmentsOf($usr3->getId()));
66 $this->assertCount(1, $prg->getAssignmentsOf($usr4->getId()));
67
68 $yesterday = new DateTime();
69 $yesterday->sub(new DateInterval('P1D'));
70 $tomorrow = new DateTime();
71 $tomorrow->add(new DateInterval('P1D'));
72
73 $m_ass1 = $this->assignment_repo->get($assignment1->getId());
74 $this->assignment_repo->update($m_ass1->setRestartDate($yesterday));
75 $m_ass2 = $this->assignment_repo->get($assignment2->getId());
76 $this->assignment_repo->update($m_ass2->setRestartDate($yesterday));
77 $m_ass3 = $this->assignment_repo->get($assignment3->getId());
78 $this->assignment_repo->update($m_ass3->setRestartDate($tomorrow));
79
80 $job->run();
81
82 $this->assertCount(2, $prg->getAssignmentsOf($usr1->getId()));
83 $this->assertCount(2, $prg->getAssignmentsOf($usr2->getId()));
84 $this->assertCount(1, $prg->getAssignmentsOf($usr3->getId()));
85 $this->assertCount(1, $prg->getAssignmentsOf($usr4->getId()));
86
87 foreach ($prg->getAssignmentsOf($usr1->getId()) as $ass) {
88 if ($ass->getId() !== $assignment1->getId()) {
89 $assignment1_r = $ass;
90 }
91 if ($ass->getId() === $assignment1->getId()) {
92 $assignment1 = $ass;
93 }
94 }
95 $this->assertEquals($assignment1->getRestartedAssignmentId(), $assignment1_r->getId());
96 }
97
98 public static function tearDownAfterClass() : void
99 {
100 foreach (self::$instances as $instance) {
101 try {
102 $instance->delete();
103 } catch (Exception $e) {
104 }
105 }
106 foreach (self::$users as $user) {
107 $user->delete();
108 }
109 }
110
111
112 protected function newUser()
113 {
114 $user = new ilObjUser();
115 $user->create();
116 self::$users[] = $user;
117 return $user;
118 }
119
120 protected function newPrg()
121 {
123
124
125 self::$instances[] = $prg;
126 return $prg;
127 }
128}
An exception for terminatinating execution or to throw for unit testing.
static createInstance()
Create an instance of ilObjStudyProgramme, put in cache.
Re-assign users (according to restart-date).
const ROOT_FOLDER_ID
Definition: constants.php:30
global $DIC
Definition: goto.php:24