19declare(strict_types=1);
21use PHPUnit\Framework\TestCase;
22use PHPUnit\Framework\MockObject\MockObject;
35 protected function setUp(): void
47 $user = $this->getMockBuilder(ilObjUser::class)
48 ->disableOriginalConstructor()
50 $user->expects($this->never())
51 ->method($this->anything());
70 $mock_db->method(
'quote')
71 ->willReturnCallback(function ($arg1, string $arg2) {
72 return (
string) $arg1;
74 $mock_db->method(
'quoteIdentifier')
75 ->willReturnCallback(
function (
string $arg1) {
81 $this->web_link_repo = $this->getMockBuilder(ilWebLinkDatabaseRepository::class)
82 ->setConstructorArgs([$webr_id])
85 'getNewDateTimeImmutable',
90 $this->web_link_repo->method(
'getCurrentTime')
91 ->willReturn($current_time);
92 $this->web_link_repo->method(
'getNewDateTimeImmutable')
93 ->willReturnOnConsecutiveCalls(...$datetimes);
96 protected function setGlobal(
string $name, MockObject $obj): void
119 $datetime = $this->getMockBuilder(DateTimeImmutable::class)
120 ->disableOriginalConstructor()
121 ->onlyMethods([
'getTimestamp'])
133 #[\PHPUnit\Framework\Attributes\PreserveGlobalState(false)]
134 #[\PHPUnit\Framework\Attributes\RunInSeparateProcess]
137 $mock_db = $this->getMockBuilder(ilDBInterface::class)
138 ->disableOriginalConstructor()
141 $mock_db->expects($this->exactly(3))
143 ->willReturn(7, 71, 72);
152 $mock_db->expects($this->exactly(3))
154 ->willReturnCallback(fn($table,
$data) => match([$table,
$data]) {
158 'webr_id' => [
'integer', 0],
159 'link_id' => [
'integer', 7],
160 'param_id' => [
'integer', 71],
161 'name' => [
'text',
'name1'],
168 'webr_id' => [
'integer', 0],
169 'link_id' => [
'integer', 7],
170 'param_id' => [
'integer', 72],
171 'name' => [
'text',
'name2'],
178 'internal' => [
'integer', 0],
179 'webr_id' => [
'integer', 0],
180 'link_id' => [
'integer', 7],
181 'title' => [
'text',
'title'],
182 'description' => [
'text',
'description'],
183 'target' => [
'text',
'target'],
184 'active' => [
'integer', 1],
185 'create_date' => [
'integer', 12345678],
186 'last_update' => [
'integer', 12345678]
208 $datetime1 = $this->getNewDateTimeMock(12345678);
209 $datetime2 = $this->getNewDateTimeMock(12345678);
211 $this->setGlobalDBAndRepo(
215 [$datetime1, $datetime2]
218 $this->web_link_repo->expects($this->never())
219 ->method(
'isInternalLink');
249 [$expected_param1, $expected_param2]
251 $this->web_link_repo->createItem($item)
259 #[\PHPUnit\Framework\Attributes\PreserveGlobalState(false)]
260 #[\PHPUnit\Framework\Attributes\RunInSeparateProcess]
263 $mock_db = $this->getMockBuilder(ilDBInterface::class)
264 ->disableOriginalConstructor()
266 $mock_db->expects($this->exactly(3))
268 ->willReturn(7, 71, 72);
277 $mock_db->expects($this->exactly(2))
279 ->willReturnCallback(fn($table,
$data) => match([$table,
$data]) {
283 'webr_id' => [
'integer', 0],
284 'link_id' => [
'integer', 7],
285 'param_id' => [
'integer', 72],
286 'name' => [
'text',
'name2'],
293 'internal' => [
'integer', 1],
294 'webr_id' => [
'integer', 0],
295 'link_id' => [
'integer', 7],
296 'title' => [
'text',
'title'],
297 'description' => [
'text',
'description'],
298 'target' => [
'text',
'trg|123'],
299 'active' => [
'integer', 1],
300 'create_date' => [
'integer', 12345678],
301 'last_update' => [
'integer', 12345678]
323 $datetime1 = $this->getNewDateTimeMock(12345678);
324 $datetime2 = $this->getNewDateTimeMock(12345678);
326 $this->setGlobalDBAndRepo(
330 [$datetime1, $datetime2]
333 $this->web_link_repo->expects($this->once())
334 ->method(
'isInternalLink')
359 $this->web_link_repo->createItem($item)
363 #[\PHPUnit\Framework\Attributes\PreserveGlobalState(false)]
364 #[\PHPUnit\Framework\Attributes\RunInSeparateProcess]
367 $mock_db = $this->getMockBuilder(ilDBInterface::class)
368 ->disableOriginalConstructor()
371 $mock_db->expects($this->once())
376 $mock_db->expects($this->never())
396 $datetime1 = $this->getNewDateTimeMock(12345678);
397 $datetime2 = $this->getNewDateTimeMock(12345678);
399 $this->setGlobalDBAndRepo(
403 [$datetime1, $datetime2]
406 $this->web_link_repo->expects($this->once())
407 ->method(
'isInternalLink')
411 $this->expectException(ilWebLinkDatabaseRepositoryException::class);
412 $this->web_link_repo->createItem($item);
415 #[\PHPUnit\Framework\Attributes\PreserveGlobalState(false)]
416 #[\PHPUnit\Framework\Attributes\RunInSeparateProcess]
419 $mock_db = $this->getMockBuilder(ilDBInterface::class)
420 ->disableOriginalConstructor()
423 $mock_db->expects($this->never())
426 $mock_db->expects($this->once())
431 'webr_id' => [
'integer', 0],
432 'title' => [
'text',
'title'],
433 'description' => [
'text',
''],
434 'create_date' => [
'integer', 12345678],
435 'last_update' => [
'integer', 12345678]
444 $datetime1 = $this->getNewDateTimeMock(12345678);
445 $datetime2 = $this->getNewDateTimeMock(12345678);
447 $this->setGlobalDBAndRepo(
451 [$datetime1, $datetime2]
462 $this->web_link_repo->createList($list)
466 #[\PHPUnit\Framework\Attributes\PreserveGlobalState(false)]
467 #[\PHPUnit\Framework\Attributes\RunInSeparateProcess]
470 $mock_db = $this->getMockBuilder(ilDBInterface::class)
471 ->disableOriginalConstructor()
474 $datetime1 = $this->getNewDateTimeMock(12345678);
475 $datetime2 = $this->getNewDateTimeMock(12345678);
477 $this->setGlobalDBAndRepo(
481 [$datetime1, $datetime2]
498 [$draft_param1, $draft_param2]
555 $repo = $this->getMockBuilder(ilWebLinkDatabaseRepository::class)
556 ->setConstructorArgs([0,
true])
557 ->onlyMethods([
'createItem'])
560 $repo->expects($this->exactly(2))
561 ->method(
'createItem')
562 ->willReturnCallback(fn($item) => match($item) {
563 $draft_item1 => $item1,
564 $draft_item2 => $item2
572 $repo->createAllItemsInDraftContainer($draft_container)
foreach($mandatory_scripts as $file) $timestamp
Customizing of pimple-DIC for ILIAS.
const array VALUES
TODO Once the GUI is updated, undefined can be dropped.
const string PARAMS_TABLE
Draft class for creating and updating a Web Link item.
Container class for drafted Web Link items.
Draft class for creating or updating a Web Link list.
Draft class for creating and updating a parameter attached to Web Link items.
Immutable class for external Web Link items.
Immutable class for internal Web Link items.
Immutable container class for Web Link items.
Immutable class for Web Link lists.
Immutable class for parameters attached to Web Link items.
Unit tests for ilWebLinkDatabaseRepository.
getNewDateTimeMock(int $timestamp)
setGlobal(string $name, MockObject $obj)
setGlobalDBAndRepo(ilDBInterface $mock_db, int $webr_id, int $current_time, array $datetimes)
ilWebLinkRepository &MockObject $web_link_repo
testCreateItemBrokenInternalLinkException()
testCreateAllItemsInDraftContainer()
testCreateInternalItemWithBrokenParameter()
Test creating an item with one intact and one broken parameter, and an internal link.
testCreateExternalItem()
Test creating an item with two intact parameters, and an external link.