diff options
author | Tristan Darricau <tristan.darricau@sensiolabs.com> | 2015-07-09 17:04:40 +0200 |
---|---|---|
committer | Tristan Darricau <tristan.darricau@sensiolabs.com> | 2015-07-13 22:41:14 +0200 |
commit | fc34057f288c6b8c656a0ed1ac2cb5a86f86206d (patch) | |
tree | e1fead9c675d649708d7540c3d6e4bbf9d97abd2 | |
parent | f29b12e35397ef4a4996ea7d212f0ab5a7a1dba6 (diff) | |
download | forums-fc34057f288c6b8c656a0ed1ac2cb5a86f86206d.tar forums-fc34057f288c6b8c656a0ed1ac2cb5a86f86206d.tar.gz forums-fc34057f288c6b8c656a0ed1ac2cb5a86f86206d.tar.bz2 forums-fc34057f288c6b8c656a0ed1ac2cb5a86f86206d.tar.xz forums-fc34057f288c6b8c656a0ed1ac2cb5a86f86206d.zip |
[ticket/11444] Update tests and cleanup types/methods
PHPBB3-11444
-rw-r--r-- | phpBB/config/default/container/services_notification.yml | 246 | ||||
-rw-r--r-- | phpBB/phpbb/notification/manager.php | 26 | ||||
-rw-r--r-- | phpBB/phpbb/notification/type/admin_activate_user.php | 16 | ||||
-rw-r--r-- | phpBB/phpbb/notification/type/base.php | 25 | ||||
-rw-r--r-- | phpBB/phpbb/notification/type/bookmark.php | 9 | ||||
-rw-r--r-- | phpBB/phpbb/notification/type/group_request.php | 8 | ||||
-rw-r--r-- | phpBB/phpbb/notification/type/pm.php | 16 | ||||
-rw-r--r-- | phpBB/phpbb/notification/type/post.php | 17 | ||||
-rw-r--r-- | phpBB/phpbb/notification/type/report_pm.php | 2 | ||||
-rw-r--r-- | phpBB/phpbb/notification/type/topic.php | 16 | ||||
-rw-r--r-- | tests/mock/container_builder.php | 5 | ||||
-rw-r--r-- | tests/notification/base.php | 54 | ||||
-rw-r--r-- | tests/notification/fixtures/services_notification.yml | 70 | ||||
-rw-r--r-- | tests/notification/manager_helper.php | 37 | ||||
-rw-r--r-- | tests/notification/notification_test.php | 2 | ||||
-rw-r--r-- | tests/notification/submit_post_base.php | 71 | ||||
-rw-r--r-- | tests/notification/submit_post_type_quote_test.php | 3 | ||||
-rw-r--r-- | tests/test_framework/phpbb_test_case_helpers.php | 34 |
18 files changed, 305 insertions, 352 deletions
diff --git a/phpBB/config/default/container/services_notification.yml b/phpBB/config/default/container/services_notification.yml index 264ed1dbb9..f82dd4b5a5 100644 --- a/phpBB/config/default/container/services_notification.yml +++ b/phpBB/config/default/container/services_notification.yml @@ -22,190 +22,110 @@ services: tags: - { name: service_collection, tag: notification.type } - notification.type.approve_post: - class: phpbb\notification\type\approve_post - scope: prototype + notification.type.base: + abstract: true arguments: - - @user_loader - @dbal.conn - - @cache.driver - @user - @auth - - @config - %core.root_path% - %core.php_ext% - - %tables.notification_types% - %tables.user_notifications% + + notification.type.admin_activate_user: + class: phpbb\notification\type\admin_activate_user + scope: prototype + parent: notification.type.base + calls: + - [set_user_loader, ["@user_loader"]] + - [set_config, ["@config"]] + tags: + - { name: notification.type } + + notification.type.approve_post: + class: phpbb\notification\type\approve_post + scope: prototype + parent: notification.type.base tags: - { name: notification.type } notification.type.approve_topic: class: phpbb\notification\type\approve_topic scope: prototype - arguments: - - @user_loader - - @dbal.conn - - @cache.driver - - @user - - @auth - - @config - - %core.root_path% - - %core.php_ext% - - %tables.notification_types% - - %tables.user_notifications% + parent: notification.type.base tags: - { name: notification.type } notification.type.bookmark: class: phpbb\notification\type\bookmark scope: prototype - arguments: - - @user_loader - - @dbal.conn - - @cache.driver - - @user - - @auth - - @config - - %core.root_path% - - %core.php_ext% - - %tables.notification_types% - - %tables.user_notifications% + parent: notification.type.base + calls: + - [set_config, ["@config"]] tags: - { name: notification.type } notification.type.disapprove_post: class: phpbb\notification\type\disapprove_post scope: prototype - arguments: - - @user_loader - - @dbal.conn - - @cache.driver - - @user - - @auth - - @config - - %core.root_path% - - %core.php_ext% - - %tables.notification_types% - - %tables.user_notifications% + parent: notification.type.base tags: - { name: notification.type } notification.type.disapprove_topic: class: phpbb\notification\type\disapprove_topic scope: prototype - arguments: - - @user_loader - - @dbal.conn - - @cache.driver - - @user - - @auth - - @config - - %core.root_path% - - %core.php_ext% - - %tables.notification_types% - - %tables.user_notifications% + parent: notification.type.base tags: - { name: notification.type } notification.type.group_request: class: phpbb\notification\type\group_request scope: prototype - arguments: - - @user_loader - - @dbal.conn - - @cache.driver - - @user - - @auth - - @config - - %core.root_path% - - %core.php_ext% - - %tables.notification_types% - - %tables.user_notifications% + parent: notification.type.base + calls: + - [set_user_loader, ["@user_loader"]] tags: - { name: notification.type } notification.type.group_request_approved: class: phpbb\notification\type\group_request_approved scope: prototype - arguments: - - @user_loader - - @dbal.conn - - @cache.driver - - @user - - @auth - - @config - - %core.root_path% - - %core.php_ext% - - %tables.notification_types% - - %tables.user_notifications% + parent: notification.type.base tags: - { name: notification.type } notification.type.pm: class: phpbb\notification\type\pm scope: prototype - arguments: - - @user_loader - - @dbal.conn - - @cache.driver - - @user - - @auth - - @config - - %core.root_path% - - %core.php_ext% - - %tables.notification_types% - - %tables.user_notifications% + parent: notification.type.base + calls: + - [set_user_loader, ["@user_loader"]] + - [set_config, ["@config"]] tags: - { name: notification.type } notification.type.post: class: phpbb\notification\type\post scope: prototype - arguments: - - @user_loader - - @dbal.conn - - @cache.driver - - @user - - @auth - - @config - - %core.root_path% - - %core.php_ext% - - %tables.notification_types% - - %tables.user_notifications% + parent: notification.type.base + calls: + - [set_user_loader, ["@user_loader"]] + - [set_config, ["@config"]] tags: - { name: notification.type } notification.type.post_in_queue: class: phpbb\notification\type\post_in_queue scope: prototype - arguments: - - @user_loader - - @dbal.conn - - @cache.driver - - @user - - @auth - - @config - - %core.root_path% - - %core.php_ext% - - %tables.notification_types% - - %tables.user_notifications% + parent: notification.type.base tags: - { name: notification.type } notification.type.quote: class: phpbb\notification\type\quote scope: prototype - arguments: - - @user_loader - - @dbal.conn - - @cache.driver - - @user - - @auth - - @config - - %core.root_path% - - %core.php_ext% - - %tables.notification_types% - - %tables.user_notifications% + parent: notification.type.base calls: - [set_utils, [@text_formatter.utils]] tags: @@ -214,119 +134,45 @@ services: notification.type.report_pm: class: phpbb\notification\type\report_pm scope: prototype - arguments: - - @user_loader - - @dbal.conn - - @cache.driver - - @user - - @auth - - @config - - %core.root_path% - - %core.php_ext% - - %tables.notification_types% - - %tables.user_notifications% + parent: notification.type.base tags: - { name: notification.type } notification.type.report_pm_closed: class: phpbb\notification\type\report_pm_closed scope: prototype - arguments: - - @user_loader - - @dbal.conn - - @cache.driver - - @user - - @auth - - @config - - %core.root_path% - - %core.php_ext% - - %tables.notification_types% - - %tables.user_notifications% + parent: notification.type.base tags: - { name: notification.type } notification.type.report_post: class: phpbb\notification\type\report_post scope: prototype - arguments: - - @user_loader - - @dbal.conn - - @cache.driver - - @user - - @auth - - @config - - %core.root_path% - - %core.php_ext% - - %tables.notification_types% - - %tables.user_notifications% + parent: notification.type.base tags: - { name: notification.type } notification.type.report_post_closed: class: phpbb\notification\type\report_post_closed scope: prototype - arguments: - - @user_loader - - @dbal.conn - - @cache.driver - - @user - - @auth - - @config - - %core.root_path% - - %core.php_ext% - - %tables.notification_types% - - %tables.user_notifications% + parent: notification.type.base tags: - { name: notification.type } notification.type.topic: class: phpbb\notification\type\topic scope: prototype - arguments: - - @user_loader - - @dbal.conn - - @cache.driver - - @user - - @auth - - @config - - %core.root_path% - - %core.php_ext% - - %tables.notification_types% - - %tables.user_notifications% + parent: notification.type.base + calls: + - [set_user_loader, ["@user_loader"]] + - [set_config, ["@config"]] tags: - { name: notification.type } notification.type.topic_in_queue: class: phpbb\notification\type\topic_in_queue scope: prototype - arguments: - - @user_loader - - @dbal.conn - - @cache.driver - - @user - - @auth - - @config - - %core.root_path% - - %core.php_ext% - - %tables.notification_types% - - %tables.user_notifications% - tags: - - { name: notification.type } - - notification.type.admin_activate_user: - class: phpbb\notification\type\admin_activate_user - scope: prototype - arguments: - - @user_loader - - @dbal.conn - - @cache.driver - - @user - - @auth - - @config - - %core.root_path% - - %core.php_ext% - - %tables.notification_types% - - %tables.user_notifications% + parent: notification.type.base tags: - { name: notification.type } diff --git a/phpBB/phpbb/notification/manager.php b/phpBB/phpbb/notification/manager.php index 9a8b671ef8..04259382ba 100644 --- a/phpBB/phpbb/notification/manager.php +++ b/phpBB/phpbb/notification/manager.php @@ -26,7 +26,7 @@ class manager /** @var array */ protected $subscription_types; - /** @var array */ + /** @var method\method_interface[] */ protected $notification_methods; /** @var ContainerInterface */ @@ -805,8 +805,10 @@ class manager } /** - * Helper to get the list of methods enabled by default - */ + * Helper to get the list of methods enabled by default + * + * @return method\method_interface[] + */ public function get_default_methods() { $default_methods = array(); @@ -823,8 +825,10 @@ class manager } /** - * Helper to get the notifications item type class and set it up - */ + * Helper to get the notifications item type class and set it up + * + * @return type\type_interface + */ public function get_item_type_class($notification_type_name, $data = array()) { $item = $this->load_object($notification_type_name); @@ -835,16 +839,20 @@ class manager } /** - * Helper to get the notifications method class and set it up - */ + * Helper to get the notifications method class and set it up + * + * @return method\method_interface + */ public function get_method_class($method_name) { return $this->load_object($method_name); } /** - * Helper to load objects (notification types/methods) - */ + * Helper to load objects (notification types/methods) + * + * @return method\method_interface|type\type_interface + */ protected function load_object($object_name) { $object = $this->phpbb_container->get($object_name); diff --git a/phpBB/phpbb/notification/type/admin_activate_user.php b/phpBB/phpbb/notification/type/admin_activate_user.php index 5b7e58bd92..b191fa62ae 100644 --- a/phpBB/phpbb/notification/type/admin_activate_user.php +++ b/phpBB/phpbb/notification/type/admin_activate_user.php @@ -41,6 +41,22 @@ class admin_activate_user extends \phpbb\notification\type\base 'group' => 'NOTIFICATION_GROUP_ADMINISTRATION', ); + /** @var \phpbb\user_loader */ + protected $user_loader; + + /** @var \phpbb\config\config */ + protected $config; + + public function set_config(\phpbb\config\config $config) + { + $this->config = $config; + } + + public function set_user_loader(\phpbb\user_loader $user_loader) + { + $this->user_loader = $user_loader; + } + /** * {@inheritdoc} */ diff --git a/phpBB/phpbb/notification/type/base.php b/phpBB/phpbb/notification/type/base.php index 843ab98de8..06f7f9c615 100644 --- a/phpBB/phpbb/notification/type/base.php +++ b/phpBB/phpbb/notification/type/base.php @@ -21,27 +21,15 @@ abstract class base implements \phpbb\notification\type\type_interface /** @var \phpbb\notification\manager */ protected $notification_manager; - /** @var \phpbb\user_loader */ - protected $user_loader; - /** @var \phpbb\db\driver\driver_interface */ protected $db; - /** @var \phpbb\cache\driver\driver_interface */ - protected $cache; - - /** @var \phpbb\template\template */ - protected $template; - /** @var \phpbb\user */ protected $user; /** @var \phpbb\auth\auth */ protected $auth; - /** @var \phpbb\config\config */ - protected $config; - /** @var string */ protected $phpbb_root_path; @@ -49,9 +37,6 @@ abstract class base implements \phpbb\notification\type\type_interface protected $php_ext; /** @var string */ - protected $notification_types_table; - - /** @var string */ protected $user_notifications_table; /** @@ -88,31 +73,23 @@ abstract class base implements \phpbb\notification\type\type_interface /** * Notification Type Base Constructor * - * @param \phpbb\user_loader $user_loader * @param \phpbb\db\driver\driver_interface $db - * @param \phpbb\cache\driver\driver_interface $cache * @param \phpbb\user $user * @param \phpbb\auth\auth $auth - * @param \phpbb\config\config $config * @param string $phpbb_root_path * @param string $php_ext - * @param string $notification_types_table * @param string $user_notifications_table * @return \phpbb\notification\type\base */ - public function __construct(\phpbb\user_loader $user_loader, \phpbb\db\driver\driver_interface $db, \phpbb\cache\driver\driver_interface $cache, $user, \phpbb\auth\auth $auth, \phpbb\config\config $config, $phpbb_root_path, $php_ext, $notification_types_table, $user_notifications_table) + public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\user $user, \phpbb\auth\auth $auth, $phpbb_root_path, $php_ext, $user_notifications_table) { - $this->user_loader = $user_loader; $this->db = $db; - $this->cache = $cache; $this->user = $user; $this->auth = $auth; - $this->config = $config; $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; - $this->notification_types_table = $notification_types_table; $this->user_notifications_table = $user_notifications_table; } diff --git a/phpBB/phpbb/notification/type/bookmark.php b/phpBB/phpbb/notification/type/bookmark.php index 4f66a1ef5c..59423ca248 100644 --- a/phpBB/phpbb/notification/type/bookmark.php +++ b/phpBB/phpbb/notification/type/bookmark.php @@ -48,6 +48,14 @@ class bookmark extends \phpbb\notification\type\post 'group' => 'NOTIFICATION_GROUP_POSTING', ); + /** @var \phpbb\config\config */ + protected $config; + + public function set_config(\phpbb\config\config $config) + { + $this->config = $config; + } + /** * Is available */ @@ -100,6 +108,7 @@ class bookmark extends \phpbb\notification\type\post { unset($notify_users[$user]); + /** @var bookmark $notification */ $notification = $this->notification_manager->get_item_type_class($this->get_type(), $notification_data); $update_responders = $notification->add_responders($post); if (!empty($update_responders)) diff --git a/phpBB/phpbb/notification/type/group_request.php b/phpBB/phpbb/notification/type/group_request.php index 9a5746bcce..8a0027bfec 100644 --- a/phpBB/phpbb/notification/type/group_request.php +++ b/phpBB/phpbb/notification/type/group_request.php @@ -30,6 +30,14 @@ class group_request extends \phpbb\notification\type\base 'lang' => 'NOTIFICATION_TYPE_GROUP_REQUEST', ); + /** @var \phpbb\user_loader */ + protected $user_loader; + + public function set_user_loader(\phpbb\user_loader $user_loader) + { + $this->user_loader = $user_loader; + } + /** * {@inheritdoc} */ diff --git a/phpBB/phpbb/notification/type/pm.php b/phpBB/phpbb/notification/type/pm.php index 6c66c9c057..2de2dcfa0b 100644 --- a/phpBB/phpbb/notification/type/pm.php +++ b/phpBB/phpbb/notification/type/pm.php @@ -40,6 +40,22 @@ class pm extends \phpbb\notification\type\base 'lang' => 'NOTIFICATION_TYPE_PM', ); + /** @var \phpbb\user_loader */ + protected $user_loader; + + /** @var \phpbb\config\config */ + protected $config; + + public function set_config(\phpbb\config\config $config) + { + $this->config = $config; + } + + public function set_user_loader(\phpbb\user_loader $user_loader) + { + $this->user_loader = $user_loader; + } + /** * Is available */ diff --git a/phpBB/phpbb/notification/type/post.php b/phpBB/phpbb/notification/type/post.php index e310484187..f3dd6d531a 100644 --- a/phpBB/phpbb/notification/type/post.php +++ b/phpBB/phpbb/notification/type/post.php @@ -55,6 +55,22 @@ class post extends \phpbb\notification\type\base 'group' => 'NOTIFICATION_GROUP_POSTING', ); + /** @var \phpbb\user_loader */ + protected $user_loader; + + /** @var \phpbb\config\config */ + protected $config; + + public function set_config(\phpbb\config\config $config) + { + $this->config = $config; + } + + public function set_user_loader(\phpbb\user_loader $user_loader) + { + $this->user_loader = $user_loader; + } + /** * Is available */ @@ -140,6 +156,7 @@ class post extends \phpbb\notification\type\base { unset($notify_users[$user]); + /** @var post $notification */ $notification = $this->notification_manager->get_item_type_class($this->get_type(), $notification_data); $update_responders = $notification->add_responders($post); if (!empty($update_responders)) diff --git a/phpBB/phpbb/notification/type/report_pm.php b/phpBB/phpbb/notification/type/report_pm.php index a68685547a..0f7dce0a68 100644 --- a/phpBB/phpbb/notification/type/report_pm.php +++ b/phpBB/phpbb/notification/type/report_pm.php @@ -141,6 +141,8 @@ class report_pm extends \phpbb\notification\type\pm */ public function get_email_template_variables() { + $user_data = $this->user_loader->get_username($this->get_data('reporter_id'), 'no_profile'); + return array( 'AUTHOR_NAME' => htmlspecialchars_decode($user_data['username']), 'SUBJECT' => htmlspecialchars_decode(censor_text($this->get_data('message_subject'))), diff --git a/phpBB/phpbb/notification/type/topic.php b/phpBB/phpbb/notification/type/topic.php index 22eb4bd526..4812e8b5af 100644 --- a/phpBB/phpbb/notification/type/topic.php +++ b/phpBB/phpbb/notification/type/topic.php @@ -55,6 +55,22 @@ class topic extends \phpbb\notification\type\base 'group' => 'NOTIFICATION_GROUP_POSTING', ); + /** @var \phpbb\user_loader */ + protected $user_loader; + + /** @var \phpbb\config\config */ + protected $config; + + public function set_config(\phpbb\config\config $config) + { + $this->config = $config; + } + + public function set_user_loader(\phpbb\user_loader $user_loader) + { + $this->user_loader = $user_loader; + } + /** * Is available */ diff --git a/tests/mock/container_builder.php b/tests/mock/container_builder.php index e04a83804d..134589b0b8 100644 --- a/tests/mock/container_builder.php +++ b/tests/mock/container_builder.php @@ -188,4 +188,9 @@ class phpbb_mock_container_builder implements ContainerInterface public function isScopeActive($name) { } + + public function isFrozen() + { + return false; + } } diff --git a/tests/notification/base.php b/tests/notification/base.php index c898c76947..1295f099f0 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 @@ -70,8 +74,9 @@ abstract class phpbb_tests_notification_base extends phpbb_database_test_case $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\dummy(), + $cache_driver, $this->config, $this->db, $phpbb_root_path, @@ -80,36 +85,48 @@ abstract class phpbb_tests_notification_base extends phpbb_database_test_case $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('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, $this->user, - $phpbb_root_path, - $phpEx, 'phpbb_notification_types', '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); @@ -117,11 +134,9 @@ abstract class phpbb_tests_notification_base extends phpbb_database_test_case $methods = array(); foreach ($this->get_notification_methods() as $method) { - $method_parts = explode('.', $method); - $class = $this->build_type('phpbb\notification\method\\' . array_pop($method_parts)); + $class = $this->container->get($method); $methods[$method] = $class; - $this->container->set($method, $class); } $this->notifications->set_var('notification_methods', $methods); @@ -133,26 +148,11 @@ abstract class phpbb_tests_notification_base extends phpbb_database_test_case protected function build_type($type) { - 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_user_notifications'); - - if ($type === 'phpbb\\notification\\type\\quote') - { - $instance->set_utils(new \phpbb\textformatter\s9e\utils); - } + $instance = $this->container->get($type); 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('notification.method.board', array_merge(array( diff --git a/tests/notification/fixtures/services_notification.yml b/tests/notification/fixtures/services_notification.yml new file mode 100644 index 0000000000..7eaa7e81ec --- /dev/null +++ b/tests/notification/fixtures/services_notification.yml @@ -0,0 +1,70 @@ +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 + + auth: + synthetic: true + + cache.driver: + 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/manager_helper.php b/tests/notification/manager_helper.php index 40cf9b3ad4..2e8699e1e0 100644 --- a/tests/notification/manager_helper.php +++ b/tests/notification/manager_helper.php @@ -37,41 +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->user_notifications_table); - - if ($item_type === 'phpbb\\notification\\type\\quote') - { - $item->set_utils(new \phpbb\textformatter\s9e\utils); - } - - $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_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, 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 167cde13ca..ec42aa193c 100644 --- a/tests/notification/notification_test.php +++ b/tests/notification/notification_test.php @@ -81,9 +81,9 @@ class phpbb_notification_test extends phpbb_tests_notification_base ); $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]); } diff --git a/tests/notification/submit_post_base.php b/tests/notification/submit_post_base.php index 73711369ed..72b25abf0a 100644 --- a/tests/notification/submit_post_base.php +++ b/tests/notification/submit_post_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__) . '/../../phpBB/includes/functions.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/functions_posting.php'; @@ -75,8 +79,9 @@ abstract class phpbb_notification_submit_post_base extends phpbb_database_test_c 'allow_board_notifications' => true, )); + $cache_driver = new \phpbb\cache\driver\dummy(); $cache = new \phpbb\cache\service( - new \phpbb\cache\driver\dummy(), + $cache_driver, $config, $db, $phpbb_root_path, @@ -103,58 +108,49 @@ 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('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 = $this->build_type($type); - $phpbb_container->set('notification.type.' . $type, array(array($this, 'build_type'), array($type))); + $class = $phpbb_container->get('notification.type.' . $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_methods_array = array('notification.method.board' => $phpbb_container->get('notification.method.board')); // Notification Manager $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, + $phpbb_container, $user_loader, $phpbb_dispatcher, $db, $cache, $user, 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 */ @@ -177,11 +173,4 @@ 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'); - } } diff --git a/tests/notification/submit_post_type_quote_test.php b/tests/notification/submit_post_type_quote_test.php index 8ad6a62b09..3fab8c05ba 100644 --- a/tests/notification/submit_post_type_quote_test.php +++ b/tests/notification/submit_post_type_quote_test.php @@ -51,7 +51,8 @@ class phpbb_notification_submit_post_type_quote_test extends phpbb_notification_ */ public function submit_post_data() { - $parser = $this->get_test_case_helpers()->set_s9e_services()->get('text_formatter.parser'); + // 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( /** diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 62a56ed693..70bd309653 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -426,24 +426,34 @@ class phpbb_test_case_helpers $cache_key_parser = $prefix . '_parser'; $cache_key_renderer = $prefix . '_renderer'; $container->set('cache.driver', $cache); - $container->setParameter('cache.dir', $cache_dir); + + if (!$container->isFrozen()) + { + $container->setParameter('cache.dir', $cache_dir); + } // Create a path_helper - if (!$container->has('path_helper')) + if (!$container->has('path_helper') || $container->getDefinition('path_helper')->isSynthetic()) { + $path_helper = new \phpbb\path_helper( + new \phpbb\symfony_request( + new phpbb_mock_request() + ), + new \phpbb\filesystem(), + $this->test_case->getMock('\phpbb\request\request'), + $phpbb_root_path, + $phpEx + ); + $container->set( 'path_helper', - new \phpbb\path_helper( - new \phpbb\symfony_request( - new phpbb_mock_request() - ), - new \phpbb\filesystem(), - $this->test_case->getMock('\phpbb\request\request'), - $phpbb_root_path, - $phpEx - ) + $path_helper ); } + else + { + $path_helper = $container->get('path_helper'); + } // Create an event dispatcher if ($container->has('dispatcher')) @@ -534,7 +544,7 @@ class phpbb_test_case_helpers // Calls configured in services.yml $renderer->configure_quote_helper($quote_helper); - $renderer->configure_smilies_path($config, $container->get('path_helper')); + $renderer->configure_smilies_path($config, $path_helper); $renderer->configure_user($user, $config, $auth); $container->set('text_formatter.renderer', $renderer); |