Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
137 / 137 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| phpbb_tests_notification_base | |
100.00% |
137 / 137 |
|
100.00% |
5 / 5 |
9 | |
100.00% |
1 / 1 |
| get_notification_types | |
100.00% |
20 / 20 |
|
100.00% |
1 / 1 |
1 | |||
| get_notification_methods | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| setUp | |
100.00% |
101 / 101 |
|
100.00% |
1 / 1 |
3 | |||
| build_type | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| assert_notifications | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
3 | |||
| 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 | use Symfony\Component\Config\FileLocator; |
| 15 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
| 16 | use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
| 17 | |
| 18 | require_once __DIR__ . '/manager_helper.php'; |
| 19 | |
| 20 | abstract class phpbb_tests_notification_base extends phpbb_database_test_case |
| 21 | { |
| 22 | /** @var phpbb_notification_manager_helper */ |
| 23 | protected $notifications; |
| 24 | protected $db, $container, $user, $config, $auth, $cache, $user_loader, $phpbb_dispatcher; |
| 25 | |
| 26 | protected function get_notification_types() |
| 27 | { |
| 28 | return array( |
| 29 | 'test', |
| 30 | 'notification.type.approve_post', |
| 31 | 'notification.type.approve_topic', |
| 32 | 'notification.type.bookmark', |
| 33 | 'notification.type.disapprove_post', |
| 34 | 'notification.type.disapprove_topic', |
| 35 | 'notification.type.forum', |
| 36 | 'notification.type.mention', |
| 37 | 'notification.type.pm', |
| 38 | 'notification.type.post', |
| 39 | 'notification.type.post_in_queue', |
| 40 | 'notification.type.quote', |
| 41 | 'notification.type.report_pm', |
| 42 | 'notification.type.report_pm_closed', |
| 43 | 'notification.type.report_post', |
| 44 | 'notification.type.report_post_closed', |
| 45 | 'notification.type.topic', |
| 46 | 'notification.type.topic_in_queue', |
| 47 | ); |
| 48 | } |
| 49 | |
| 50 | protected function get_notification_methods() |
| 51 | { |
| 52 | return array( |
| 53 | 'notification.method.board', |
| 54 | ); |
| 55 | } |
| 56 | |
| 57 | protected function setUp(): void |
| 58 | { |
| 59 | parent::setUp(); |
| 60 | |
| 61 | global $phpbb_root_path, $phpEx; |
| 62 | |
| 63 | include_once(__DIR__ . '/ext/test/notification/type/test.' . $phpEx); |
| 64 | |
| 65 | global $db, $config, $user, $auth, $cache, $phpbb_container; |
| 66 | |
| 67 | $avatar_helper = $this->getMockBuilder('\phpbb\avatar\helper') |
| 68 | ->disableOriginalConstructor() |
| 69 | ->getMock(); |
| 70 | $db = $this->db = $this->new_dbal(); |
| 71 | $config = $this->config = new \phpbb\config\config(array( |
| 72 | 'allow_privmsg' => true, |
| 73 | 'allow_bookmarks' => true, |
| 74 | 'allow_topic_notify' => true, |
| 75 | 'allow_forum_notify' => true, |
| 76 | 'allow_board_notifications' => true, |
| 77 | 'allow_mentions' => true, |
| 78 | )); |
| 79 | $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); |
| 80 | $lang = new \phpbb\language\language($lang_loader); |
| 81 | $user = new \phpbb\user($lang, '\phpbb\datetime'); |
| 82 | $user->data['user_id'] = 0; |
| 83 | $user->data['user_type'] = USER_NORMAL; |
| 84 | $this->user = $user; |
| 85 | $this->user_loader = new \phpbb\user_loader($avatar_helper, $this->db, $phpbb_root_path, $phpEx, 'phpbb_users'); |
| 86 | $auth = $this->auth = new phpbb_mock_notifications_auth(); |
| 87 | $this->phpbb_dispatcher = new phpbb_mock_event_dispatcher(); |
| 88 | $cache_driver = new \phpbb\cache\driver\dummy(); |
| 89 | $cache = $this->cache = new \phpbb\cache\service( |
| 90 | $cache_driver, |
| 91 | $this->config, |
| 92 | $this->db, |
| 93 | $this->phpbb_dispatcher, |
| 94 | $phpbb_root_path, |
| 95 | $phpEx |
| 96 | ); |
| 97 | |
| 98 | $phpbb_container = $this->container = new ContainerBuilder(); |
| 99 | $loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__ . '/fixtures')); |
| 100 | $loader->load('services_notification.yml'); |
| 101 | $phpbb_container->set('avatar.helper', $avatar_helper); |
| 102 | $phpbb_container->set('user_loader', $this->user_loader); |
| 103 | $phpbb_container->set('user', $user); |
| 104 | $phpbb_container->set('language', $lang); |
| 105 | $phpbb_container->set('config', $this->config); |
| 106 | $phpbb_container->set('controller.helper', $this->createMock('\phpbb\controller\helper')); |
| 107 | $phpbb_container->set('dbal.conn', $this->db); |
| 108 | $phpbb_container->set('auth', $auth); |
| 109 | $phpbb_container->set('cache.driver', $cache_driver); |
| 110 | $phpbb_container->set('cache', $cache); |
| 111 | $phpbb_container->set('log', new \phpbb\log\dummy()); |
| 112 | $phpbb_container->set('text_formatter.utils', new \phpbb\textformatter\s9e\utils()); |
| 113 | $phpbb_container->set( |
| 114 | 'text_formatter.s9e.mention_helper', |
| 115 | new \phpbb\textformatter\s9e\mention_helper( |
| 116 | $this->db, |
| 117 | $auth, |
| 118 | $this->user, |
| 119 | $phpbb_root_path, |
| 120 | $phpEx |
| 121 | ) |
| 122 | ); |
| 123 | $phpbb_container->set('event_dispatcher', $this->phpbb_dispatcher); |
| 124 | $phpbb_container->setParameter('core.root_path', $phpbb_root_path); |
| 125 | $phpbb_container->setParameter('core.php_ext', $phpEx); |
| 126 | $phpbb_container->setParameter('tables.notifications', 'phpbb_notifications'); |
| 127 | $phpbb_container->setParameter('tables.user_notifications', 'phpbb_user_notifications'); |
| 128 | $phpbb_container->setParameter('tables.notification_types', 'phpbb_notification_types'); |
| 129 | $phpbb_container->setParameter('tables.notification_emails', 'phpbb_notification_emails'); |
| 130 | $phpbb_container->setParameter('tables.notification_push', 'phpbb_notification_push'); |
| 131 | $phpbb_container->setParameter('tables.push_subscriptions', 'phpbb_push_subscriptions'); |
| 132 | |
| 133 | $this->notifications = new phpbb_notification_manager_helper( |
| 134 | array(), |
| 135 | array(), |
| 136 | $this->container, |
| 137 | $this->user_loader, |
| 138 | $this->phpbb_dispatcher, |
| 139 | $this->db, |
| 140 | $this->cache, |
| 141 | $lang, |
| 142 | $this->user, |
| 143 | 'phpbb_notification_types', |
| 144 | 'phpbb_user_notifications' |
| 145 | ); |
| 146 | |
| 147 | $phpbb_container->set('notification_manager', $this->notifications); |
| 148 | |
| 149 | $phpbb_container->addCompilerPass(new phpbb\di\pass\markpublic_pass()); |
| 150 | |
| 151 | $messenger_method_collection = new \phpbb\di\service_collection($phpbb_container); |
| 152 | $messenger_method_collection->add('messenger.method.email'); |
| 153 | $phpbb_container->set('messenger.method_collection', $messenger_method_collection); |
| 154 | |
| 155 | $phpbb_container->compile(); |
| 156 | |
| 157 | $this->notifications->setDependencies($this->auth, $this->config); |
| 158 | |
| 159 | $types = array(); |
| 160 | foreach ($this->get_notification_types() as $type) |
| 161 | { |
| 162 | $class = $this->build_type($type); |
| 163 | |
| 164 | $types[$type] = $class; |
| 165 | } |
| 166 | |
| 167 | $this->notifications->set_var('notification_types', $types); |
| 168 | |
| 169 | $methods = array(); |
| 170 | foreach ($this->get_notification_methods() as $method) |
| 171 | { |
| 172 | $class = $this->container->get($method); |
| 173 | |
| 174 | $methods[$method] = $class; |
| 175 | } |
| 176 | |
| 177 | $this->notifications->set_var('notification_methods', $methods); |
| 178 | |
| 179 | $this->db->sql_query('DELETE FROM phpbb_notification_types'); |
| 180 | $this->db->sql_query('DELETE FROM phpbb_notifications'); |
| 181 | $this->db->sql_query('DELETE FROM phpbb_user_notifications'); |
| 182 | } |
| 183 | |
| 184 | protected function build_type($type) |
| 185 | { |
| 186 | $instance = $this->container->get($type); |
| 187 | |
| 188 | return $instance; |
| 189 | } |
| 190 | |
| 191 | protected function assert_notifications($expected, $options = array()) |
| 192 | { |
| 193 | $notifications = $this->notifications->load_notifications('notification.method.board', array_merge(array( |
| 194 | 'count_unread' => true, |
| 195 | 'order_by' => 'notification_time', |
| 196 | 'order_dir' => 'ASC', |
| 197 | ), $options)); |
| 198 | |
| 199 | $this->assertEquals(count($expected), $notifications['unread_count']); |
| 200 | |
| 201 | $i = 0; |
| 202 | foreach ($notifications['notifications'] as $notification) |
| 203 | { |
| 204 | foreach ($expected[$i] as $key => $value) |
| 205 | { |
| 206 | $this->assertEquals($value, $notification->$key, $i . ' ' . $key); |
| 207 | } |
| 208 | |
| 209 | $i++; |
| 210 | } |
| 211 | } |
| 212 | } |