ILIAS  release_8 Revision v8.24
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 $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 26 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 34 of file ilNotificationOSDTest.php.

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

References $i, ILIAS\LTI\ToolProvider\$key, and $query.

Referenced by testCreateNotification(), testGet0Notification(), testGetNotification(), testRemoveNoNotification(), and testRemoveNotification().

+ Here is the caller graph for this function:

◆ setUp()

ilNotificationOSDTest::setUp ( )
protected

Definition at line 96 of file ilNotificationOSDTest.php.

96 : void
97 {
98 $this->db = $this->createMock(ilDBPdo::class);
99 $this->handler = new \ILIAS\Notifications\ilNotificationOSDHandler(
100 new ILIAS\Notifications\Repository\ilNotificationOSDRepository($this->db)
101 );
102 $this->user = $this->createMock(ilObjUser::class);
103 $this->user->method('getId')->willReturn(4);
104 }
Class ChatMainBarProvider \MainMenu\Provider.

References ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ testCreateNotification()

ilNotificationOSDTest::testCreateNotification ( )

Definition at line 106 of file ilNotificationOSDTest.php.

106 : void
107 {
108 $this->createDBFunctionCalls(1);
109 $config = new \ILIAS\Notifications\Model\ilNotificationConfig('test_type');
110 $config->setTitleVar('Test Notification');
111 $config->setShortDescriptionVar('This is a test notification');
112 $test_obj = new \ILIAS\Notifications\Model\ilNotificationObject($config, $this->user);
113 $this->handler->notify($test_obj);
114
115 $this->assertCount(1, $this->database);
116 }
createDBFunctionCalls(int $insert=0, int $queryF=0, int $fetchAssoc=0, int $manipulateF=0)
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:85

References $config, createDBFunctionCalls(), and ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ testGet0Notification()

ilNotificationOSDTest::testGet0Notification ( )

Definition at line 118 of file ilNotificationOSDTest.php.

118 : void
119 {
120 $this->createDBFunctionCalls(0, 1, 1);
121 $this->assertCount(0, $this->handler->getOSDNotificationsForUser($this->user->getId()));
122 }

References createDBFunctionCalls().

+ Here is the call graph for this function:

◆ testGetNotification()

ilNotificationOSDTest::testGetNotification ( )

Definition at line 124 of file ilNotificationOSDTest.php.

124 : void
125 {
126 $this->createDBFunctionCalls(1, 1, 2);
127 $config = new \ILIAS\Notifications\Model\ilNotificationConfig('test_type');
128 $test_obj = new \ILIAS\Notifications\Model\ilNotificationObject($config, $this->user);
129 $this->handler->notify($test_obj);
130
131 $this->assertCount(1, $this->handler->getOSDNotificationsForUser($this->user->getId()));
132 }

References $config, createDBFunctionCalls(), and ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ testRemoveNoNotification()

ilNotificationOSDTest::testRemoveNoNotification ( )

Definition at line 148 of file ilNotificationOSDTest.php.

148 : void
149 {
150 $this->createDBFunctionCalls(0, 2, 2, 0);
151 $this->assertCount(0, $this->handler->getOSDNotificationsForUser($this->user->getId()));
152 $this->assertFalse($this->handler->removeOSDNotification(3));
153 }

References createDBFunctionCalls().

+ Here is the call graph for this function:

◆ testRemoveNotification()

ilNotificationOSDTest::testRemoveNotification ( )

Definition at line 134 of file ilNotificationOSDTest.php.

134 : void
135 {
136 $this->createDBFunctionCalls(1, 3, 4, 1);
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 $notifications = $this->handler->getOSDNotificationsForUser($this->user->getId());
142
143 $this->assertCount(1, $notifications);
144 $this->assertTrue($this->handler->removeOSDNotification($notifications[0]->getId()));
145 $this->assertCount(0, $this->handler->getOSDNotificationsForUser($this->user->getId()));
146 }

References $config, createDBFunctionCalls(), and ILIAS\Repository\user().

+ Here is the call graph for this function:

Field Documentation

◆ $database

array ilNotificationOSDTest::$database
private

Definition at line 31 of file ilNotificationOSDTest.php.

◆ $db

ilDBInterface ilNotificationOSDTest::$db
private

Definition at line 30 of file ilNotificationOSDTest.php.

◆ $handler

ILIAS Notifications ilNotificationOSDHandler ilNotificationOSDTest::$handler
private

Definition at line 28 of file ilNotificationOSDTest.php.

◆ $result

array ilNotificationOSDTest::$result
private

Definition at line 32 of file ilNotificationOSDTest.php.

◆ $user

ilObjUser ilNotificationOSDTest::$user
private

Definition at line 29 of file ilNotificationOSDTest.php.


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