ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilNotificationOSDTest Class Reference
+ Inheritance diagram for ilNotificationOSDTest:
+ Collaboration diagram for ilNotificationOSDTest:

Public Member Functions

 testCreateNotification ()
 
 testGet0Notification ()
 
 testGetNotification ()
 
 testRemoveNotification ()
 
 testRemoveNoNotification ()
 

Protected Member Functions

 setUp ()
 

Private Member Functions

 createDBFunctionCalls (int $insert=0, int $queryF=0, int $fetchAssoc=0, int $manipulateF=0)
 

Private Attributes

ILIAS Notifications ilNotificationOSDHandler $handler
 
ilObjUser $user
 
ilDBInterface &PHPUnit Framework MockObject MockObject $db
 
array $database
 
array $result
 

Detailed Description

Author
Ingmar Szmais iszma.nosp@m.is@d.nosp@m.ataba.nosp@m.y.de

Definition at line 24 of file ilNotificationOSDTest.php.

Member Function Documentation

◆ createDBFunctionCalls()

ilNotificationOSDTest::createDBFunctionCalls ( int  $insert = 0,
int  $queryF = 0,
int  $fetchAssoc = 0,
int  $manipulateF = 0 
)
private

Definition at line 32 of file ilNotificationOSDTest.php.

37 : void {
38 $this->database = [];
39 $this->result = [];
40 $this->db->expects(self::exactly($insert))->method('nextId')->willReturnCallback(function (string $table): int {
41 return count($this->database) + 1;
42 });
43 $this->db->expects(self::exactly($insert))->method('insert')->willReturnCallback(
44 function (string $table, array $object): int {
45 foreach ($object as &$value) {
46 $value = $value[1];
47 }
48 unset($value);
49 $this->database[] = $object;
50 return $object['notification_osd_id'];
51 }
52 );
53 $this->db->expects(self::exactly($queryF))->method('queryF')->willReturnCallback(
54 function (string $query, array $types, array $values): ilPDOStatement {
55 $this->result = [];
56 if (str_contains($query, 'WHERE usr_id')) {
57 foreach ($this->database as $row) {
58 if ($row['usr_id'] === $values[0]) {
59 $this->result[] = $row;
60 }
61 }
62 }
63 if (str_contains($query, 'WHERE notification_osd_id')) {
64 foreach ($this->database as $row) {
65 if ($row['notification_osd_id'] === $values[0]) {
66 $this->result[] = $row;
67 }
68 }
69 }
70 if (str_contains($query, 'SELECT count(*) AS count')) {
71 $this->result = [0 => ['count' => count($this->result)]];
72 }
73 return $this->createMock(ilPDOStatement::class);
74 }
75 );
76 $this->db->expects(self::exactly($fetchAssoc))->method('fetchAssoc')->willReturnCallback(
77 function (ilPDOStatement $rset): ?array {
78 return array_shift($this->result);
79 }
80 );
81 $this->db->expects(self::exactly($manipulateF))->method('manipulateF')->willReturnCallback(
82 function (string $query, array $types, array $values): int {
83 if (count($values) === 1) {
84 foreach ($this->database as $key => $row) {
85 if ($row['notification_osd_id'] === $values[0]) {
86 unset($this->database[$key]);
87 return 1;
88 }
89 }
90 }
91 if (count($values) === 2) {
92 $i = 0;
93 foreach ($this->database as $key => $row) {
94 if ($row['usr_id'] === $values[0] && $row['type'] === $values[1]) {
95 unset($this->database[$key]);
96 $i++;
97 }
98 }
99 return $i;
100 }
101 return 0;
102 }
103 );
104 }
Class ilPDOStatement is a Wrapper Class for PDOStatement.

References ILIAS\Repository\database().

+ Here is the call graph for this function:

◆ setUp()

ilNotificationOSDTest::setUp ( )
protected

Definition at line 106 of file ilNotificationOSDTest.php.

