19 declare(strict_types=1);
35 protected function setUp(): void
44 $this->dic = is_object($DIC) ? clone
$DIC :
$DIC;
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
102 $DIC[$name] =
static function (
Container $c) use ($obj) {
119 $datetime = $this->getMockBuilder(DateTimeImmutable::class)
120 ->disableOriginalConstructor()
121 ->onlyMethods([
'getTimestamp'])
124 ->willReturn($timestamp);
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]
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]
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())
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]
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()
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)
Draft class for creating and updating a parameter attached to Web Link items.
getNewDateTimeMock(int $timestamp)
Immutable class for parameters attached to Web Link items.
Customizing of pimple-DIC for ILIAS.
testCreateAllItemsInDraftContainer()
setGlobal(string $name, MockObject $obj)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
ilWebLinkRepository &MockObject $web_link_repo
Immutable class for external Web Link items.
const array VALUES
TODO Once the GUI is updated, undefined can be dropped.
testCreateItemBrokenInternalLinkException()
Immutable class for Web Link lists.
Immutable container class for Web Link items.
testCreateInternalItemWithBrokenParameter()
Test creating an item with one intact and one broken parameter, and an internal link.
Container class for drafted Web Link items.
foreach($mandatory_scripts as $file) $timestamp
Draft class for creating or updating a Web Link list.
Immutable class for internal Web Link items.
setGlobalDBAndRepo(ilDBInterface $mock_db, int $webr_id, int $current_time, array $datetimes)
Draft class for creating and updating a Web Link item.
const string PARAMS_TABLE
testCreateExternalItem()
Test creating an item with two intact parameters, and an external link.
Unit tests for ilWebLinkDatabaseRepository.