ILIAS  release_8 Revision v8.24
class.ilCalendarRecurrenceCalculationTest.php
Go to the documentation of this file.
1<?php
2
19use PHPUnit\Framework\TestCase;
21
23{
24 protected $backupGlobals = false;
25 protected Container $dic;
26
27 protected function setUp(): void
28 {
29 $this->initDependencies();
30 parent::setUp();
31 }
32
33 public function testCalculatorConstruct()
34 {
35 $entry = new ilCalendarEntry(0);
36 $entry->setStart(new ilDate('2022-01-01', IL_CAL_DATE));
37 $entry->setEnd(new ilDate('2022-01-01', IL_CAL_DATE));
38 $entry->setFullday(true);
39 $entry->setTitle('First');
40 $rec = new ilCalendarRecurrence(0);
41
43 $entry,
44 $rec
45 );
46 $this->assertTrue($calc instanceof ilCalendarRecurrenceCalculator);
47 }
48
49 public function testYearly()
50 {
51 $entry = new ilCalendarEntry(0);
52 $entry->setStart(new ilDate('2022-01-01', IL_CAL_DATE));
53 $entry->setEnd(new ilDate('2022-01-01', IL_CAL_DATE));
54 $entry->setFullday(true);
55
56 $rec = new ilCalendarRecurrence(0);
57 $rec->setFrequenceType(ilCalendarRecurrence::FREQ_YEARLY);
58 $rec->setInterval(1);
59 $rec->setFrequenceUntilCount(1);
60
62 $entry,
63 $rec
64 );
65 $dl = $calc->calculateDateList(
66 new ilDateTime('2021-12-31', IL_CAL_DATE),
67 new ilDate('2023-12-31', IL_CAL_DATE),
68 -1
69 );
70 $this->assertCount(1, $dl);
71 foreach ($dl as $date) {
72 $this->assertTrue(strcmp($date->get(IL_CAL_DATE), '2022-01-01') === 0);
73 }
74 }
75
76 public function testMonthly()
77 {
78 $entry = new ilCalendarEntry(0);
79 $entry->setStart(new ilDate('2022-01-01', IL_CAL_DATE));
80 $entry->setEnd(new ilDate('2023-01-01', IL_CAL_DATE));
81 $entry->setFullday(true);
82
83 $rec = new ilCalendarRecurrence(0);
84 $rec->setFrequenceType(ilCalendarRecurrence::FREQ_MONTHLY);
85 $rec->setInterval(1);
86 $rec->setFrequenceUntilCount(2);
87
89 $entry,
90 $rec
91 );
92 $dl = $calc->calculateDateList(
93 new ilDateTime('2021-12-31', IL_CAL_DATE),
94 new ilDate('2023-12-31', IL_CAL_DATE),
95 -1
96 );
97 $result = new ilDateList(ilDateList::TYPE_DATE);
98 $result->add(new ilDate('2022-01-01', IL_CAL_DATE));
99 $result->add(new ilDate('2022-02-01', IL_CAL_DATE));
100
101 $this->assertTrue($result == $dl);
102 }
103
104 public function testMonthlyByDay()
105 {
106 $entry = new ilCalendarEntry(0);
107 $entry->setStart(new ilDate('2022-01-01', IL_CAL_DATE));
108 $entry->setEnd(new ilDate('2023-01-01', IL_CAL_DATE));
109 $entry->setFullday(true);
110
111 // next two first days of the month which are on saturday => (2022-01-01, 2022-10-01)
112 $rec = new ilCalendarRecurrence(0);
113 $rec->setFrequenceType(ilCalendarRecurrence::FREQ_MONTHLY);
114 $rec->setBYDAY('SA');
115 $rec->setBYMONTHDAY('1');
116 $rec->setInterval(1);
117 $rec->setFrequenceUntilCount(2);
118
120 $entry,
121 $rec
122 );
123 $dl = $calc->calculateDateList(
124 new ilDateTime('2021-12-31', IL_CAL_DATE),
125 new ilDate('2023-12-31', IL_CAL_DATE),
126 -1
127 );
128 $result = new ilDateList(ilDateList::TYPE_DATE);
129 $result->add(new ilDate('2022-01-01', IL_CAL_DATE));
130 $result->add(new ilDate('2022-10-01', IL_CAL_DATE));
131 $this->assertTrue($result == $dl);
132 }
133
134 protected function setGlobalVariable(string $name, $value): void
135 {
136 global $DIC;
137
138 $GLOBALS[$name] = $value;
139 unset($DIC[$name]);
140 $DIC[$name] = static function (\ILIAS\DI\Container $c) use ($value) {
141 return $value;
142 };
143 }
144
145 protected function initDependencies(): void
146 {
147 $this->dic = new Container();
148 $GLOBALS['DIC'] = $this->dic;
149
150 $this->setGlobalVariable('ilDB', $this->createMock(ilDBInterface::class));
151 $this->setGlobalVariable('lng', $this->createMock(ilLanguage::class));
152 $this->setGlobalVariable('ilErr', $this->createMock(ilErrorHandling::class));
153
154 $logger = $this->getMockBuilder(ilLogger::class)
155 ->disableOriginalConstructor()
156 ->getMock();
157
158 $logger_factory = $this->getMockBuilder(ilLoggerFactory::class)
159 ->disableOriginalConstructor()
160 ->onlyMethods(['getComponentLogger'])
161 ->getMock();
162 $logger_factory->method('getComponentLogger')->willReturn($logger);
163 $this->setGlobalVariable('ilLoggerFactory', $logger_factory);
164 }
165}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:32
const IL_CAL_DATE
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
List of dates.
@classDescription Date and time handling
Class for single dates.
$c
Definition: cli.php:38
global $DIC
Definition: feed.php:28
if($format !==null) $name
Definition: metadata.php:247