ILIAS  release_8 Revision v8.24
ilLearnerProgressDBTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21use PHPUnit\Framework\TestCase;
22
24{
25 protected function getLearningProgressFor(int $usr_id, LSItem $ls_item): int
26 {
27 return 20;
28 }
29}
30
31class ilLearnerProgressDBTest extends TestCase
32{
36 protected $items_db;
37
41 protected $access;
42
43 protected function setUp(): void
44 {
45 $this->items_db = $this->createMock(ilLSItemsDB::class);
46 $this->access = $this->createMock(ilAccess::class);
47 $this->obj_data_cache = $this->createMock(ilObjectDataCache::class);
48 }
49
50 public function testCreateObject(): void
51 {
52 $obj = new ilLearnerProgressDB($this->items_db, $this->access, $this->obj_data_cache);
53
54 $this->assertInstanceOf(ilLearnerProgressDB::class, $obj);
55 }
56
57 public function testGetLearnerItemsWithoutData(): void
58 {
59 $this->items_db
60 ->expects($this->once())
61 ->method('getLsItems')
62 ->with(33)
63 ->willReturn([])
64 ;
65
66 $obj = new ilLearnerProgressDB($this->items_db, $this->access, $this->obj_data_cache);
67 $result = $obj->getLearnerItems(100, 33);
68
69 $this->assertIsArray($result);
70 $this->assertEmpty($result);
71 }
72
74 {
75 $ls_item = $this->createMock(LSItem::class);
76
77 $ls_item
78 ->expects($this->once())
79 ->method('isOnline')
80 ->willReturn(false)
81 ;
82 $ls_item
83 ->expects($this->once())
84 ->method('getRefId')
85 ->willReturn(33)
86 ;
87
88 $this->access
89 ->expects($this->once())
90 ->method('checkAccessOfUser')
91 ->with(100, 'visible', '', 33)
92 ->willReturn(false)
93 ;
94
95 $this->items_db
96 ->expects($this->once())
97 ->method('getLSItems')
98 ->with(44)
99 ->willReturn([$ls_item])
100 ;
101
102 $obj = new ilLearnerProgressDB($this->items_db, $this->access, $this->obj_data_cache);
103 $result = $obj->getLearnerItems(100, 44);
104
105 $this->assertIsArray($result);
106 $this->assertEmpty($result);
107 }
108
110 {
111 $ls_item = $this->createMock(LSItem::class);
112
113 $ls_item
114 ->expects($this->exactly(2))
115 ->method('isOnline')
116 ->willReturn(true)
117 ;
118 $ls_item
119 ->expects($this->exactly(3))
120 ->method('getRefId')
121 ->willReturn(33)
122 ;
123
124 $this->access
125 ->expects($this->once())
126 ->method('clear')
127 ;
128 $this->access
129 ->expects($this->exactly(2))
130 ->method('checkAccessOfUser')
131 ->withConsecutive([100, 'visible', '', 33], [100, 'read', '', 33])
132 ->willReturn(true)
133 ;
134
135 $this->items_db
136 ->expects($this->once())
137 ->method('getLSItems')
138 ->with(44)
139 ->willReturn([$ls_item])
140 ;
141
142 $obj = new ilLearnerProgressDBStub($this->items_db, $this->access, $this->obj_data_cache);
143 $result = $obj->getLearnerItems(100, 44);
144
145 foreach ($result as $ls_learner_item) {
146 $this->assertInstanceOf(LSLearnerItem::class, $ls_learner_item);
147 $this->assertEquals(33, $ls_learner_item->getRefId());
148 $this->assertEquals(20, $ls_learner_item->getLearningProgressStatus());
149 $this->assertEquals(1, $ls_learner_item->getAvailability());
150 }
151 }
152}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: LSItem.php:25
getLearningProgressFor(int $usr_id, LSItem $ls_item)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...