Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
120 / 120 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| phpbb_notification_submit_post_base | |
100.00% |
120 / 120 |
|
100.00% |
3 / 3 |
5 | |
100.00% |
1 / 1 |
| getDataSet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setUp | |
100.00% |
102 / 102 |
|
100.00% |
1 / 1 |
2 | |||
| test_submit_post | |
100.00% |
17 / 17 |
|
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 | use Symfony\Component\Config\FileLocator; |
| 15 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
| 16 | use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
| 17 | |
| 18 | require_once __DIR__ . '/../../phpBB/includes/functions_posting.php'; |
| 19 | |
| 20 | abstract class phpbb_notification_submit_post_base extends phpbb_database_test_case |
| 21 | { |
| 22 | protected $db; |
| 23 | protected $item_type = ''; |
| 24 | |
| 25 | protected $poll_data = array(); |
| 26 | protected $post_data = array( |
| 27 | 'forum_id' => 1, |
| 28 | 'topic_id' => 1, |
| 29 | 'topic_title' => 'topic_title', |
| 30 | 'icon_id' => 0, |
| 31 | 'enable_bbcode' => 0, |
| 32 | 'enable_smilies' => 0, |
| 33 | 'enable_urls' => 0, |
| 34 | 'enable_sig' => 0, |
| 35 | 'message' => '', |
| 36 | 'message_md5' => '', |
| 37 | 'attachment_data' => array(), |
| 38 | 'bbcode_bitfield' => '', |
| 39 | 'bbcode_uid' => '', |
| 40 | 'post_edit_locked' => false, |
| 41 | 'notify_set' => 0, |
| 42 | 'notify' => false, |
| 43 | 'forum_name' => 'Test forum name', |
| 44 | //'force_approved_state' => 1, |
| 45 | ); |
| 46 | |
| 47 | public function getDataSet() |
| 48 | { |
| 49 | return $this->createXMLDataSet(__DIR__ . '/fixtures/submit_post_' . $this->item_type . '.xml'); |
| 50 | } |
| 51 | |
| 52 | protected function setUp(): void |
| 53 | { |
| 54 | global $auth, $cache, $config, $db, $phpbb_container, $phpbb_dispatcher, $lang, $user, $request, $phpEx, $phpbb_root_path, $user_loader, $phpbb_log; |
| 55 | |
| 56 | parent::setUp(); |
| 57 | |
| 58 | // Database |
| 59 | $this->db = $this->new_dbal(); |
| 60 | $db = $this->db; |
| 61 | |
| 62 | // Auth |
| 63 | $auth = $this->createMock('\phpbb\auth\auth'); |
| 64 | $auth->expects($this->any()) |
| 65 | ->method('acl_get') |
| 66 | ->with($this->stringContains('_'), |
| 67 | $this->anything()) |
| 68 | ->will($this->returnValueMap(array( |
| 69 | array('f_noapprove', 1, true), |
| 70 | array('f_postcount', 1, true), |
| 71 | array('m_edit', 1, false), |
| 72 | array('f_mention', 1, true), |
| 73 | array('u_mention', 0, true), |
| 74 | ))); |
| 75 | |
| 76 | // Config |
| 77 | $config = new \phpbb\config\config(array( |
| 78 | 'num_topics' => 1, |
| 79 | 'num_posts' => 1, |
| 80 | 'allow_board_notifications' => true, |
| 81 | 'allow_mentions' => true, |
| 82 | 'board_startdate' => 1692429414, |
| 83 | )); |
| 84 | |
| 85 | // Event dispatcher |
| 86 | $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); |
| 87 | |
| 88 | $cache_driver = new \phpbb\cache\driver\dummy(); |
| 89 | $cache = new \phpbb\cache\service( |
| 90 | $cache_driver, |
| 91 | $config, |
| 92 | $db, |
| 93 | $phpbb_dispatcher, |
| 94 | $phpbb_root_path, |
| 95 | $phpEx |
| 96 | ); |
| 97 | |
| 98 | // Language |
| 99 | $lang = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); |
| 100 | |
| 101 | // Storage |
| 102 | $storage = $this->createMock('\phpbb\storage\storage'); |
| 103 | |
| 104 | // User |
| 105 | $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); |
| 106 | $lang = new \phpbb\language\language($lang_loader); |
| 107 | $user = new \phpbb\user($lang, '\phpbb\datetime'); |
| 108 | $user->ip = ''; |
| 109 | $user->data['user_id'] = 2; |
| 110 | $user->data['username'] = 'user-name'; |
| 111 | $user->data['is_registered'] = true; |
| 112 | $user->data['user_colour'] = ''; |
| 113 | $user->data['user_lastmark'] = 0; |
| 114 | |
| 115 | // Request |
| 116 | $request = new phpbb_mock_request(); |
| 117 | |
| 118 | $avatar_helper = $this->getMockBuilder('\phpbb\avatar\helper') |
| 119 | ->disableOriginalConstructor() |
| 120 | ->getMock(); |
| 121 | |
| 122 | $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); |
| 123 | $user_loader = new \phpbb\user_loader($avatar_helper, $db, $phpbb_root_path, $phpEx, USERS_TABLE); |
| 124 | $phpbb_log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); |
| 125 | |
| 126 | // Container |
| 127 | $phpbb_container = new ContainerBuilder(); |
| 128 | $loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__ . '/fixtures')); |
| 129 | $loader->load('services_notification.yml'); |
| 130 | $phpbb_container->set('avatar.helper', $avatar_helper); |
| 131 | $phpbb_container->set('user_loader', $user_loader); |
| 132 | $phpbb_container->set('user', $user); |
| 133 | $phpbb_container->set('language', $lang); |
| 134 | $phpbb_container->set('config', $config); |
| 135 | $phpbb_container->set('dbal.conn', $db); |
| 136 | $phpbb_container->set('auth', $auth); |
| 137 | $phpbb_container->set('cache.driver', $cache_driver); |
| 138 | $phpbb_container->set('cache', $cache); |
| 139 | $phpbb_container->set('controller.helper', $this->createMock('\phpbb\controller\helper')); |
| 140 | $phpbb_container->set('log', new \phpbb\log\dummy()); |
| 141 | $phpbb_container->set('text_formatter.utils', new \phpbb\textformatter\s9e\utils()); |
| 142 | $phpbb_container->set( |
| 143 | 'text_formatter.s9e.mention_helper', |
| 144 | new \phpbb\textformatter\s9e\mention_helper( |
| 145 | $this->db, |
| 146 | $auth, |
| 147 | $user, |
| 148 | $phpbb_root_path, |
| 149 | $phpEx |
| 150 | ) |
| 151 | ); |
| 152 | $phpbb_container->set('event_dispatcher', $phpbb_dispatcher); |
| 153 | $phpbb_container->set('storage.attachment', $storage); |
| 154 | $phpbb_container->setParameter('core.root_path', $phpbb_root_path); |
| 155 | $phpbb_container->setParameter('core.php_ext', $phpEx); |
| 156 | $phpbb_container->setParameter('tables.notifications', 'phpbb_notifications'); |
| 157 | $phpbb_container->setParameter('tables.user_notifications', 'phpbb_user_notifications'); |
| 158 | $phpbb_container->setParameter('tables.notification_types', 'phpbb_notification_types'); |
| 159 | $phpbb_container->setParameter('tables.notification_emails', 'phpbb_notification_emails'); |
| 160 | $phpbb_container->setParameter('tables.notification_push', 'phpbb_notification_push'); |
| 161 | $phpbb_container->setParameter('tables.push_subscriptions', 'phpbb_push_subscriptions'); |
| 162 | $phpbb_container->set('content.visibility', new \phpbb\content_visibility($auth, $config, $phpbb_dispatcher, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE)); |
| 163 | |
| 164 | $messenger_method_collection = new \phpbb\di\service_collection($phpbb_container); |
| 165 | $messenger_method_collection->add('messenger.method.email'); |
| 166 | $phpbb_container->set('messenger.method_collection', $messenger_method_collection); |
| 167 | |
| 168 | $phpbb_container->addCompilerPass(new phpbb\di\pass\markpublic_pass()); |
| 169 | $phpbb_container->compile(); |
| 170 | |
| 171 | // Notification Types |
| 172 | $notification_types = array('quote', 'mention', 'bookmark', 'post', 'post_in_queue', 'topic', 'topic_in_queue', 'approve_topic', 'approve_post', 'forum'); |
| 173 | $notification_types_array = array(); |
| 174 | foreach ($notification_types as $type) |
| 175 | { |
| 176 | $class = $phpbb_container->get('notification.type.' . $type); |
| 177 | $notification_types_array['notification.type.' . $type] = $class; |
| 178 | } |
| 179 | |
| 180 | // Methods Types |
| 181 | $notification_methods_array = array('notification.method.board' => $phpbb_container->get('notification.method.board')); |
| 182 | |
| 183 | // Notification Manager |
| 184 | $phpbb_notifications = new \phpbb\notification\manager($notification_types_array, $notification_methods_array, |
| 185 | $phpbb_container, $user_loader, $phpbb_dispatcher, $db, $cache, $lang, $user, |
| 186 | NOTIFICATION_TYPES_TABLE, USER_NOTIFICATIONS_TABLE); |
| 187 | $phpbb_container->set('notification_manager', $phpbb_notifications); |
| 188 | } |
| 189 | |
| 190 | /** |
| 191 | * @dataProvider submit_post_data |
| 192 | */ |
| 193 | public function test_submit_post($additional_post_data, $expected_before, $expected_after) |
| 194 | { |
| 195 | global $db, $auth, $user, $config, $phpEx, $phpbb_root_path, $phpbb_container, $phpbb_dispatcher, $phpbb_log, $request; |
| 196 | |
| 197 | if (isset($additional_post_data['message'])) |
| 198 | { |
| 199 | $parser = $this->get_test_case_helpers()->set_s9e_services($phpbb_container)->get('text_formatter.parser'); |
| 200 | $additional_post_data['message'] = $parser->parse($additional_post_data['message']); |
| 201 | } |
| 202 | |
| 203 | $sql = 'SELECT user_id, item_id, item_parent_id |
| 204 | FROM ' . NOTIFICATIONS_TABLE . ' n, ' . NOTIFICATION_TYPES_TABLE . " nt |
| 205 | WHERE nt.notification_type_name = '" . $this->item_type . "' |
| 206 | AND n.notification_type_id = nt.notification_type_id |
| 207 | ORDER BY user_id ASC, item_id ASC"; |
| 208 | $result = $this->db->sql_query($sql); |
| 209 | $this->assertEquals($expected_before, $this->db->sql_fetchrowset($result)); |
| 210 | $this->db->sql_freeresult($result); |
| 211 | |
| 212 | $poll_data = $this->poll_data; |
| 213 | $post_data = array_merge($this->post_data, $additional_post_data); |
| 214 | submit_post('reply', '', 'poster-name', POST_NORMAL, $poll_data, $post_data, false, false); |
| 215 | |
| 216 | $result = $this->db->sql_query($sql); |
| 217 | $this->assertEquals($expected_after, $this->db->sql_fetchrowset($result)); |
| 218 | $this->db->sql_freeresult($result); |
| 219 | } |
| 220 | } |