aboutsummaryrefslogtreecommitdiffstats
path: root/tests/notification
diff options
context:
space:
mode:
Diffstat (limited to 'tests/notification')
-rw-r--r--tests/notification/base.php69
-rw-r--r--tests/notification/convert_test.php3
-rw-r--r--tests/notification/ext/test/notification/type/test.php5
-rw-r--r--tests/notification/fixtures/services_notification.yml76
-rw-r--r--tests/notification/fixtures/submit_post_notification.type.bookmark.xml12
-rw-r--r--tests/notification/fixtures/submit_post_notification.type.post.xml17
-rw-r--r--tests/notification/fixtures/submit_post_notification.type.post_in_queue.xml16
-rw-r--r--tests/notification/fixtures/submit_post_notification.type.quote.xml12
-rw-r--r--tests/notification/fixtures/submit_post_notification.type.topic.xml10
-rw-r--r--tests/notification/group_request_test.php25
-rw-r--r--tests/notification/manager_helper.php31
-rw-r--r--tests/notification/notification_test.php52
-rw-r--r--tests/notification/submit_post_base.php73
-rw-r--r--tests/notification/submit_post_type_quote_test.php39
-rw-r--r--tests/notification/submit_post_type_topic_test.php2
-rw-r--r--tests/notification/user_list_trim_test.php25
16 files changed, 302 insertions, 165 deletions
diff --git a/tests/notification/base.php b/tests/notification/base.php
index 162feae557..80b9a0d777 100644
--- a/tests/notification/base.php
+++ b/tests/notification/base.php
@@ -11,6 +11,10 @@
*
*/
+use Symfony\Component\Config\FileLocator;
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
+
require_once dirname(__FILE__) . '/manager_helper.php';
abstract class phpbb_tests_notification_base extends phpbb_database_test_case
@@ -39,6 +43,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,55 +66,83 @@ 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,
));
- $user = $this->user = new \phpbb\user('\phpbb\datetime');
+ $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
+ $lang = new \phpbb\language\language($lang_loader);
+ $user = new \phpbb\user($lang, '\phpbb\datetime');
+ $this->user = $user;
$this->user_loader = new \phpbb\user_loader($this->db, $phpbb_root_path, $phpEx, 'phpbb_users');
$auth = $this->auth = new phpbb_mock_notifications_auth();
+ $cache_driver = new \phpbb\cache\driver\dummy();
$cache = $this->cache = new \phpbb\cache\service(
- new \phpbb\cache\driver\null(),
+ $cache_driver,
$this->config,
$this->db,
$phpbb_root_path,
$phpEx
);
-
+
$this->phpbb_dispatcher = new phpbb_mock_event_dispatcher();
- $phpbb_container = $this->container = new phpbb_mock_container_builder();
+ $phpbb_container = $this->container = new ContainerBuilder();
+ $loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__ . '/fixtures'));
+ $loader->load('services_notification.yml');
+ $phpbb_container->set('user_loader', $this->user_loader);
+ $phpbb_container->set('user', $user);
+ $phpbb_container->set('language', $lang);
+ $phpbb_container->set('config', $this->config);
+ $phpbb_container->set('dbal.conn', $this->db);
+ $phpbb_container->set('auth', $auth);
+ $phpbb_container->set('cache.driver', $cache_driver);
+ $phpbb_container->set('cache', $cache);
+ $phpbb_container->set('text_formatter.utils', new \phpbb\textformatter\s9e\utils());
+ $phpbb_container->set('dispatcher', $this->phpbb_dispatcher);
+ $phpbb_container->setParameter('core.root_path', $phpbb_root_path);
+ $phpbb_container->setParameter('core.php_ext', $phpEx);
+ $phpbb_container->setParameter('tables.notifications', 'phpbb_notifications');
+ $phpbb_container->setParameter('tables.user_notifications', 'phpbb_user_notifications');
+ $phpbb_container->setParameter('tables.notification_types', 'phpbb_notification_types');
$this->notifications = new phpbb_notification_manager_helper(
array(),
array(),
$this->container,
$this->user_loader,
- $this->config,
$this->phpbb_dispatcher,
$this->db,
$this->cache,
+ $lang,
$this->user,
- $phpbb_root_path,
- $phpEx,
'phpbb_notification_types',
- 'phpbb_notifications',
'phpbb_user_notifications'
);
$phpbb_container->set('notification_manager', $this->notifications);
+ $phpbb_container->compile();
$this->notifications->setDependencies($this->auth, $this->config);
$types = array();
foreach ($this->get_notification_types() as $type)
{
- $type_parts = explode('.', $type);
- $class = $this->build_type('phpbb\notification\type\\' . array_pop($type_parts));
+ $class = $this->build_type($type);
$types[$type] = $class;
- $this->container->set($type, $class);
}
$this->notifications->set_var('notification_types', $types);
+ $methods = array();
+ foreach ($this->get_notification_methods() as $method)
+ {
+ $class = $this->container->get($method);
+
+ $methods[$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');
@@ -111,20 +150,20 @@ abstract class phpbb_tests_notification_base extends phpbb_database_test_case
protected function build_type($type)
{
- global $phpbb_root_path, $phpEx;
+ $instance = $this->container->get($type);
- return 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');
+ return $instance;
}
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',
), $options));
- $this->assertEquals(sizeof($expected), $notifications['unread_count']);
+ $this->assertEquals(count($expected), $notifications['unread_count']);
$i = 0;
foreach ($notifications['notifications'] as $notification)
diff --git a/tests/notification/convert_test.php b/tests/notification/convert_test.php
index 32ab34c9bc..4a7fd89409 100644
--- a/tests/notification/convert_test.php
+++ b/tests/notification/convert_test.php
@@ -28,11 +28,12 @@ class phpbb_notification_convert_test extends phpbb_database_test_case
global $phpbb_root_path, $phpEx;
$this->db = $this->new_dbal();
+ $factory = new \phpbb\db\tools\factory();
$this->migration = new \phpbb\db\migration\data\v310\notification_options_reconvert(
new \phpbb\config\config(array()),
$this->db,
- new \phpbb\db\tools($this->db),
+ $factory->get($this->db),
$phpbb_root_path,
$phpEx,
'phpbb_'
diff --git a/tests/notification/ext/test/notification/type/test.php b/tests/notification/ext/test/notification/type/test.php
index b02a563f06..7f3b4a4ef1 100644
--- a/tests/notification/ext/test/notification/type/test.php
+++ b/tests/notification/ext/test/notification/type/test.php
@@ -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(
diff --git a/tests/notification/fixtures/services_notification.yml b/tests/notification/fixtures/services_notification.yml
new file mode 100644
index 0000000000..6e68cccff6
--- /dev/null
+++ b/tests/notification/fixtures/services_notification.yml
@@ -0,0 +1,76 @@
+imports:
+ - { resource: ../../../phpBB/config/default/container/services_notification.yml }
+
+services:
+ notification_manager:
+ synthetic: true
+
+ user_loader:
+ synthetic: true
+
+ user:
+ synthetic: true
+
+ config:
+ synthetic: true
+
+ dbal.conn:
+ synthetic: true
+
+ language:
+ synthetic: true
+
+ auth:
+ synthetic: true
+
+ cache.driver:
+ synthetic: true
+
+ group_helper:
+ synthetic: true
+
+ path_helper:
+ synthetic: true
+
+ groupposition.legend:
+ synthetic: true
+
+ groupposition.teampage:
+ synthetic: true
+
+ groupposition.teampage:
+ synthetic: true
+
+ text_formatter.s9e.factory:
+ synthetic: true
+
+ text_formatter.s9e.quote_helper:
+ synthetic: true
+
+ text_formatter.parser:
+ synthetic: true
+
+ text_formatter.s9e.parser:
+ synthetic: true
+
+ text_formatter.renderer:
+ synthetic: true
+
+ text_formatter.s9e.renderer:
+ synthetic: true
+
+ text_formatter.utils:
+ synthetic: true
+
+ text_formatter.s9e.utils:
+ synthetic: true
+
+ text_formatter.data_access:
+ synthetic: true
+
+ test:
+ class: phpbb\notification\type\test
+ scope: prototype
+ parent: notification.type.base
+ tags:
+ - { name: notification.type }
diff --git a/tests/notification/fixtures/submit_post_notification.type.bookmark.xml b/tests/notification/fixtures/submit_post_notification.type.bookmark.xml
index a1413e2cf8..db1cef2ef6 100644
--- a/tests/notification/fixtures/submit_post_notification.type.bookmark.xml
+++ b/tests/notification/fixtures/submit_post_notification.type.bookmark.xml
@@ -29,6 +29,7 @@
</row>
</table>
<table name="phpbb_notifications">
+ <column>notification_id</column>
<column>notification_type_id</column>
<column>user_id</column>
<column>item_id</column>
@@ -37,6 +38,7 @@
<column>notification_data</column>
<row>
<value>1</value>
+ <value>1</value>
<value>5</value>
<value>1</value>
<value>1</value>
@@ -126,35 +128,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>
diff --git a/tests/notification/fixtures/submit_post_notification.type.post.xml b/tests/notification/fixtures/submit_post_notification.type.post.xml
index ed75787c70..920b271525 100644
--- a/tests/notification/fixtures/submit_post_notification.type.post.xml
+++ b/tests/notification/fixtures/submit_post_notification.type.post.xml
@@ -21,6 +21,7 @@
</row>
</table>
<table name="phpbb_notifications">
+ <column>notification_id</column>
<column>notification_type_id</column>
<column>user_id</column>
<column>item_id</column>
@@ -29,6 +30,7 @@
<column>notification_data</column>
<row>
<value>1</value>
+ <value>1</value>
<value>5</value>
<value>1</value>
<value>1</value>
@@ -36,6 +38,7 @@
<value></value>
</row>
<row>
+ <value>2</value>
<value>1</value>
<value>8</value>
<value>1</value>
@@ -156,49 +159,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>
diff --git a/tests/notification/fixtures/submit_post_notification.type.post_in_queue.xml b/tests/notification/fixtures/submit_post_notification.type.post_in_queue.xml
index 2dea8e34dd..12e73b0ff2 100644
--- a/tests/notification/fixtures/submit_post_notification.type.post_in_queue.xml
+++ b/tests/notification/fixtures/submit_post_notification.type.post_in_queue.xml
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<dataset>
<table name="phpbb_notifications">
+ <column>notification_id</column>
<column>notification_type_id</column>
<column>user_id</column>
<column>item_id</column>
@@ -9,6 +10,7 @@
<column>notification_data</column>
<row>
<value>1</value>
+ <value>1</value>
<value>6</value>
<value>1</value>
<value>1</value>
@@ -110,49 +112,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>
diff --git a/tests/notification/fixtures/submit_post_notification.type.quote.xml b/tests/notification/fixtures/submit_post_notification.type.quote.xml
index dd5bc620cd..9f4ba91475 100644
--- a/tests/notification/fixtures/submit_post_notification.type.quote.xml
+++ b/tests/notification/fixtures/submit_post_notification.type.quote.xml
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<dataset>
<table name="phpbb_notifications">
+ <column>notification_id</column>
<column>notification_type_id</column>
<column>user_id</column>
<column>item_id</column>
@@ -9,6 +10,7 @@
<column>notification_data</column>
<row>
<value>1</value>
+ <value>1</value>
<value>5</value>
<value>1</value>
<value>1</value>
@@ -98,35 +100,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>
diff --git a/tests/notification/fixtures/submit_post_notification.type.topic.xml b/tests/notification/fixtures/submit_post_notification.type.topic.xml
index 1ba8d05699..1f96ed2ee7 100644
--- a/tests/notification/fixtures/submit_post_notification.type.topic.xml
+++ b/tests/notification/fixtures/submit_post_notification.type.topic.xml
@@ -21,6 +21,7 @@
</row>
</table>
<table name="phpbb_notifications">
+ <column>notification_id</column>
<column>notification_type_id</column>
<column>user_id</column>
<column>item_id</column>
@@ -29,6 +30,7 @@
<column>notification_data</column>
<row>
<value>1</value>
+ <value>1</value>
<value>8</value>
<value>1</value>
<value>1</value>
@@ -106,28 +108,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>
diff --git a/tests/notification/group_request_test.php b/tests/notification/group_request_test.php
index 0d1bda95ce..e849c66fa5 100644
--- a/tests/notification/group_request_test.php
+++ b/tests/notification/group_request_test.php
@@ -12,7 +12,6 @@
*/
require_once dirname(__FILE__) . '/base.php';
-require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
class phpbb_notification_group_request_test extends phpbb_tests_notification_base
{
@@ -40,8 +39,6 @@ class phpbb_notification_group_request_test extends phpbb_tests_notification_bas
include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx);
include_once($phpbb_root_path . 'includes/functions_content.' . $phpEx);
- set_config(false, false, false, $this->config);
-
$this->container->set('groupposition.legend', new \phpbb\groupposition\legend(
$this->db,
$this->user
@@ -51,8 +48,28 @@ class phpbb_notification_group_request_test extends phpbb_tests_notification_bas
$this->user,
$this->cache->get_driver()
));
+ $this->container->set('group_helper', new \phpbb\group\helper(
+ $this->getMock('\phpbb\auth\auth'),
+ $this->cache,
+ $this->config,
+ new \phpbb\language\language(
+ new phpbb\language\language_file_loader($phpbb_root_path, $phpEx)
+ ),
+ new phpbb_mock_event_dispatcher(),
+ new \phpbb\path_helper(
+ new \phpbb\symfony_request(
+ new phpbb_mock_request()
+ ),
+ new \phpbb\filesystem\filesystem(),
+ $this->getMock('\phpbb\request\request'),
+ $phpbb_root_path,
+ $phpEx
+ ),
+ $this->user
+ ));
$phpbb_dispatcher = new phpbb_mock_event_dispatcher;
- $phpbb_log = new \phpbb\log\null();
+ $phpbb_log = new \phpbb\log\dummy();
+ $this->get_test_case_helpers()->set_s9e_services();
// Now on to the actual test
diff --git a/tests/notification/manager_helper.php b/tests/notification/manager_helper.php
index 75b7275d3a..2e8699e1e0 100644
--- a/tests/notification/manager_helper.php
+++ b/tests/notification/manager_helper.php
@@ -37,35 +37,4 @@ class phpbb_notification_manager_helper extends \phpbb\notification\manager
$this->auth = $auth;
$this->config = $config;
}
-
- /**
- * Helper to get the notifications item type class and set it up
- */
- public function get_item_type_class($item_type, $data = array())
- {
- $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->set_notification_manager($this);
-
- $item->set_initial_data($data);
-
- return $item;
- }
-
- /**
- * Helper to get the notifications method class and set it up
- */
- public function get_method_class($method_name)
- {
- $method_name = 'phpbb\notification\method\\' . $method_name;
-
- $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->set_notification_manager($this);
-
- return $method;
- }
}
diff --git a/tests/notification/notification_test.php b/tests/notification/notification_test.php
index 79fa5338c4..6bbabfc602 100644
--- a/tests/notification/notification_test.php
+++ b/tests/notification/notification_test.php
@@ -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,33 +72,33 @@ 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);
-
foreach ($expected_subscriptions as $item_type => $methods)
{
+ self::assertArrayHasKey($item_type, $subscriptions);
$this->assert_array_content_equals($methods, $subscriptions[$item_type]);
}
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()
@@ -108,7 +108,7 @@ class phpbb_notification_test extends phpbb_tests_notification_base
$types = array('notification.type.quote', 'notification.type.bookmark', 'notification.type.post', 'test');
foreach ($types as $id => $type)
{
- $this->db->sql_query('INSERT INTO phpbb_notification_types ' .
+ $this->getConnection()->createQueryTable('insertNotification', 'INSERT INTO phpbb_notification_types ' .
$this->db->sql_build_array('INSERT', array(
'notification_type_id' => ($id + 1),
'notification_type_name' => $type,
@@ -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,
)));
diff --git a/tests/notification/submit_post_base.php b/tests/notification/submit_post_base.php
index 5e770f71c9..21559c42a5 100644
--- a/tests/notification/submit_post_base.php
+++ b/tests/notification/submit_post_base.php
@@ -11,10 +11,11 @@
*
*/
-require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
-require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php';
+use Symfony\Component\Config\FileLocator;
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
+
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_posting.php';
-require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
abstract class phpbb_notification_submit_post_base extends phpbb_database_test_case
{
@@ -50,7 +51,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, $lang, $user, $request, $phpEx, $phpbb_root_path, $user_loader;
// Database
$this->db = $this->new_dbal();
@@ -69,12 +70,15 @@ 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,));
- set_config(null, null, null, $config);
- set_config_count(null, null, null, $config);
+ $config = new \phpbb\config\config(array(
+ 'num_topics' => 1,
+ 'num_posts' => 1,
+ 'allow_board_notifications' => true,
+ ));
+ $cache_driver = new \phpbb\cache\driver\dummy();
$cache = new \phpbb\cache\service(
- new \phpbb\cache\driver\null(),
+ $cache_driver,
$config,
$db,
$phpbb_root_path,
@@ -84,8 +88,14 @@ abstract class phpbb_notification_submit_post_base extends phpbb_database_test_c
// Event dispatcher
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+ // Language
+ $lang = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx));
+
// User
- $user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime'));
+ $user = $this->getMock('\phpbb\user', array(), array(
+ $lang,
+ '\phpbb\datetime'
+ ));
$user->ip = '';
$user->data = array(
'user_id' => 2,
@@ -98,34 +108,47 @@ abstract class phpbb_notification_submit_post_base extends phpbb_database_test_c
$type_cast_helper = $this->getMock('\phpbb\request\type_cast_helper_interface');
$request = $this->getMock('\phpbb\request\request');
- // Container
- $phpbb_container = new phpbb_mock_container_builder();
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
- $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));
-
$user_loader = new \phpbb\user_loader($db, $phpbb_root_path, $phpEx, USERS_TABLE);
+ // Container
+ $phpbb_container = new ContainerBuilder();
+ $loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__ . '/fixtures'));
+ $loader->load('services_notification.yml');
+ $phpbb_container->set('user_loader', $user_loader);
+ $phpbb_container->set('user', $user);
+ $phpbb_container->set('language', $lang);
+ $phpbb_container->set('config', $config);
+ $phpbb_container->set('dbal.conn', $db);
+ $phpbb_container->set('auth', $auth);
+ $phpbb_container->set('cache.driver', $cache_driver);
+ $phpbb_container->set('cache', $cache);
+ $phpbb_container->set('text_formatter.utils', new \phpbb\textformatter\s9e\utils());
+ $phpbb_container->set('dispatcher', $phpbb_dispatcher);
+ $phpbb_container->setParameter('core.root_path', $phpbb_root_path);
+ $phpbb_container->setParameter('core.php_ext', $phpEx);
+ $phpbb_container->setParameter('tables.notifications', 'phpbb_notifications');
+ $phpbb_container->setParameter('tables.user_notifications', 'phpbb_user_notifications');
+ $phpbb_container->setParameter('tables.notification_types', 'phpbb_notification_types');
+ $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));
+ $phpbb_container->compile();
+
// Notification Types
$notification_types = array('quote', 'bookmark', 'post', 'post_in_queue', 'topic', 'topic_in_queue', 'approve_topic', 'approve_post');
$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);
-
- $phpbb_container->set('notification.type.' . $type, $class);
-
+ $class = $phpbb_container->get('notification.type.' . $type);
$notification_types_array['notification.type.' . $type] = $class;
}
+ // Methods Types
+ $notification_methods_array = array('notification.method.board' => $phpbb_container->get('notification.method.board'));
+
// Notification Manager
- $phpbb_notifications = new \phpbb\notification\manager($notification_types_array, array(),
- $phpbb_container, $user_loader, $config, $phpbb_dispatcher, $db, $cache, $user,
- $phpbb_root_path, $phpEx,
- NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE);
+ $phpbb_notifications = new \phpbb\notification\manager($notification_types_array, $notification_methods_array,
+ $phpbb_container, $user_loader, $phpbb_dispatcher, $db, $cache, $lang, $user,
+ NOTIFICATION_TYPES_TABLE, USER_NOTIFICATIONS_TABLE);
$phpbb_container->set('notification_manager', $phpbb_notifications);
}
diff --git a/tests/notification/submit_post_type_quote_test.php b/tests/notification/submit_post_type_quote_test.php
index 61e3840773..3fab8c05ba 100644
--- a/tests/notification/submit_post_type_quote_test.php
+++ b/tests/notification/submit_post_type_quote_test.php
@@ -51,6 +51,9 @@ class phpbb_notification_submit_post_type_quote_test extends phpbb_notification_
*/
public function submit_post_data()
{
+ // The new mock container is needed because the data providers may be executed before phpunit call setUp()
+ $parser = $this->get_test_case_helpers()->set_s9e_services(new phpbb_mock_container_builder())->get('text_formatter.parser');
+
return array(
/**
* Normal post
@@ -65,15 +68,15 @@ class phpbb_notification_submit_post_type_quote_test extends phpbb_notification_
*/
array(
array(
- 'message' => implode(' ', array(
- '[quote=&quot;poster&quot;:uid]poster should not be notified[/quote:uid]',
- '[quote=&quot;test&quot;:uid]test should be notified[/quote:uid]',
- '[quote=&quot;unauthorized&quot;:uid]unauthorized to read, should not receive a notification[/quote:uid]',
- '[quote=&quot;notified&quot;:uid]already notified, should not receive a new notification[/quote:uid]',
- '[quote=&quot;disabled&quot;:uid]option disabled, should not receive a notification[/quote:uid]',
- '[quote=&quot;default&quot;:uid]option set to default, should receive a notification[/quote:uid]',
- '[quote=&quot;doesn\'t exist&quot;:uid]user does not exist, should not receive a notification[/quote:uid]',
- )),
+ 'message' => $parser->parse(implode(' ', array(
+ '[quote="poster"]poster should not be notified[/quote]',
+ '[quote="test"]test should be notified[/quote]',
+ '[quote="unauthorized"]unauthorized to read, should not receive a notification[/quote]',
+ '[quote="notified"]already notified, should not receive a new notification[/quote]',
+ '[quote="disabled"]option disabled, should not receive a notification[/quote]',
+ '[quote="default"]option set to default, should receive a notification[/quote]',
+ '[quote="doesn\'t exist"]user does not exist, should not receive a notification[/quote]',
+ ))),
'bbcode_uid' => 'uid',
),
array(
@@ -94,15 +97,15 @@ class phpbb_notification_submit_post_type_quote_test extends phpbb_notification_
*/
array(
array(
- 'message' => implode(' ', array(
- '[quote=&quot;poster&quot;:uid]poster should not be notified[/quote:uid]',
- '[quote=&quot;test&quot;:uid]test should be notified[/quote:uid]',
- '[quote=&quot;unauthorized&quot;:uid]unauthorized to read, should not receive a notification[/quote:uid]',
- '[quote=&quot;notified&quot;:uid]already notified, should not receive a new notification[/quote:uid]',
- '[quote=&quot;disabled&quot;:uid]option disabled, should not receive a notification[/quote:uid]',
- '[quote=&quot;default&quot;:uid]option set to default, should receive a notification[/quote:uid]',
- '[quote=&quot;doesn\'t exist&quot;:uid]user does not exist, should not receive a notification[/quote:uid]',
- )),
+ 'message' => $parser->parse(implode(' ', array(
+ '[quote="poster"]poster should not be notified[/quote]',
+ '[quote="test"]test should be notified[/quote]',
+ '[quote="unauthorized"]unauthorized to read, should not receive a notification[/quote]',
+ '[quote="notified"]already notified, should not receive a new notification[/quote]',
+ '[quote="disabled"]option disabled, should not receive a notification[/quote]',
+ '[quote="default"]option set to default, should receive a notification[/quote]',
+ '[quote="doesn\'t exist"]user does not exist, should not receive a notification[/quote]',
+ ))),
'bbcode_uid' => 'uid',
'force_approved_state' => false,
),
diff --git a/tests/notification/submit_post_type_topic_test.php b/tests/notification/submit_post_type_topic_test.php
index c095fbc4ba..f14f305517 100644
--- a/tests/notification/submit_post_type_topic_test.php
+++ b/tests/notification/submit_post_type_topic_test.php
@@ -42,7 +42,7 @@ class phpbb_notification_submit_post_type_topic_test extends phpbb_notification_
),
)));
- $phpbb_log = $this->getMock('\phpbb\log\null');
+ $phpbb_log = $this->getMock('\phpbb\log\dummy');
}
/**
diff --git a/tests/notification/user_list_trim_test.php b/tests/notification/user_list_trim_test.php
index c43eff729c..7d4dff6024 100644
--- a/tests/notification/user_list_trim_test.php
+++ b/tests/notification/user_list_trim_test.php
@@ -11,9 +11,6 @@
*
*/
-require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php';
-require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
-
class phpbb_notification_user_list_trim_test extends phpbb_database_test_case
{
protected $notification;
@@ -33,11 +30,9 @@ class phpbb_notification_user_list_trim_test extends phpbb_database_test_case
$db = $this->new_dbal();
$config = new \phpbb\config\config(array());
- set_config(null, null, null, $config);
- set_config_count(null, null, null, $config);
$cache = new \phpbb\cache\service(
- new \phpbb\cache\driver\null(),
+ new \phpbb\cache\driver\dummy(),
$config,
$db,
$phpbb_root_path,
@@ -53,15 +48,17 @@ class phpbb_notification_user_list_trim_test extends phpbb_database_test_case
array('u_viewprofile', 1, false),
)));
- $user = new \phpbb\user('\phpbb\datetime');
+ $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
+ $lang = new \phpbb\language\language($lang_loader);
+ $user = new \phpbb\user($lang, '\phpbb\datetime');
$user->data = array('user_lang' => 'en');
- $user->add_lang('common');
+ $lang->add_lang('common');
$user_loader = new phpbb\user_loader($db, $phpbb_root_path, $phpEx, USERS_TABLE);
$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, $lang, $user, null, null, $phpbb_root_path, $phpEx, null, null
);
}
@@ -73,7 +70,7 @@ class phpbb_notification_user_list_trim_test extends phpbb_database_test_case
'topic_title' => 'Test',
'poster_id' => 2,
'post_username' => 'A',
- 'responders' => null,
+ 'responders' => null,
),
'<strong>Reply</strong> from A in topic:',
),
@@ -84,7 +81,7 @@ class phpbb_notification_user_list_trim_test extends phpbb_database_test_case
'post_username' => 'A',
'responders' => array(
array('username' => '', 'poster_id' => 3),
- ),
+ ),
),
'<strong>Reply</strong> from A and <span class="username">B</span> in topic:',
),
@@ -96,7 +93,7 @@ class phpbb_notification_user_list_trim_test extends phpbb_database_test_case
'responders' => array(
array('username' => '', 'poster_id' => 3),
array('username' => '', 'poster_id' => 4),
- ),
+ ),
),
'<strong>Reply</strong> from A, <span class="username">B</span>, and <span class="username">C</span> in topic:',
),
@@ -109,7 +106,7 @@ class phpbb_notification_user_list_trim_test extends phpbb_database_test_case
array('username' => '', 'poster_id' => 3),
array('username' => '', 'poster_id' => 4),
array('username' => '', 'poster_id' => 5),
- ),
+ ),
),
'<strong>Reply</strong> from A, <span class="username">B</span>, <span class="username">C</span>, and <span class="username">D</span> in topic:',
),
@@ -123,7 +120,7 @@ class phpbb_notification_user_list_trim_test extends phpbb_database_test_case
array('username' => '', 'poster_id' => 4),
array('username' => '', 'poster_id' => 5),
array('username' => '', 'poster_id' => 6),
- ),
+ ),
),
'<strong>Reply</strong> from A, <span class="username">B</span>, <span class="username">C</span>, and 2 others in topic:',
),