19 declare(strict_types=1);
39 $class = ilWebLinkItemInternal::class;
41 $class = ilWebLinkItemExternal::class;
44 $item = $this->getMockBuilder($class)
45 ->disableOriginalConstructor()
46 ->onlyMethods([
'getTitle',
'getLinkId'])
49 $item->method(
'getTitle')->willReturn($title);
50 $item->method(
'getLinkId')->willReturn($link_id);
63 $container = $this->getMockBuilder(ilWebLinkItemsContainer::class)
64 ->setConstructorArgs([
66 [$item1, $item2, $item3, $item4, $item5]
68 ->onlyMethods([
'lookupSortMode',
'lookupManualPositions',
'sortArray'])
71 ->method(
'lookupSortMode')
75 ->method(
'lookupManualPositions');
80 3 => [
'title' =>
'a',
'item' => $item3],
81 2 => [
'title' =>
'b',
'item' => $item2],
82 1 => [
'title' =>
'c',
'item' => $item1],
83 5 => [
'title' =>
'd',
'item' => $item5],
84 4 => [
'title' =>
'e',
'item' => $item4]
89 $this->assertSame(
$container, $container_after_sorting);
91 [$item3, $item2, $item1, $item5, $item4],
92 $container_after_sorting->getItems()
104 $container = $this->getMockBuilder(ilWebLinkItemsContainer::class)
105 ->setConstructorArgs([
107 [$item1, $item2, $item3, $item4, $item5]
109 ->onlyMethods([
'lookupSortMode',
'lookupManualPositions',
'sortArray'])
112 ->method(
'lookupSortMode')
116 ->method(
'lookupManualPositions')
118 ->willReturn([1 => 10, 2 => 30, 3 => 20]);
120 ->method(
'sortArray')
121 ->willReturnOnConsecutiveCalls(
123 1 => [
'position' => 10,
'item' => $item1],
124 3 => [
'position' => 20,
'item' => $item3],
125 2 => [
'position' => 30,
'item' => $item2]
128 5 => [
'title' =>
'd',
'item' => $item5],
129 4 => [
'title' =>
'e',
'item' => $item4]
133 $container_after_sorting =
$container->sort();
134 $this->assertSame(
$container, $container_after_sorting);
136 [$item1, $item3, $item2, $item5, $item4],
137 $container_after_sorting->getItems()
createItemMock(bool $internal, string $title, int $link_id)
Unit tests for ilWebLinkItemsContainer.