ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilStudyProgrammeSettingsRepositoryTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
24 class ilStudyProgrammeSettingsRepositoryTest extends \PHPUnit\Framework\TestCase
25 {
26  protected $backupGlobals = false;
27  protected static $created;
28 
29  protected function setUp(): void
30  {
32 
33  global $DIC;
34  if (!$DIC) {
35  try {
36  include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
37  ilUnitUtil::performInitialisation();
38  } catch (Exception $e) {
39  }
40  }
41  global $DIC;
42  $this->db = $DIC['ilDB'];
43  $this->tps = $this->createMock(ilOrgUnitObjectTypePositionSetting::class);
44  $this->tps->method('getActivationDefault')
45  ->willReturn(true);
46  }
47 
48  public function test_init()
49  {
51  $this->db,
52  $this->tps
53  );
54  $this->assertInstanceOf(ilStudyProgrammeSettingsRepository::class, $repo);
55  return $repo;
56  }
57 
61  public function testPRGRepoCreate($repo)
62  {
63  $set = $repo->createFor(-1);
64  $this->assertEquals($set->getSubtypeId(), ilStudyProgrammeSettings::DEFAULT_SUBTYPE);
65  $this->assertEquals($set->getStatus(), ilStudyProgrammeSettings::STATUS_DRAFT);
66  $this->assertEquals($set->getLPMode(), ilStudyProgrammeSettings::MODE_UNDEFINED);
67  $this->assertEquals($set->getPoints(), ilStudyProgrammeSettings::DEFAULT_POINTS);
68  $this->assertEquals($set->getDeadlinePeriod(), 0);
69  $this->assertNull($set->getDeadlineDate());
70  $this->assertEquals($set->getValidityOfQualificationPeriod(), ilStudyProgrammeSettings::NO_VALIDITY_OF_QUALIFICATION_PERIOD);
71  $this->assertNull($set->getValidityOfQualificationDate());
72  $this->assertEquals($set->getRestartPeriod(), ilStudyProgrammeSettings::NO_RESTART);
73  }
74 
78  public function testPRGRepoEditAndUpdate()
79  {
81  $this->db,
82  $this->tps
83  );
84  $set = $repo->get(-1);
85  $this->assertEquals($set->getSubtypeId(), ilStudyProgrammeSettings::DEFAULT_SUBTYPE);
86  $this->assertEquals($set->getStatus(), ilStudyProgrammeSettings::STATUS_DRAFT);
87  $this->assertEquals($set->getLPMode(), ilStudyProgrammeSettings::MODE_UNDEFINED);
88  $this->assertEquals($set->getPoints(), ilStudyProgrammeSettings::DEFAULT_POINTS);
89  $this->assertEquals($set->getDeadlinePeriod(), 0);
90  $this->assertNull($set->getDeadlineDate());
91  $this->assertEquals($set->getValidityOfQualificationPeriod(), ilStudyProgrammeSettings::NO_VALIDITY_OF_QUALIFICATION_PERIOD);
92  $this->assertNull($set->getValidityOfQualificationDate());
93  $this->assertEquals($set->getRestartPeriod(), ilStudyProgrammeSettings::NO_RESTART);
94 
96  $this->db,
97  $this->tps
98  );
100  $set = $repo->get(-1);
101  $this->assertEquals($set->getSubtypeId(), ilStudyProgrammeSettings::DEFAULT_SUBTYPE);
102  $this->assertEquals($set->getStatus(), ilStudyProgrammeSettings::STATUS_DRAFT);
103  $this->assertEquals($set->getLPMode(), ilStudyProgrammeSettings::MODE_UNDEFINED);
104  $this->assertEquals($set->getPoints(), ilStudyProgrammeSettings::DEFAULT_POINTS);
105  $this->assertEquals($set->getDeadlinePeriod(), 0);
106  $this->assertNull($set->getDeadlineDate());
107  $this->assertEquals($set->getValidityOfQualificationPeriod(), ilStudyProgrammeSettings::NO_VALIDITY_OF_QUALIFICATION_PERIOD);
108  $this->assertNull($set->getValidityOfQualificationDate());
109  $this->assertEquals($set->getRestartPeriod(), ilStudyProgrammeSettings::NO_RESTART);
110 
111  $set->setSubtypeId(123)
114  ->setPoints(10)
115  ->setDeadlinePeriod(10)
116  ->setValidityOfQualificationPeriod(20)
117  ->setRestartPeriod(30);
118  $repo->update($set);
120  $set = $repo->get(-1);
121  $this->assertEquals($set->getSubtypeId(), 123);
122  $this->assertEquals($set->getStatus(), ilStudyProgrammeSettings::STATUS_ACTIVE);
123  $this->assertEquals($set->getLPMode(), ilStudyProgrammeSettings::MODE_POINTS);
124  $this->assertEquals($set->getPoints(), 10);
125  $this->assertEquals($set->getDeadlinePeriod(), 10);
126  $this->assertNull($set->getDeadlineDate());
127  $this->assertEquals($set->getValidityOfQualificationPeriod(), 20);
128  $this->assertNull($set->getValidityOfQualificationDate());
129  $this->assertEquals($set->getRestartPeriod(), 30);
130 
131  $set->setSubtypeId(123)
132  ->setDeadlineDate(new DateTime())
133  ->setValidityOfQualificationDate(DateTime::createFromFormat('Ymd', '20200101'))
134  ->setRestartPeriod(ilStudyProgrammeSettings::NO_RESTART);
135  $repo->update($set);
137  $set = $repo->get(-1);
138  $this->assertEquals($set->getDeadlinePeriod(), 0);
139  $this->assertEquals($set->getDeadlineDate()->format('Ymd'), (new DateTime())->format('Ymd'));
140  $this->assertEquals($set->getValidityOfQualificationDate()->format('Ymd'), '20200101');
141  $this->assertEquals($set->getValidityOfQualificationPeriod(), ilStudyProgrammeSettings::NO_VALIDITY_OF_QUALIFICATION_PERIOD);
142  $this->assertEquals($set->getRestartPeriod(), ilStudyProgrammeSettings::NO_RESTART);
143 
145  $this->db,
146  $this->tps
147  );
149  $set = $repo->get(-1);
150  $this->assertEquals($set->getSubtypeId(), 123);
151  $this->assertEquals($set->getStatus(), ilStudyProgrammeSettings::STATUS_ACTIVE);
152  $this->assertEquals($set->getLPMode(), ilStudyProgrammeSettings::MODE_POINTS);
153  $this->assertEquals($set->getPoints(), 10);
154  }
155 
159  public function testPRGRepoDelete()
160  {
161  $this->expectException(\LogicException::class);
163  $this->db,
164  $this->tps
165  );
166  $set = $repo->get(-1);
167  $this->assertEquals($set->getSubtypeId(), 123);
168  $this->assertEquals($set->getStatus(), ilStudyProgrammeSettings::STATUS_ACTIVE);
169  $this->assertEquals($set->getLPMode(), ilStudyProgrammeSettings::MODE_POINTS);
170  $this->assertEquals($set->getPoints(), 10);
171  $repo->delete($set);
172  $repo->get(-1);
173  }
174 }
bool $enabled
Whether the system instance is enabled to accept connection requests.
Definition: System.php:123
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...