ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilLearningSequenceActivationDBTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use PHPUnit\Framework\TestCase;
22
24{
28 protected $db;
29
30 protected function setUp(): void
31 {
32 $this->db = $this->createMock(ilDBInterface::class);
33 }
34
35 public function testCreateObjectMinimal(): void
36 {
37 $obj = new ilLearningSequenceActivationDB($this->db);
38
39 $this->assertInstanceOf(ilLearningSequenceActivationDB::class, $obj);
40 }
41
43 {
44 $sql =
45 'SELECT ref_id, online, effective_online, activation_start_ts, activation_end_ts' . PHP_EOL
46 . 'FROM lso_activation' . PHP_EOL
47 . 'WHERE ref_id = 22' . PHP_EOL
48 ;
49
50 $values = [
51 "ref_id" => ["integer", 22],
52 "online" => ["integer", false],
53 "effective_online" => ["integer", false],
54 "activation_start_ts" => ["integer", null],
55 "activation_end_ts" => ["integer", null]
56 ];
57
58 $this->db
59 ->expects($this->once())
60 ->method('quote')
61 ->with(22, 'integer')
62 ->willReturn('22')
63 ;
64 $return = $this->getMockBuilder(ilDBStatement::class)->getMock();
65 $this->db
66 ->expects($this->once())
67 ->method('query')
68 ->with($sql)
69 ->willReturn($return)
70 ;
71 $this->db
72 ->expects($this->once())
73 ->method('numRows')
74 ->willReturn(0)
75 ;
76 $this->db
77 ->expects($this->once())
78 ->method('insert')
79 ->with('lso_activation', $values)
80 ;
81
82 $obj = new ilLearningSequenceActivationDB($this->db);
83 $settings = $obj->getActivationForRefId(22);
84
85 $this->assertInstanceOf(ilLearningSequenceActivation::class, $settings);
86 $this->assertEquals(22, $settings->getRefId());
87 $this->assertFalse($settings->getIsOnline());
88 $this->assertFalse($settings->getEffectiveOnlineStatus());
89 $this->assertNull($settings->getActivationStart());
90 $this->assertNull($settings->getActivationEnd());
91 }
92
93 public function testGetActivationForRefIdWithData(): void
94 {
95 $start_date = new DateTime('2021-07-21 08:19');
96 $end_date = new DateTime('2021-07-21 08:20');
97
98 $sql =
99 'SELECT ref_id, online, effective_online, activation_start_ts, activation_end_ts' . PHP_EOL
100 . 'FROM lso_activation' . PHP_EOL
101 . 'WHERE ref_id = 33' . PHP_EOL
102 ;
103
104 $values = [
105 "ref_id" => 33,
106 "online" => true,
107 "effective_online" => true,
108 "activation_start_ts" => $start_date->getTimestamp(),
109 "activation_end_ts" => $end_date->getTimestamp()
110 ];
111
112 $this->db
113 ->expects($this->once())
114 ->method('quote')
115 ->with(33, 'integer')
116 ->willReturn('33')
117 ;
118 $return_statement = $this->getMockBuilder(ilDBStatement::class)->getMock();
119 $this->db
120 ->expects($this->once())
121 ->method('query')
122 ->with($sql)
123 ->willReturn($return_statement)
124 ;
125 $this->db
126 ->expects($this->once())
127 ->method('numRows')
128 ->willReturn(1)
129 ;
130 $this->db
131 ->expects($this->once())
132 ->method('fetchAssoc')
133 ->with($return_statement)
134 ->willReturn($values)
135 ;
136
137 $obj = new ilLearningSequenceActivationDB($this->db);
138 $settings = $obj->getActivationForRefId(33);
139
140 $this->assertInstanceOf(ilLearningSequenceActivation::class, $settings);
141 $this->assertEquals(33, $settings->getRefId());
142 $this->assertTrue($settings->getIsOnline());
143 $this->assertTrue($settings->getEffectiveOnlineStatus());
144 $this->assertEquals($start_date, $settings->getActivationStart());
145 $this->assertEquals($end_date, $settings->getActivationEnd());
146 }
147
148 public function testDeleteForRefId(): void
149 {
150 $sql =
151 'DELETE FROM lso_activation' . PHP_EOL
152 . 'WHERE ref_id = 44' . PHP_EOL
153 ;
154
155 $this->db
156 ->expects($this->once())
157 ->method('quote')
158 ->with(44, 'integer')
159 ->willReturn('44')
160 ;
161 $this->db
162 ->expects($this->once())
163 ->method('manipulate')
164 ->with($sql)
165 ;
166
167 $obj = new ilLearningSequenceActivationDB($this->db);
168 $obj->deleteForRefId(44);
169 }
170
171 public function testStore(): void
172 {
173 $start_date = new DateTime('2021-07-21 08:19');
174 $end_date = new DateTime('2021-07-21 08:20');
175
176
177 $where = ['ref_id' => ['integer', 35]];
178
179 $values = [
180 "online" => ["integer", true],
181 "activation_start_ts" => ["integer", $start_date->getTimestamp()],
182 "activation_end_ts" => ["integer", $end_date->getTimestamp()]
183 ];
184
185 $this->db
186 ->expects($this->once())
187 ->method('update')
188 ->with('lso_activation', $values, $where)
189 ;
190
191 $settings = new ilLearningSequenceActivation(35, true, false, $start_date, $end_date);
192 $obj = new ilLearningSequenceActivationDB($this->db);
193 $obj->store($settings);
194 }
195}
Persistence for online/activation period.