ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilLearnerProgressDBTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
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{
34 protected ilAccess $access;
36
37 protected function setUp(): void
38 {
39 $this->items_db = $this->createMock(ilLSItemsDB::class);
40 $this->access = $this->createMock(ilAccess::class);
41 $this->obj_data_cache = $this->createMock(ilObjectDataCache::class);
42 }
43
44 public function testCreateObject(): void
45 {
46 $obj = new ilLearnerProgressDB($this->items_db, $this->access, $this->obj_data_cache);
47
48 $this->assertInstanceOf(ilLearnerProgressDB::class, $obj);
49 }
50
51 public function testGetLearnerItemsWithoutData(): void
52 {
53 $this->items_db
54 ->expects($this->once())
55 ->method('getLsItems')
56 ->with(33)
57 ->willReturn([])
58 ;
59
60 $obj = new ilLearnerProgressDB($this->items_db, $this->access, $this->obj_data_cache);
61 $result = $obj->getLearnerItems(100, 33);
62
63 $this->assertIsArray($result);
64 $this->assertEmpty($result);
65 }
66
68 {
69 $ls_item = $this->createMock(LSItem::class);
70
71 $ls_item
72 ->expects($this->once())
73 ->method('isOnline')
74 ->willReturn(false)
75 ;
76 $ls_item
77 ->expects($this->once())
78 ->method('getRefId')
79 ->willReturn(33)
80 ;
81
82 $this->access
83 ->expects($this->once())
84 ->method('checkAccessOfUser')
85 ->with(100, 'visible', '', 33)
86 ->willReturn(false)
87 ;
88
89 $this->items_db
90 ->expects($this->once())
91 ->method('getLSItems')
92 ->with(44)
93 ->willReturn([$ls_item])
94 ;
95
96 $obj = new ilLearnerProgressDB($this->items_db, $this->access, $this->obj_data_cache);
97 $result = $obj->getLearnerItems(100, 44);
98
99 $this->assertIsArray($result);
100 $this->assertEmpty($result);
101 }
102
104 {
105 $ls_item = $this->createMock(LSItem::class);
106
107 $ls_item
108 ->expects($this->exactly(2))
109 ->method('isOnline')
110 ->willReturn(true)
111 ;
112 $ls_item
113 ->expects($this->exactly(3))
114 ->method('getRefId')
115 ->willReturn(33)
116 ;
117
118 $this->access
119 ->expects($this->once())
120 ->method('clear')
121 ;
122
123 $consecutive = [
124 [100, 'visible', '', 33],
125 [100, 'read', '', 33]
126 ];
127 $this->access
128 ->expects($this->exactly(2))
129 ->method('checkAccessOfUser')
130 ->willReturnCallback(
131 function ($uid, $perm, $cmd, $ref_id) use (&$consecutive) {
132 $expected = array_shift($consecutive);
133 $this->assertEquals($expected, [$uid, $perm, $cmd, $ref_id]);
134 return true;
135 }
136 );
137 ;
138
139 $this->items_db
140 ->expects($this->once())
141 ->method('getLSItems')
142 ->with(44)
143 ->willReturn([$ls_item])
144 ;
145
146 $obj = new ilLearnerProgressDBStub($this->items_db, $this->access, $this->obj_data_cache);
147 $result = $obj->getLearnerItems(100, 44);
148
149 foreach ($result as $ls_learner_item) {
150 $this->assertInstanceOf(LSLearnerItem::class, $ls_learner_item);
151 $this->assertEquals(33, $ls_learner_item->getRefId());
152 $this->assertEquals(20, $ls_learner_item->getLearningProgressStatus());
153 $this->assertEquals(1, $ls_learner_item->getAvailability());
154 }
155 }
156}
Data holding class LSItem .
Definition: LSItem.php:25
Class ilAccessHandler Checks access for ILIAS objects.
Class ilLSItemsDB.
Definition: ilLSItemsDB.php:25
getLearningProgressFor(int $usr_id, LSItem $ls_item)
Get LearningProgress and availability of items in sequence.
class ilObjectDataCache
$ref_id
Definition: ltiauth.php:66