3declare(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());
72 $mock_db->method(
'quote')
73 ->willReturnCallback(
function ($arg1, string $arg2) {
74 return (
string) $arg1;
76 $mock_db->method(
'quoteIdentifier')
77 ->willReturnCallback(
function (
string $arg1) {
83 $this->web_link_repo = $this->getMockBuilder(ilWebLinkDatabaseRepository::class)
84 ->setConstructorArgs([$webr_id, $update_history])
85 ->onlyMethods([
'getCurrentTime',
'getNewDateTimeImmutable'])
88 $this->web_link_repo->method(
'getCurrentTime')
89 ->willReturn($current_time);
90 $this->web_link_repo->method(
'getNewDateTimeImmutable')
91 ->willReturnOnConsecutiveCalls(...$datetimes);
117 $datetime = $this->getMockBuilder(DateTimeImmutable::class)
118 ->disableOriginalConstructor()
119 ->onlyMethods([
'getTimestamp'])
121 $datetime->method(
'getTimestamp')
135 $mock_db = $this->getMockBuilder(ilDBInterface::class)
136 ->disableOriginalConstructor()
139 $mock_db->expects($this->exactly(3))
146 ->willReturn(7, 71, 72);
148 $mock_db->expects($this->exactly(3))
154 'webr_id' => [
'integer', 0],
155 'link_id' => [
'integer', 7],
156 'param_id' => [
'integer', 71],
157 'name' => [
'text',
'name1'],
164 'webr_id' => [
'integer', 0],
165 'link_id' => [
'integer', 7],
166 'param_id' => [
'integer', 72],
167 'name' => [
'text',
'name2'],
174 'internal' => [
'integer', 0],
175 'webr_id' => [
'integer', 0],
176 'link_id' => [
'integer', 7],
177 'title' => [
'text',
'title'],
178 'description' => [
'text',
'description'],
179 'target' => [
'text',
'target'],
180 'active' => [
'integer', 1],
181 'create_date' => [
'integer', 12345678],
182 'last_update' => [
'integer', 12345678]
187 $history = Mockery::mock(
'alias:' . ilHistory::class);
188 $history->shouldReceive(
'_createEntry')
190 ->with(0,
'add', [
'title']);
192 $link_input = Mockery::mock(
'alias:' . ilLinkInputGUI::class);
193 $link_input->shouldReceive(
'isInternalLink')
213 $datetime1 = $this->getNewDateTimeMock(12345678);
214 $datetime2 = $this->getNewDateTimeMock(12345678);
216 $this->setGlobalDBAndRepo(
221 [$datetime1, $datetime2]
252 [$expected_param1, $expected_param2]
254 $this->web_link_repo->createItem($item)
266 $mock_db = $this->getMockBuilder(ilDBInterface::class)
267 ->disableOriginalConstructor()
270 $mock_db->expects($this->exactly(3))
277 ->willReturn(7, 71, 72);
279 $mock_db->expects($this->exactly(2))
285 'webr_id' => [
'integer', 0],
286 'link_id' => [
'integer', 7],
287 'param_id' => [
'integer', 72],
288 'name' => [
'text',
'name2'],
295 'internal' => [
'integer', 1],
296 'webr_id' => [
'integer', 0],
297 'link_id' => [
'integer', 7],
298 'title' => [
'text',
'title'],
299 'description' => [
'text',
'description'],
300 'target' => [
'text',
'trg|123'],
301 'active' => [
'integer', 1],
302 'create_date' => [
'integer', 12345678],
303 'last_update' => [
'integer', 12345678]
308 $history = Mockery::mock(
'alias:' . ilHistory::class);
309 $history->shouldReceive(
'_createEntry')
311 ->with(0,
'add', [
'title']);
313 $link_input = Mockery::mock(
'alias:' . ilLinkInputGUI::class);
314 $link_input->shouldReceive(
'isInternalLink')
336 $datetime1 = $this->getNewDateTimeMock(12345678);
337 $datetime2 = $this->getNewDateTimeMock(12345678);
339 $this->setGlobalDBAndRepo(
344 [$datetime1, $datetime2]
368 $this->web_link_repo->createItem($item)
378 $mock_db = $this->getMockBuilder(ilDBInterface::class)
379 ->disableOriginalConstructor()
382 $mock_db->expects($this->once())
387 $mock_db->expects($this->never())
390 $history = Mockery::mock(
'alias:' . ilHistory::class);
391 $history->shouldReceive(
'_createEntry')
394 $link_input = Mockery::mock(
'alias:' . ilLinkInputGUI::class);
395 $link_input->shouldReceive(
'isInternalLink')
417 $datetime1 = $this->getNewDateTimeMock(12345678);
418 $datetime2 = $this->getNewDateTimeMock(12345678);
420 $this->setGlobalDBAndRepo(
425 [$datetime1, $datetime2]
428 $this->expectException(ilWebLinkDatabaseRepositoryException::class);
429 $this->web_link_repo->createItem($item);
438 $mock_db = $this->getMockBuilder(ilDBInterface::class)
439 ->disableOriginalConstructor()
442 $mock_db->expects($this->never())
445 $mock_db->expects($this->once())
450 'webr_id' => [
'integer', 0],
451 'title' => [
'text',
'title'],
452 'description' => [
'text',
''],
453 'create_date' => [
'integer', 12345678],
454 'last_update' => [
'integer', 12345678]
458 $history = Mockery::mock(
'alias:' . ilHistory::class);
459 $history->shouldReceive(
'_createEntry')
461 ->with(0,
'add', [
'title']);
468 $datetime1 = $this->getNewDateTimeMock(12345678);
469 $datetime2 = $this->getNewDateTimeMock(12345678);
471 $this->setGlobalDBAndRepo(
476 [$datetime1, $datetime2]
487 $this->web_link_repo->createList($list)
497 $mock_db = $this->getMockBuilder(ilDBInterface::class)
498 ->disableOriginalConstructor()
501 $datetime1 = $this->getNewDateTimeMock(12345678);
502 $datetime2 = $this->getNewDateTimeMock(12345678);
504 $this->setGlobalDBAndRepo(
509 [$datetime1, $datetime2]
526 [$draft_param1, $draft_param2]
583 $repo = $this->getMockBuilder(ilWebLinkDatabaseRepository::class)
584 ->setConstructorArgs([0,
true])
585 ->onlyMethods([
'createItem'])
588 $repo->expects($this->exactly(2))
589 ->method(
'createItem')
590 ->withConsecutive([$draft_item1], [$draft_item2])
591 ->willReturn($item1, $item2);
598 $repo->createAllItemsInDraftContainer($draft_container)
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
static return function(ContainerConfigurator $containerConfigurator)
foreach($mandatory_scripts as $file) $timestamp
Customizing of pimple-DIC for ILIAS.
const VALUES
TODO Once the GUI is updated, undefined can be dropped.
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...
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...
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...
Unit tests for ilWebLinkDatabaseRepository.
getNewDateTimeMock(int $timestamp)
testCreateList()
@runInSeparateProcess @preserveGlobalState disabled
setGlobal(string $name, MockObject $obj)
ilWebLinkRepository $web_link_repo
setGlobalDBAndRepo(ilDBInterface $mock_db, int $webr_id, bool $update_history, int $current_time, array $datetimes)
testCreateItemBrokenInternalLinkException()
@runInSeparateProcess @preserveGlobalState disabled
testCreateAllItemsInDraftContainer()
@runInSeparateProcess @preserveGlobalState disabled
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...