1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-30 21:40:43 +02:00

[ticket/11444] Moving the in-board notifications to a method class

Currently the in-board method for the notifications is hardcoded and
cannot be disabled. This method should be in his own class extending
`phpbb\notification\method\method_interface`.

It also add the possibility, for each method, to be enabled by default (ie:
no entry in the DB => notification enabled).

https://tracker.phpbb.com/browse/PHPBB3-11444
https://tracker.phpbb.com/browse/PHPBB3-11967

PHPBB3-11444
This commit is contained in:
Nicofuma
2014-04-28 14:00:27 +02:00
committed by Tristan Darricau
parent 58d1d37c16
commit be0d4e20d4
55 changed files with 1229 additions and 609 deletions

View File

@@ -39,6 +39,13 @@ abstract class phpbb_tests_notification_base extends phpbb_database_test_case
);
}
protected function get_notification_methods()
{
return array(
'notification.method.board',
);
}
protected function setUp()
{
parent::setUp();
@@ -55,6 +62,7 @@ abstract class phpbb_tests_notification_base extends phpbb_database_test_case
'allow_bookmarks' => true,
'allow_topic_notify' => true,
'allow_forum_notify' => true,
'allow_board_notifications' => true,
));
$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
$lang = new \phpbb\language\language($lang_loader);
@@ -87,7 +95,6 @@ abstract class phpbb_tests_notification_base extends phpbb_database_test_case
$phpbb_root_path,
$phpEx,
'phpbb_notification_types',
'phpbb_notifications',
'phpbb_user_notifications'
);
@@ -107,6 +114,18 @@ abstract class phpbb_tests_notification_base extends phpbb_database_test_case
$this->notifications->set_var('notification_types', $types);
$methods = array();
foreach ($this->get_notification_methods() as $method)
{
$method_parts = explode('.', $method);
$class = $this->build_type('phpbb\notification\method\\' . array_pop($method_parts));
$methods[$method] = $class;
$this->container->set($method, $class);
}
$this->notifications->set_var('notification_methods', $methods);
$this->db->sql_query('DELETE FROM phpbb_notification_types');
$this->db->sql_query('DELETE FROM phpbb_notifications');
$this->db->sql_query('DELETE FROM phpbb_user_notifications');
@@ -116,7 +135,7 @@ abstract class phpbb_tests_notification_base extends phpbb_database_test_case
{
global $phpbb_root_path, $phpEx;
$instance = new $type($this->user_loader, $this->db, $this->cache->get_driver(), $this->user, $this->auth, $this->config, $phpbb_root_path, $phpEx, 'phpbb_notification_types', 'phpbb_notifications', 'phpbb_user_notifications');
$instance = new $type($this->user_loader, $this->db, $this->cache->get_driver(), $this->user, $this->auth, $this->config, $phpbb_root_path, $phpEx, 'phpbb_notification_types', 'phpbb_user_notifications');
if ($type === 'phpbb\\notification\\type\\quote')
{
@@ -126,9 +145,17 @@ abstract class phpbb_tests_notification_base extends phpbb_database_test_case
return $instance;
}
protected function build_method($method)
{
global $phpbb_root_path, $phpEx;
return new $method($this->user_loader, $this->db, $this->cache->get_driver(), $this->user, $this->auth, $this->config,
$phpbb_root_path, $phpEx, 'phpbb_notification_types', 'phpbb_notifications', 'phpbb_user_notifications');
}
protected function assert_notifications($expected, $options = array())
{
$notifications = $this->notifications->load_notifications(array_merge(array(
$notifications = $this->notifications->load_notifications('notification.method.board', array_merge(array(
'count_unread' => true,
'order_by' => 'notification_time',
'order_dir' => 'ASC',

View File

@@ -47,12 +47,13 @@ class test extends \phpbb\notification\type\base
{
$this->notification_time = $post['post_time'];
return parent::create_insert_array($post, $pre_create_data);
parent::create_insert_array($post, $pre_create_data);
}
public function create_update_array($type_data)
{
$data = $this->create_insert_array($type_data);
$this->create_insert_array($type_data);
$data = $this->get_insert_array();
// Unset data unique to each row
unset(

View File

@@ -126,35 +126,35 @@
<value>notification.type.bookmark</value>
<value>0</value>
<value>2</value>
<value></value>
<value>notification.method.board</value>
<value>1</value>
</row>
<row>
<value>notification.type.bookmark</value>
<value>0</value>
<value>3</value>
<value></value>
<value>notification.method.board</value>
<value>1</value>
</row>
<row>
<value>notification.type.bookmark</value>
<value>0</value>
<value>4</value>
<value></value>
<value>notification.method.board</value>
<value>1</value>
</row>
<row>
<value>notification.type.bookmark</value>
<value>0</value>
<value>5</value>
<value></value>
<value>notification.method.board</value>
<value>1</value>
</row>
<row>
<value>notification.type.bookmark</value>
<value>0</value>
<value>6</value>
<value></value>
<value>notification.method.board</value>
<value>0</value>
</row>
</table>

View File

@@ -156,49 +156,49 @@
<value>notification.type.post</value>
<value>0</value>
<value>2</value>
<value></value>
<value>notification.method.board</value>
<value>1</value>
</row>
<row>
<value>notification.type.post</value>
<value>0</value>
<value>3</value>
<value></value>
<value>notification.method.board</value>
<value>1</value>
</row>
<row>
<value>notification.type.post</value>
<value>0</value>
<value>4</value>
<value></value>
<value>notification.method.board</value>
<value>1</value>
</row>
<row>
<value>notification.type.post</value>
<value>0</value>
<value>5</value>
<value></value>
<value>notification.method.board</value>
<value>1</value>
</row>
<row>
<value>notification.type.post</value>
<value>0</value>
<value>6</value>
<value></value>
<value>notification.method.board</value>
<value>1</value>
</row>
<row>
<value>notification.type.post</value>
<value>0</value>
<value>7</value>
<value></value>
<value>notification.method.board</value>
<value>1</value>
</row>
<row>
<value>notification.type.post</value>
<value>0</value>
<value>8</value>
<value></value>
<value>notification.method.board</value>
<value>1</value>
</row>
</table>

View File

@@ -110,49 +110,49 @@
<value>notification.type.needs_approval</value>
<value>0</value>
<value>2</value>
<value></value>
<value>notification.method.board</value>
<value>1</value>
</row>
<row>
<value>notification.type.needs_approval</value>
<value>0</value>
<value>3</value>
<value></value>
<value>notification.method.board</value>
<value>1</value>
</row>
<row>
<value>notification.type.needs_approval</value>
<value>0</value>
<value>4</value>
<value></value>
<value>notification.method.board</value>
<value>1</value>
</row>
<row>
<value>notification.type.needs_approval</value>
<value>0</value>
<value>5</value>
<value></value>
<value>notification.method.board</value>
<value>1</value>
</row>
<row>
<value>notification.type.needs_approval</value>
<value>0</value>
<value>6</value>
<value></value>
<value>notification.method.board</value>
<value>1</value>
</row>
<row>
<value>notification.type.needs_approval</value>
<value>0</value>
<value>7</value>
<value></value>
<value>notification.method.board</value>
<value>0</value>
</row>
<row>
<value>notification.type.needs_approval</value>
<value>0</value>
<value>9</value>
<value></value>
<value>notification.method.board</value>
<value>1</value>
</row>
</table>

View File

@@ -98,35 +98,35 @@
<value>notification.type.quote</value>
<value>0</value>
<value>2</value>
<value></value>
<value>notification.method.board</value>
<value>1</value>
</row>
<row>
<value>notification.type.quote</value>
<value>0</value>
<value>3</value>
<value></value>
<value>notification.method.board</value>
<value>1</value>
</row>
<row>
<value>notification.type.quote</value>
<value>0</value>
<value>4</value>
<value></value>
<value>notification.method.board</value>
<value>1</value>
</row>
<row>
<value>notification.type.quote</value>
<value>0</value>
<value>5</value>
<value></value>
<value>notification.method.board</value>
<value>1</value>
</row>
<row>
<value>notification.type.quote</value>
<value>0</value>
<value>6</value>
<value></value>
<value>notification.method.board</value>
<value>0</value>
</row>
</table>

View File

@@ -106,28 +106,28 @@
<value>notification.type.topic</value>
<value>0</value>
<value>2</value>
<value></value>
<value>notification.method.board</value>
<value>1</value>
</row>
<row>
<value>notification.type.topic</value>
<value>0</value>
<value>6</value>
<value></value>
<value>notification.method.board</value>
<value>1</value>
</row>
<row>
<value>notification.type.topic</value>
<value>0</value>
<value>7</value>
<value></value>
<value>notification.method.board</value>
<value>1</value>
</row>
<row>
<value>notification.type.topic</value>
<value>0</value>
<value>8</value>
<value></value>
<value>notification.method.board</value>
<value>1</value>
</row>
</table>

View File

@@ -46,7 +46,7 @@ class phpbb_notification_manager_helper extends \phpbb\notification\manager
$item_parts = explode('.', $item_type);
$item_type = 'phpbb\notification\type\\' . array_pop($item_parts);
$item = new $item_type($this->user_loader, $this->db, $this->cache->get_driver(), $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notification_types_table, $this->notifications_table, $this->user_notifications_table);
$item = new $item_type($this->user_loader, $this->db, $this->cache->get_driver(), $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notification_types_table, $this->user_notifications_table);
if ($item_type === 'phpbb\\notification\\type\\quote')
{
@@ -65,9 +65,10 @@ class phpbb_notification_manager_helper extends \phpbb\notification\manager
*/
public function get_method_class($method_name)
{
$method_name = 'phpbb\notification\method\\' . $method_name;
$method_parts = explode('.', $method_name);
$method_name = 'phpbb\notification\method\\' . array_pop($method_parts);
$method = new $method_name($this->user_loader, $this->db, $this->cache->get_driver(), $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notification_types_table, $this->notifications_table, $this->user_notifications_table);
$method = new $method_name($this->user_loader, $this->db, $this->cache->get_driver(), $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notification_types_table, NOTIFICATIONS_TABLE, $this->user_notifications_table);
$method->set_notification_manager($this);

View File

@@ -29,7 +29,7 @@ class phpbb_notification_test extends phpbb_tests_notification_base
$quote_type_id = $this->notifications->get_notification_type_id('notification.type.quote');
$test_type_id = $this->notifications->get_notification_type_id('test');
$this->assertEquals(array(
self::assertEquals(array(
'test' => $test_type_id,
'notification.type.quote' => $quote_type_id,
'notification.type.post' => $post_type_id,
@@ -40,13 +40,13 @@ class phpbb_notification_test extends phpbb_tests_notification_base
'notification.type.post',
)
));
$this->assertEquals($quote_type_id, $this->notifications->get_notification_type_id('notification.type.quote'));
self::assertEquals($quote_type_id, $this->notifications->get_notification_type_id('notification.type.quote'));
try
{
$this->assertEquals(false, $this->notifications->get_notification_type_id('fail'));
self::assertEquals(false, $this->notifications->get_notification_type_id('fail'));
$this->fail('Non-existent type should throw an exception');
self::fail('Non-existent type should throw an exception');
}
catch (Exception $e) {}
}
@@ -55,15 +55,15 @@ class phpbb_notification_test extends phpbb_tests_notification_base
{
$subscription_types = $this->notifications->get_subscription_types();
$this->assertArrayHasKey('NOTIFICATION_GROUP_MISCELLANEOUS', $subscription_types);
$this->assertArrayHasKey('NOTIFICATION_GROUP_POSTING', $subscription_types);
self::assertArrayHasKey('NOTIFICATION_GROUP_MISCELLANEOUS', $subscription_types);
self::assertArrayHasKey('NOTIFICATION_GROUP_POSTING', $subscription_types);
$this->assertArrayHasKey('notification.type.bookmark', $subscription_types['NOTIFICATION_GROUP_POSTING']);
$this->assertArrayHasKey('notification.type.post', $subscription_types['NOTIFICATION_GROUP_POSTING']);
$this->assertArrayHasKey('notification.type.quote', $subscription_types['NOTIFICATION_GROUP_POSTING']);
$this->assertArrayHasKey('notification.type.topic', $subscription_types['NOTIFICATION_GROUP_POSTING']);
self::assertArrayHasKey('notification.type.bookmark', $subscription_types['NOTIFICATION_GROUP_POSTING']);
self::assertArrayHasKey('notification.type.post', $subscription_types['NOTIFICATION_GROUP_POSTING']);
self::assertArrayHasKey('notification.type.quote', $subscription_types['NOTIFICATION_GROUP_POSTING']);
self::assertArrayHasKey('notification.type.topic', $subscription_types['NOTIFICATION_GROUP_POSTING']);
$this->assertArrayHasKey('notification.type.pm', $subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']);
self::assertArrayHasKey('notification.type.pm', $subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']);
//get_subscription_types
//get_subscription_methods
@@ -72,12 +72,12 @@ class phpbb_notification_test extends phpbb_tests_notification_base
public function test_subscriptions()
{
$expected_subscriptions = array(
'notification.type.post' => array(''),
'notification.type.topic' => array(''),
'notification.type.quote' => array(''),
'notification.type.bookmark' => array(''),
'test' => array(''),
'notification.type.pm' => array(''),
'notification.type.post' => array('notification.method.board'),
'notification.type.topic' => array('notification.method.board'),
'notification.type.quote' => array('notification.method.board'),
'notification.type.bookmark' => array('notification.method.board'),
'test' => array('notification.method.board'),
'notification.type.pm' => array('notification.method.board'),
);
$subscriptions = $this->notifications->get_global_subscriptions(2);
@@ -89,16 +89,16 @@ class phpbb_notification_test extends phpbb_tests_notification_base
foreach ($subscriptions as $item_type => $methods)
{
$this->assert_array_content_equals($methods, $expected_subscriptions[$item_type]);
$this->assert_array_content_equals($methods, $expected_subscriptions[$item_type]);
}
$this->notifications->delete_subscription('notification.type.post', 0, '', 2);
$this->notifications->delete_subscription('notification.type.post', 0, 'notification.method.board', 2);
$this->assertArrayNotHasKey('notification.type.post', $this->notifications->get_global_subscriptions(2));
self::assertArrayNotHasKey('notification.type.post', $this->notifications->get_global_subscriptions(2));
$this->notifications->add_subscription('notification.type.post', 0, '', 2);
$this->notifications->add_subscription('notification.type.post', 0, 'notification.method.board', 2);
$this->assertArrayHasKey('notification.type.post', $this->notifications->get_global_subscriptions(2));
self::assertArrayHasKey('notification.type.post', $this->notifications->get_global_subscriptions(2));
}
public function test_notifications()
@@ -124,11 +124,11 @@ class phpbb_notification_test extends phpbb_tests_notification_base
'user_id' => 0,
)));
$this->assertEquals(array(
self::assertEquals(array(
'notifications' => array(),
'unread_count' => 0,
'total_count' => 0,
), $this->notifications->load_notifications(array(
), $this->notifications->load_notifications('notification.method.board', array(
'count_unread' => true,
)));

View File

@@ -50,7 +50,7 @@ abstract class phpbb_notification_submit_post_base extends phpbb_database_test_c
{
parent::setUp();
global $auth, $cache, $config, $db, $phpbb_container, $phpbb_dispatcher, $user, $request, $phpEx, $phpbb_root_path;
global $auth, $cache, $config, $db, $phpbb_container, $phpbb_dispatcher, $user, $request, $phpEx, $phpbb_root_path, $user_loader;
// Database
$this->db = $this->new_dbal();
@@ -69,7 +69,11 @@ abstract class phpbb_notification_submit_post_base extends phpbb_database_test_c
)));
// Config
$config = new \phpbb\config\config(array('num_topics' => 1,'num_posts' => 1,));
$config = new \phpbb\config\config(array(
'num_topics' => 1,
'num_posts' => 1,
'allow_board_notifications' => true,
));
$cache = new \phpbb\cache\service(
new \phpbb\cache\driver\dummy(),
@@ -111,30 +115,46 @@ abstract class phpbb_notification_submit_post_base extends phpbb_database_test_c
$notification_types_array = array();
foreach ($notification_types as $type)
{
$class_name = '\phpbb\notification\type\\' . $type;
$class = new $class_name(
$user_loader, $db, $cache->get_driver(), $user, $auth, $config,
$phpbb_root_path, $phpEx,
NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE);
if ($type === 'quote')
{
$class->set_utils(new \phpbb\textformatter\s9e\utils);
}
$phpbb_container->set('notification.type.' . $type, $class);
$class = $this->build_type($type);
$phpbb_container->set('notification.type.' . $type, array(array($this, 'build_type'), array($type)));
$notification_types_array['notification.type.' . $type] = $class;
}
// Methods Types
$class_name = 'phpbb\notification\method\board';
$class = new $class_name(
$user_loader, $db, $cache->get_driver(), $user, $auth, $config,
$phpbb_root_path, $phpEx,
NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE);
$phpbb_container->set('notification.method.board', $class);
$notification_methods_array = array('notification.method.board' => $class);
// Notification Manager
$phpbb_notifications = new \phpbb\notification\manager($notification_types_array, array(),
$phpbb_notifications = new \phpbb\notification\manager($notification_types_array, $notification_methods_array,
$phpbb_container, $user_loader, $config, $phpbb_dispatcher, $db, $cache, $user,
$phpbb_root_path, $phpEx,
NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE);
NOTIFICATION_TYPES_TABLE, USER_NOTIFICATIONS_TABLE);
$phpbb_container->set('notification_manager', $phpbb_notifications);
}
public function build_type($type)
{
global $auth, $cache, $config, $db, $phpbb_container, $phpbb_dispatcher, $user, $request, $phpEx, $phpbb_root_path, $user_loader;
$class_name = '\phpbb\notification\type\\' . $type;
$class = new $class_name(
$user_loader, $db, $cache->get_driver(), $user, $auth, $config,
$phpbb_root_path, $phpEx,
NOTIFICATION_TYPES_TABLE, USER_NOTIFICATIONS_TABLE);
if ($type === 'quote')
{
$class->set_utils(new \phpbb\textformatter\s9e\utils);
}
return $class;
}
/**
* @dataProvider submit_post_data
*/
@@ -157,4 +177,11 @@ abstract class phpbb_notification_submit_post_base extends phpbb_database_test_c
$this->assertEquals($expected_after, $this->db->sql_fetchrowset($result));
$this->db->sql_freeresult($result);
}
protected function build_method($method)
{
global $phpbb_root_path, $phpEx;
return new $method($this->user_loader, $this->db, $this->cache->get_driver(), $this->user, $this->auth, $this->config, $phpbb_root_path, $phpEx, 'phpbb_notification_types', 'phpbb_notifications', 'phpbb_user_notifications');
}
}

View File

@@ -61,7 +61,7 @@ class phpbb_notification_user_list_trim_test extends phpbb_database_test_case
$user_loader->load_users(array(2, 3, 4, 5, 6));
$this->notification = new phpbb_mock_notification_type_post(
$user_loader, null, null, $user, null, null, $phpbb_root_path, $phpEx, null, null, null
$user_loader, null, null, $user, null, null, $phpbb_root_path, $phpEx, null, null
);
}