Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
99.61% |
256 / 257 |
|
80.00% |
4 / 5 |
CRAP | |
0.00% |
0 / 1 |
| phpbb_notification_test | |
99.61% |
256 / 257 |
|
80.00% |
4 / 5 |
9 | |
0.00% |
0 / 1 |
| getDataSet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| test_get_notification_type_id | |
94.44% |
17 / 18 |
|
0.00% |
0 / 1 |
2.00 | |||
| test_get_subscription_types | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
1 | |||
| test_subscriptions | |
100.00% |
20 / 20 |
|
100.00% |
1 / 1 |
3 | |||
| test_notifications | |
100.00% |
209 / 209 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * |
| 4 | * This file is part of the phpBB Forum Software package. |
| 5 | * |
| 6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
| 7 | * @license GNU General Public License, version 2 (GPL-2.0) |
| 8 | * |
| 9 | * For full copyright and license information, please see |
| 10 | * the docs/CREDITS.txt file. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | require_once __DIR__ . '/base.php'; |
| 15 | |
| 16 | class phpbb_notification_test extends phpbb_tests_notification_base |
| 17 | { |
| 18 | protected $notifications, $db, $container, $user, $config, $auth, $cache; |
| 19 | |
| 20 | public function getDataSet() |
| 21 | { |
| 22 | return $this->createXMLDataSet(__DIR__ . '/fixtures/notification.xml'); |
| 23 | } |
| 24 | |
| 25 | public function test_get_notification_type_id() |
| 26 | { |
| 27 | // They should be inserted the first time |
| 28 | $post_type_id = $this->notifications->get_notification_type_id('notification.type.post'); |
| 29 | $quote_type_id = $this->notifications->get_notification_type_id('notification.type.quote'); |
| 30 | $test_type_id = $this->notifications->get_notification_type_id('test'); |
| 31 | |
| 32 | self::assertEquals(array( |
| 33 | 'test' => $test_type_id, |
| 34 | 'notification.type.quote' => $quote_type_id, |
| 35 | 'notification.type.post' => $post_type_id, |
| 36 | ), |
| 37 | $this->notifications->get_notification_type_ids(array( |
| 38 | 'test', |
| 39 | 'notification.type.quote', |
| 40 | 'notification.type.post', |
| 41 | ) |
| 42 | )); |
| 43 | self::assertEquals($quote_type_id, $this->notifications->get_notification_type_id('notification.type.quote')); |
| 44 | |
| 45 | try |
| 46 | { |
| 47 | self::assertEquals(false, $this->notifications->get_notification_type_id('fail')); |
| 48 | |
| 49 | self::fail('Non-existent type should throw an exception'); |
| 50 | } |
| 51 | catch (Exception $e) {} |
| 52 | } |
| 53 | |
| 54 | public function test_get_subscription_types() |
| 55 | { |
| 56 | $subscription_types = $this->notifications->get_subscription_types(); |
| 57 | |
| 58 | self::assertArrayHasKey('NOTIFICATION_GROUP_MISCELLANEOUS', $subscription_types); |
| 59 | self::assertArrayHasKey('NOTIFICATION_GROUP_POSTING', $subscription_types); |
| 60 | |
| 61 | self::assertArrayHasKey('notification.type.bookmark', $subscription_types['NOTIFICATION_GROUP_POSTING']); |
| 62 | self::assertArrayHasKey('notification.type.mention', $subscription_types['NOTIFICATION_GROUP_POSTING']); |
| 63 | self::assertArrayHasKey('notification.type.post', $subscription_types['NOTIFICATION_GROUP_POSTING']); |
| 64 | self::assertArrayHasKey('notification.type.quote', $subscription_types['NOTIFICATION_GROUP_POSTING']); |
| 65 | self::assertArrayHasKey('notification.type.topic', $subscription_types['NOTIFICATION_GROUP_POSTING']); |
| 66 | |
| 67 | self::assertArrayHasKey('notification.type.pm', $subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']); |
| 68 | |
| 69 | //get_subscription_types |
| 70 | //get_subscription_methods |
| 71 | } |
| 72 | |
| 73 | public function test_subscriptions() |
| 74 | { |
| 75 | $expected_subscriptions = array( |
| 76 | 'notification.type.forum' => array('notification.method.board'), |
| 77 | 'notification.type.mention' => array('notification.method.board'), |
| 78 | 'notification.type.post' => array('notification.method.board'), |
| 79 | 'notification.type.topic' => array('notification.method.board'), |
| 80 | 'notification.type.quote' => array('notification.method.board'), |
| 81 | 'notification.type.bookmark' => array('notification.method.board'), |
| 82 | 'test' => array('notification.method.board'), |
| 83 | 'notification.type.pm' => array('notification.method.board'), |
| 84 | ); |
| 85 | |
| 86 | $subscriptions = $this->notifications->get_global_subscriptions(2); |
| 87 | foreach ($expected_subscriptions as $item_type => $methods) |
| 88 | { |
| 89 | self::assertArrayHasKey($item_type, $subscriptions); |
| 90 | $this->assert_array_content_equals($methods, $subscriptions[$item_type]); |
| 91 | } |
| 92 | |
| 93 | foreach ($subscriptions as $item_type => $methods) |
| 94 | { |
| 95 | $this->assert_array_content_equals($methods, $expected_subscriptions[$item_type]); |
| 96 | } |
| 97 | |
| 98 | $this->notifications->delete_subscription('notification.type.post', 0, 'notification.method.board', 2); |
| 99 | |
| 100 | self::assertArrayNotHasKey('notification.type.post', $this->notifications->get_global_subscriptions(2)); |
| 101 | |
| 102 | $this->notifications->add_subscription('notification.type.post', 0, 'notification.method.board', 2); |
| 103 | |
| 104 | self::assertArrayHasKey('notification.type.post', $this->notifications->get_global_subscriptions(2)); |
| 105 | } |
| 106 | |
| 107 | public function test_notifications() |
| 108 | { |
| 109 | $this->db->sql_query('DELETE FROM phpbb_notification_types'); |
| 110 | |
| 111 | $types = array('notification.type.quote', 'notification.type.bookmark', 'notification.type.post', 'test'); |
| 112 | foreach ($types as $id => $type) |
| 113 | { |
| 114 | $this->getConnection()->createQueryTable('insertNotification', 'INSERT INTO phpbb_notification_types ' . |
| 115 | $this->db->sql_build_array('INSERT', array( |
| 116 | 'notification_type_id' => ($id + 1), |
| 117 | 'notification_type_name' => $type, |
| 118 | 'notification_type_enabled' => 1, |
| 119 | )) |
| 120 | ); |
| 121 | } |
| 122 | |
| 123 | // Used to test post notifications later |
| 124 | $this->db->sql_query('INSERT INTO ' . TOPICS_WATCH_TABLE . ' ' . $this->db->sql_build_array('INSERT', array( |
| 125 | 'topic_id' => 2, |
| 126 | 'notify_status' => NOTIFY_YES, |
| 127 | 'user_id' => 0, |
| 128 | ))); |
| 129 | |
| 130 | self::assertEquals(array( |
| 131 | 'notifications' => array(), |
| 132 | 'unread_count' => 0, |
| 133 | 'total_count' => 0, |
| 134 | ), $this->notifications->load_notifications('notification.method.board', array( |
| 135 | 'count_unread' => true, |
| 136 | ))); |
| 137 | |
| 138 | $this->notifications->add_notifications('test', array( |
| 139 | 'post_id' => '1', |
| 140 | 'topic_id' => '1', |
| 141 | 'post_time' => 1349413321, |
| 142 | )); |
| 143 | |
| 144 | $this->notifications->add_notifications('test', array( |
| 145 | 'post_id' => '2', |
| 146 | 'topic_id' => '2', |
| 147 | 'post_time' => 1349413322, |
| 148 | )); |
| 149 | |
| 150 | $this->notifications->add_notifications('test', array( |
| 151 | 'post_id' => '3', |
| 152 | 'topic_id' => '2', |
| 153 | 'post_time' => 1349413323, |
| 154 | )); |
| 155 | |
| 156 | $this->notifications->add_notifications(array('notification.type.quote', 'notification.type.bookmark', 'notification.type.post', 'test'), array( |
| 157 | 'post_id' => '4', |
| 158 | 'topic_id' => '2', |
| 159 | 'post_time' => 1349413324, |
| 160 | 'poster_id' => 2, |
| 161 | 'topic_title' => 'test-title', |
| 162 | 'post_subject' => 'Re: test-title', |
| 163 | 'forum_id' => 2, |
| 164 | 'forum_name' => 'Your first forum', |
| 165 | 'post_username' => '', |
| 166 | 'post_text' => 'test text', |
| 167 | )); |
| 168 | |
| 169 | $this->db->sql_query('INSERT INTO ' . BOOKMARKS_TABLE . ' ' . $this->db->sql_build_array('INSERT', array( |
| 170 | 'topic_id' => 2, |
| 171 | 'user_id' => 0, |
| 172 | ))); |
| 173 | |
| 174 | $this->notifications->add_notifications(array('notification.type.quote', 'notification.type.bookmark', 'notification.type.post', 'test'), array( |
| 175 | 'post_id' => '5', |
| 176 | 'topic_id' => '2', |
| 177 | 'post_time' => 1349413325, |
| 178 | 'poster_id' => 2, |
| 179 | 'topic_title' => 'test-title', |
| 180 | 'post_subject' => 'Re: test-title', |
| 181 | 'forum_id' => 2, |
| 182 | 'forum_name' => 'Your first forum', |
| 183 | 'post_username' => '', |
| 184 | 'post_text' => 'test text', |
| 185 | )); |
| 186 | |
| 187 | $this->notifications->delete_subscription('test'); |
| 188 | |
| 189 | $this->notifications->add_notifications('test', array( |
| 190 | 'post_id' => '6', |
| 191 | 'topic_id' => '2', |
| 192 | 'post_time' => 1349413326, |
| 193 | )); |
| 194 | |
| 195 | $this->assert_notifications( |
| 196 | array( |
| 197 | array( |
| 198 | 'item_id' => 1, |
| 199 | 'item_parent_id' => 1, |
| 200 | 'user_id' => 0, |
| 201 | 'notification_read' => 0, |
| 202 | 'notification_time' => 1349413321, |
| 203 | 'notification_data' => array(), |
| 204 | ), |
| 205 | array( |
| 206 | 'item_id' => 2, |
| 207 | 'item_parent_id' => 2, |
| 208 | 'user_id' => 0, |
| 209 | 'notification_read' => 0, |
| 210 | 'notification_time' => 1349413322, |
| 211 | 'notification_data' => array(), |
| 212 | ), |
| 213 | array( |
| 214 | 'item_id' => 3, |
| 215 | 'item_parent_id' => 2, |
| 216 | 'user_id' => 0, |
| 217 | 'notification_read' => 0, |
| 218 | 'notification_time' => 1349413323, |
| 219 | 'notification_data' => array(), |
| 220 | ), |
| 221 | array( |
| 222 | 'item_id' => 4, |
| 223 | 'item_parent_id' => 2, |
| 224 | 'user_id' => 0, |
| 225 | 'notification_read' => 0, |
| 226 | 'notification_time' => 1349413324, |
| 227 | 'notification_data' => array( |
| 228 | 'poster_id' => 2, |
| 229 | 'topic_title' => 'test-title', |
| 230 | 'post_subject' => 'Re: test-title', |
| 231 | 'post_username' => '', |
| 232 | 'forum_id' => 2, |
| 233 | 'forum_name' => 'Your first forum', |
| 234 | ), |
| 235 | ), |
| 236 | array( |
| 237 | 'item_id' => 5, |
| 238 | 'item_parent_id' => 2, |
| 239 | 'user_id' => 0, |
| 240 | 'notification_read' => 0, |
| 241 | 'notification_time' => 1349413325, |
| 242 | 'notification_data' => array( |
| 243 | 'poster_id' => 2, |
| 244 | 'topic_title' => 'test-title', |
| 245 | 'post_subject' => 'Re: test-title', |
| 246 | 'post_username' => '', |
| 247 | 'forum_id' => 2, |
| 248 | 'forum_name' => 'Your first forum', |
| 249 | ), |
| 250 | ), |
| 251 | ) |
| 252 | ); |
| 253 | |
| 254 | // Now test updating ------------------------------- |
| 255 | |
| 256 | $this->notifications->update_notifications('test', array( |
| 257 | 'post_id' => '1', |
| 258 | 'topic_id' => '2', // change parent_id |
| 259 | 'post_time' => 1349413321, |
| 260 | )); |
| 261 | |
| 262 | $this->notifications->update_notifications('test', array( |
| 263 | 'post_id' => '3', |
| 264 | 'topic_id' => '2', |
| 265 | 'post_time' => 1234, // change time |
| 266 | )); |
| 267 | |
| 268 | $this->notifications->update_notifications(array('notification.type.quote', 'notification.type.bookmark', 'notification.type.post', 'test'), array( |
| 269 | 'post_id' => '5', |
| 270 | 'topic_id' => '2', |
| 271 | 'poster_id' => 2, |
| 272 | 'topic_title' => 'test-title2', // change topic_title |
| 273 | 'post_subject' => 'Re: test-title2', // change post_subject |
| 274 | 'forum_id' => 3, // change forum_id |
| 275 | 'forum_name' => 'Your second forum', // change forum_name |
| 276 | 'post_username' => '', |
| 277 | 'post_text' => 'test text2', |
| 278 | 'post_time' => 1349413325, |
| 279 | )); |
| 280 | |
| 281 | $this->assert_notifications( |
| 282 | array( |
| 283 | array( |
| 284 | 'item_id' => 3, |
| 285 | 'item_parent_id' => 2, |
| 286 | 'user_id' => 0, |
| 287 | 'notification_read' => 0, |
| 288 | 'notification_time' => 1234, |
| 289 | 'notification_data' => array(), |
| 290 | ), |
| 291 | array( |
| 292 | 'item_id' => 1, |
| 293 | 'item_parent_id' => 2, |
| 294 | 'user_id' => 0, |
| 295 | 'notification_read' => 0, |
| 296 | 'notification_time' => 1349413321, |
| 297 | 'notification_data' => array(), |
| 298 | ), |
| 299 | array( |
| 300 | 'item_id' => 2, |
| 301 | 'item_parent_id' => 2, |
| 302 | 'user_id' => 0, |
| 303 | 'notification_read' => 0, |
| 304 | 'notification_time' => 1349413322, |
| 305 | 'notification_data' => array(), |
| 306 | ), |
| 307 | array( |
| 308 | 'item_id' => 4, |
| 309 | 'item_parent_id' => 2, |
| 310 | 'user_id' => 0, |
| 311 | 'notification_read' => 0, |
| 312 | 'notification_time' => 1349413324, |
| 313 | 'notification_data' => array( |
| 314 | 'poster_id' => 2, |
| 315 | 'topic_title' => 'test-title', |
| 316 | 'post_subject' => 'Re: test-title', |
| 317 | 'post_username' => '', |
| 318 | 'forum_id' => 2, |
| 319 | 'forum_name' => 'Your first forum', |
| 320 | ), |
| 321 | ), |
| 322 | array( |
| 323 | 'item_id' => 5, |
| 324 | 'item_parent_id' => 2, |
| 325 | 'user_id' => 0, |
| 326 | 'notification_read' => 0, |
| 327 | 'notification_time' => 1349413325, |
| 328 | 'notification_data' => array( |
| 329 | 'poster_id' => 2, |
| 330 | 'topic_title' => 'test-title2', |
| 331 | 'post_subject' => 'Re: test-title2', |
| 332 | 'post_username' => '', |
| 333 | 'forum_id' => 3, |
| 334 | 'forum_name' => 'Your second forum', |
| 335 | ), |
| 336 | ), |
| 337 | ) |
| 338 | ); |
| 339 | } |
| 340 | } |