aboutsummaryrefslogtreecommitdiffstats
path: root/tests/notification/base.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/notification/base.php')
-rw-r--r--tests/notification/base.php107
1 files changed, 77 insertions, 30 deletions
diff --git a/tests/notification/base.php b/tests/notification/base.php
index f6333866c3..b64e25cf8c 100644
--- a/tests/notification/base.php
+++ b/tests/notification/base.php
@@ -1,12 +1,20 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2013 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
*
*/
+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
@@ -17,21 +25,28 @@ abstract class phpbb_tests_notification_base extends phpbb_database_test_case
{
return array(
'test',
- 'approve_post',
- 'approve_topic',
- 'bookmark',
- 'disapprove_post',
- 'disapprove_topic',
- 'pm',
- 'post',
- 'post_in_queue',
- 'quote',
- 'report_pm',
- 'report_pm_closed',
- 'report_post',
- 'report_post_closed',
- 'topic',
- 'topic_in_queue',
+ 'notification.type.approve_post',
+ 'notification.type.approve_topic',
+ 'notification.type.bookmark',
+ 'notification.type.disapprove_post',
+ 'notification.type.disapprove_topic',
+ 'notification.type.pm',
+ 'notification.type.post',
+ 'notification.type.post_in_queue',
+ 'notification.type.quote',
+ 'notification.type.report_pm',
+ 'notification.type.report_pm_closed',
+ 'notification.type.report_post',
+ 'notification.type.report_post_closed',
+ 'notification.type.topic',
+ 'notification.type.topic_in_queue',
+ );
+ }
+
+ protected function get_notification_methods()
+ {
+ return array(
+ 'notification.method.board',
);
}
@@ -51,51 +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();
+ $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
);
- $phpbb_container = $this->container = new phpbb_mock_container_builder();
+ $this->phpbb_dispatcher = new phpbb_mock_event_dispatcher();
+
+ $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)
{
- $class = $this->build_type('phpbb\notification\type\\' . $type);
+ $class = $this->build_type($type);
$types[$type] = $class;
- $this->container->set('notification.type.' . $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');
@@ -103,14 +150,14 @@ 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',