ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
ilStudyProgrammeSettingsRepositoryTest.php
Go to the documentation of this file.
1 <?php
2 
6 class ilStudyProgrammeSettingsRepositoryTest extends \PHPUnit\Framework\TestCase
7 {
8  protected $backupGlobals = false;
9  protected static $created;
10 
11  protected function setUp() : void
12  {
13  PHPUnit_Framework_Error_Deprecated::$enabled = false;
14 
15  global $DIC;
16  if (!$DIC) {
17  try {
18  include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
19  ilUnitUtil::performInitialisation();
20  } catch (Exception $e) {
21  }
22  }
23  global $DIC;
24  $this->db = $DIC['ilDB'];
25  $this->tps = $this->createMock(ilOrgUnitObjectTypePositionSetting::class);
26  $this->tps->method('getActivationDefault')
27  ->willReturn(true);
28  }
29 
30  public function test_init()
31  {
33  $this->db,
34  $this->tps
35  );
36  $this->assertInstanceOf(ilStudyProgrammeSettingsRepository::class, $repo);
37  return $repo;
38  }
39 
43  public function test_create($repo)
44  {
45  $set = $repo->createFor(-1);
46  $this->assertEquals($set->getSubtypeId(), ilStudyProgrammeSettings::DEFAULT_SUBTYPE);
47  $this->assertEquals($set->getStatus(), ilStudyProgrammeSettings::STATUS_DRAFT);
48  $this->assertEquals($set->getLPMode(), ilStudyProgrammeSettings::MODE_UNDEFINED);
49  $this->assertEquals($set->getPoints(), ilStudyProgrammeSettings::DEFAULT_POINTS);
50  $this->assertEquals($set->getDeadlinePeriod(), 0);
51  $this->assertNull($set->getDeadlineDate());
52  $this->assertEquals($set->getValidityOfQualificationPeriod(), ilStudyProgrammeSettings::NO_VALIDITY_OF_QUALIFICATION_PERIOD);
53  $this->assertNull($set->getValidityOfQualificationDate());
54  $this->assertEquals($set->getRestartPeriod(), ilStudyProgrammeSettings::NO_RESTART);
55  }
56 
60  public function test_edit_and_update()
61  {
63  $this->db,
64  $this->tps
65  );
66  $set = $repo->read(-1);
67  $this->assertEquals($set->getSubtypeId(), ilStudyProgrammeSettings::DEFAULT_SUBTYPE);
68  $this->assertEquals($set->getStatus(), ilStudyProgrammeSettings::STATUS_DRAFT);
69  $this->assertEquals($set->getLPMode(), ilStudyProgrammeSettings::MODE_UNDEFINED);
70  $this->assertEquals($set->getPoints(), ilStudyProgrammeSettings::DEFAULT_POINTS);
71  $this->assertEquals($set->getDeadlinePeriod(), 0);
72  $this->assertNull($set->getDeadlineDate());
73  $this->assertEquals($set->getValidityOfQualificationPeriod(), ilStudyProgrammeSettings::NO_VALIDITY_OF_QUALIFICATION_PERIOD);
74  $this->assertNull($set->getValidityOfQualificationDate());
75  $this->assertEquals($set->getRestartPeriod(), ilStudyProgrammeSettings::NO_RESTART);
76 
78  $this->db,
79  $this->tps
80  );
82  $set = $repo->read(-1);
83  $this->assertEquals($set->getSubtypeId(), ilStudyProgrammeSettings::DEFAULT_SUBTYPE);
84  $this->assertEquals($set->getStatus(), ilStudyProgrammeSettings::STATUS_DRAFT);
85  $this->assertEquals($set->getLPMode(), ilStudyProgrammeSettings::MODE_UNDEFINED);
86  $this->assertEquals($set->getPoints(), ilStudyProgrammeSettings::DEFAULT_POINTS);
87  $this->assertEquals($set->getDeadlinePeriod(), 0);
88  $this->assertNull($set->getDeadlineDate());
89  $this->assertEquals($set->getValidityOfQualificationPeriod(), ilStudyProgrammeSettings::NO_VALIDITY_OF_QUALIFICATION_PERIOD);
90  $this->assertNull($set->getValidityOfQualificationDate());
91  $this->assertEquals($set->getRestartPeriod(), ilStudyProgrammeSettings::NO_RESTART);
92 
93  $set->setSubtypeId(123)
96  ->setPoints(10)
97  ->setDeadlinePeriod(10)
98  ->setValidityOfQualificationPeriod(20)
99  ->setRestartPeriod(30);
100  $repo->update($set);
102  $set = $repo->read(-1);
103  $this->assertEquals($set->getSubtypeId(), 123);
104  $this->assertEquals($set->getStatus(), ilStudyProgrammeSettings::STATUS_ACTIVE);
105  $this->assertEquals($set->getLPMode(), ilStudyProgrammeSettings::MODE_POINTS);
106  $this->assertEquals($set->getPoints(), 10);
107  $this->assertEquals($set->getDeadlinePeriod(), 10);
108  $this->assertNull($set->getDeadlineDate());
109  $this->assertEquals($set->getValidityOfQualificationPeriod(), 20);
110  $this->assertNull($set->getValidityOfQualificationDate());
111  $this->assertEquals($set->getRestartPeriod(), 30);
112 
113  $set->setSubtypeId(123)
114  ->setDeadlineDate(new DateTime())
115  ->setValidityOfQualificationDate(DateTime::createFromFormat('Ymd', '20200101'))
116  ->setRestartPeriod(ilStudyProgrammeSettings::NO_RESTART);
117  $repo->update($set);
119  $set = $repo->read(-1);
120  $this->assertEquals($set->getDeadlinePeriod(), 0);
121  $this->assertEquals($set->getDeadlineDate()->format('Ymd'), (new DateTime())->format('Ymd'));
122  $this->assertEquals($set->getValidityOfQualificationDate()->format('Ymd'), '20200101');
123  $this->assertEquals($set->getValidityOfQualificationPeriod(), ilStudyProgrammeSettings::NO_VALIDITY_OF_QUALIFICATION_PERIOD);
124  $this->assertEquals($set->getRestartPeriod(), ilStudyProgrammeSettings::NO_RESTART);
125 
127  $this->db,
128  $this->tps
129  );
131  $set = $repo->read(-1);
132  $this->assertEquals($set->getSubtypeId(), 123);
133  $this->assertEquals($set->getStatus(), ilStudyProgrammeSettings::STATUS_ACTIVE);
134  $this->assertEquals($set->getLPMode(), ilStudyProgrammeSettings::MODE_POINTS);
135  $this->assertEquals($set->getPoints(), 10);
136  }
137 
142  public function test_delete()
143  {
145  $this->db,
146  $this->tps
147  );
148  $set = $repo->read(-1);
149  $this->assertEquals($set->getSubtypeId(), 123);
150  $this->assertEquals($set->getStatus(), ilStudyProgrammeSettings::STATUS_ACTIVE);
151  $this->assertEquals($set->getLPMode(), ilStudyProgrammeSettings::MODE_POINTS);
152  $this->assertEquals($set->getPoints(), 10);
153  $repo->delete($set);
154  $repo->read(-1);
155  }
156 }
$DIC
Definition: xapitoken.php:46