106 : void
107 {
108 $this->db = $this->createMock(ilDBPdo::class);
109 $this->handler = new \ILIAS\Notifications\ilNotificationOSDHandler(
110 new ILIAS\Notifications\Repository\ilNotificationOSDRepository($this->db)
111 );
112 $this->user = $this->createMock(ilObjUser::class);
113 $this->user->method('getId')->willReturn(4);
114 }
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.

References ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ testCreateNotification()

ilNotificationOSDTest::testCreateNotification ( )

Definition at line 116 of file ilNotificationOSDTest.php.

116 : void
117 {
118 $this->createDBFunctionCalls(1);
119 $config = new \ILIAS\Notifications\Model\ilNotificationConfig('test_type');
120 $config->setTitleVar('Test Notification');
121 $config->setShortDescriptionVar('This is a test notification');
122 $test_obj = new \ILIAS\Notifications\Model\ilNotificationObject($config, $this->user);
123 $this->handler->notify($test_obj);
124
125 $this->assertCount(1, $this->database);
126 }
createDBFunctionCalls(int $insert=0, int $queryF=0, int $fetchAssoc=0, int $manipulateF=0)

References ILIAS\Repository\database(), and ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ testGet0Notification()

ilNotificationOSDTest::testGet0Notification ( )

Definition at line 128 of file ilNotificationOSDTest.php.

128 : void
129 {
130 $this->createDBFunctionCalls(0, 1, 1);
131 $this->assertCount(0, $this->handler->getOSDNotificationsForUser($this->user->getId()));
132 }

◆ testGetNotification()

ilNotificationOSDTest::testGetNotification ( )

Definition at line 134 of file ilNotificationOSDTest.php.

134 : void
135 {
136 $this->createDBFunctionCalls(1, 1, 2);
137 $config = new \ILIAS\Notifications\Model\ilNotificationConfig('test_type');
138 $test_obj = new \ILIAS\Notifications\Model\ilNotificationObject($config, $this->user);
139 $this->handler->notify($test_obj);
140
141 $this->assertCount(1, $this->handler->getOSDNotificationsForUser($this->user->getId()));
142 }

References ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ testRemoveNoNotification()

ilNotificationOSDTest::testRemoveNoNotification ( )

Definition at line 158 of file ilNotificationOSDTest.php.

158 : void
159 {
160 $this->createDBFunctionCalls(0, 2, 2, 0);
161 $this->assertCount(0, $this->handler->getOSDNotificationsForUser($this->user->getId()));
162 $this->assertFalse($this->handler->removeOSDNotification(3));
163 }

◆ testRemoveNotification()

ilNotificationOSDTest::testRemoveNotification ( )

Definition at line 144 of file ilNotificationOSDTest.php.

144 : void
145 {
146 $this->createDBFunctionCalls(1, 3, 4, 1);
147 $config = new \ILIAS\Notifications\Model\ilNotificationConfig('test_type');
148 $test_obj = new \ILIAS\Notifications\Model\ilNotificationObject($config, $this->user);
149 $this->handler->notify($test_obj);
150
151 $notifications = $this->handler->getOSDNotificationsForUser($this->user->getId());
152
153 $this->assertCount(1, $notifications);
154 $this->assertTrue($this->handler->removeOSDNotification($notifications[0]->getId()));
155 $this->assertCount(0, $this->handler->getOSDNotificationsForUser($this->user->getId()));
156 }

References ILIAS\Repository\user().

+ Here is the call graph for this function:

Field Documentation

◆ $database

array ilNotificationOSDTest::$database
private

Definition at line 29 of file ilNotificationOSDTest.php.

◆ $db

ilDBInterface& PHPUnit Framework MockObject MockObject ilNotificationOSDTest::$db
private

Definition at line 28 of file ilNotificationOSDTest.php.

◆ $handler

ILIAS Notifications ilNotificationOSDHandler ilNotificationOSDTest::$handler
private

Definition at line 26 of file ilNotificationOSDTest.php.

◆ $result

array ilNotificationOSDTest::$result
private

Definition at line 30 of file ilNotificationOSDTest.php.

◆ $user

ilObjUser ilNotificationOSDTest::$user
private

Definition at line 27 of file ilNotificationOSDTest.php.


The documentation for this class was generated from the following file: