ILIAS  release_8 Revision v8.24
ilWebResourceItemsContainerTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21use PHPUnit\Framework\TestCase;
22use PHPUnit\Framework\MockObject\MockObject;
23
28class ilWebResourceItemsContainerTest extends TestCase
29{
33 protected function createItemMock(
34 bool $internal,
35 string $title,
36 int $link_id
37 ): MockObject {
38 if ($internal) {
39 $class = ilWebLinkItemInternal::class;
40 } else {
41 $class = ilWebLinkItemExternal::class;
42 }
43
44 $item = $this->getMockBuilder($class)
45 ->disableOriginalConstructor()
46 ->onlyMethods(['getTitle','getLinkId'])
47 ->getMock();
48
49 $item->method('getTitle')->willReturn($title);
50 $item->method('getLinkId')->willReturn($link_id);
51
52 return $item;
53 }
54
59 public function testSort(): void
60 {
61 $item1 = $this->createItemMock(false, 'c', 1);
62 $item2 = $this->createItemMock(true, 'b', 2);
63 $item3 = $this->createItemMock(true, 'a', 3);
64 $item4 = $this->createItemMock(false, 'e', 4);
65 $item5 = $this->createItemMock(false, 'd', 5);
66
67 $sort_settings = Mockery::mock('alias:' . ilContainerSortingSettings::class);
68 $sort_settings->shouldReceive('_lookupSortMode')
69 ->twice()
70 ->with(13)
72
73 $sort = Mockery::mock('alias:' . ilContainerSorting::class);
74 $sort->shouldReceive('lookupPositions')
75 ->once()
76 ->with(13)
77 ->andReturn([1 => 10, 2 => 30, 3 => 20]);
78
79 $array_util = Mockery::mock('alias:' . ilArrayUtil::class);
80 $array_util->shouldReceive('sortArray')
81 ->once()
82 ->andReturn(
83 [
84 3 => ['title' => 'a', 'item' => $item3],
85 2 => ['title' => 'b', 'item' => $item2],
86 1 => ['title' => 'c', 'item' => $item1],
87 5 => ['title' => 'd', 'item' => $item5],
88 4 => ['title' => 'e', 'item' => $item4]
89 ],
90 [
91 1 => ['position' => 10, 'item' => $item1],
92 3 => ['position' => 20, 'item' => $item3],
93 2 => ['position' => 30, 'item' => $item2]
94 ],
95 [
96 5 => ['title' => 'd', 'item' => $item5],
97 4 => ['title' => 'e', 'item' => $item4]
98 ]
99 );
100
102 13,
103 [$item1, $item2, $item3, $item4, $item5]
104 );
105
106 $this->assertSame($container, $container->sort());
107 $this->assertSame(
108 [$item3, $item2, $item1, $item5, $item4],
109 $container->getItems()
110 );
111 $this->assertSame($container, $container->sort());
112 $this->assertSame(
113 [$item1, $item3, $item2, $item5, $item4],
114 $container->getItems()
115 );
116 }
117}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Unit tests for ilWebLinkItemsContainer.
testSort()
@runInSeparateProcess @preserveGlobalState disabled
createItemMock(bool $internal, string $title, int $link_id)
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
$container
@noRector
Definition: wac.php:14