ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilLearnerProgressDBTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 
24 {
25  protected function getLearningProgressFor(int $usr_id, LSItem $ls_item): int
26  {
27  return 20;
28  }
29 }
30 
31 class 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 
103  public function testGetLearnerItemsWithVisibleLSItem(): void
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  $this->access
123  ->expects($this->exactly(2))
124  ->method('checkAccessOfUser')
125  ->withConsecutive([100, 'visible', '', 33], [100, 'read', '', 33])
126  ->willReturn(true)
127  ;
128 
129  $this->items_db
130  ->expects($this->once())
131  ->method('getLSItems')
132  ->with(44)
133  ->willReturn([$ls_item])
134  ;
135 
136  $obj = new ilLearnerProgressDBStub($this->items_db, $this->access, $this->obj_data_cache);
137  $result = $obj->getLearnerItems(100, 44);
138 
139  foreach ($result as $ls_learner_item) {
140  $this->assertInstanceOf(LSLearnerItem::class, $ls_learner_item);
141  $this->assertEquals(33, $ls_learner_item->getRefId());
142  $this->assertEquals(20, $ls_learner_item->getLearningProgressStatus());
143  $this->assertEquals(1, $ls_learner_item->getAvailability());
144  }
145  }
146 }
Class ilLSItemsDB.
Definition: ilLSItemsDB.php:24
Data holding class LSItem .
Definition: LSItem.php:24
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getLearningProgressFor(int $usr_id, LSItem $ls_item)