diff options
author | Nathaniel Guse <nathaniel.guse@gmail.com> | 2013-07-26 13:08:53 -0500 |
---|---|---|
committer | Nathaniel Guse <nathaniel.guse@gmail.com> | 2013-07-26 13:08:53 -0500 |
commit | a988c7e396283b1b44a6d3a08582b47cc68c8067 (patch) | |
tree | 9d9c69f133262f723a8bf76ea39f06806d245879 /tests | |
parent | 3f230b1a8c716adb77b679fed91d50c391387b19 (diff) | |
download | forums-a988c7e396283b1b44a6d3a08582b47cc68c8067.tar forums-a988c7e396283b1b44a6d3a08582b47cc68c8067.tar.gz forums-a988c7e396283b1b44a6d3a08582b47cc68c8067.tar.bz2 forums-a988c7e396283b1b44a6d3a08582b47cc68c8067.tar.xz forums-a988c7e396283b1b44a6d3a08582b47cc68c8067.zip |
[ticket/11744] Create base notification test class for setup
PHPBB3-11744
Diffstat (limited to 'tests')
-rw-r--r-- | tests/notification/base.php | 105 | ||||
-rw-r--r-- | tests/notification/notification_test.php | 85 |
2 files changed, 107 insertions, 83 deletions
diff --git a/tests/notification/base.php b/tests/notification/base.php new file mode 100644 index 0000000000..ab92f88262 --- /dev/null +++ b/tests/notification/base.php @@ -0,0 +1,105 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +require_once dirname(__FILE__) . '/manager_helper.php'; + +abstract class phpbb_tests_notification_base extends phpbb_database_test_case +{ + protected $notifications, $db, $container, $user, $config, $auth, $cache; + + protected function get_notification_types() + { + 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', + ); + } + + protected function setUp() + { + parent::setUp(); + + global $phpbb_root_path, $phpEx; + + include_once(__DIR__ . '/ext/test/notification/type/test.' . $phpEx); + + global $db, $config, $user, $auth, $cache, $phpbb_container; + + $db = $this->db = $this->new_dbal(); + $config = $this->config = new phpbb_config(array( + 'allow_privmsg' => true, + 'allow_bookmarks' => true, + 'allow_topic_notify' => true, + 'allow_forum_notify' => true, + )); + $user = $this->user = new phpbb_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 = $this->cache = new phpbb_cache_service( + new phpbb_cache_driver_null(), + $this->config, + $this->db, + $phpbb_root_path, + $phpEx + ); + + $phpbb_container = $this->container = new phpbb_mock_container_builder(); + + $this->notifications = new phpbb_notification_manager_helper( + array(), + array(), + $this->container, + $this->user_loader, + $this->db, + $this->cache, + $this->user, + $phpbb_root_path, + $phpEx, + 'phpbb_notification_types', + 'phpbb_notifications', + 'phpbb_user_notifications' + ); + + $phpbb_container->set('notification_manager', $this->notifications); + + $this->notifications->setDependencies($this->auth, $this->config); + + $types = array(); + foreach ($this->get_notification_types() as $type) + { + $class = $this->build_type('phpbb_notification_type_' . $type); + + $types[$type] = $class; + $this->container->set('notification.type.' . $type, $class); + } + + $this->notifications->set_var('notification_types', $types); + } + + protected function build_type($type) + { + global $phpbb_root_path, $phpEx; + + 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'); + } +} diff --git a/tests/notification/notification_test.php b/tests/notification/notification_test.php index 8f7eb3b8a8..39073c2602 100644 --- a/tests/notification/notification_test.php +++ b/tests/notification/notification_test.php @@ -7,9 +7,9 @@ * */ -require_once dirname(__FILE__) . '/manager_helper.php'; +require_once dirname(__FILE__) . '/base.php'; -class phpbb_notification_test extends phpbb_database_test_case +class phpbb_notification_test extends phpbb_tests_notification_base { protected $notifications, $db, $container, $user, $config, $auth, $cache; @@ -18,87 +18,6 @@ class phpbb_notification_test extends phpbb_database_test_case return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/notification.xml'); } - protected function setUp() - { - parent::setUp(); - - global $phpbb_root_path, $phpEx; - - include_once(__DIR__ . '/ext/test/notification/type/test.' . $phpEx); - - $this->db = $this->new_dbal(); - $this->config = new phpbb_config(array( - 'allow_privmsg' => true, - 'allow_bookmarks' => true, - 'allow_topic_notify' => true, - 'allow_forum_notify' => true, - )); - $this->user = new phpbb_user(); - $this->user_loader = new phpbb_user_loader($this->db, $phpbb_root_path, $phpEx, 'phpbb_users'); - $this->auth = new phpbb_mock_notifications_auth(); - $this->cache = new phpbb_cache_service( - new phpbb_cache_driver_null(), - $this->config, - $this->db, - $phpbb_root_path, - $phpEx - ); - - $this->container = new phpbb_mock_container_builder(); - - $this->notifications = new phpbb_notification_manager_helper( - array(), - array(), - $this->container, - $this->user_loader, - $this->db, - $this->cache, - $this->user, - $phpbb_root_path, - $phpEx, - 'phpbb_notification_types', - 'phpbb_notifications', - 'phpbb_user_notifications' - ); - - $this->notifications->setDependencies($this->auth, $this->config); - - $types = array(); - foreach (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', - ) as $type) - { - $class = $this->build_type('phpbb_notification_type_' . $type); - - $types[$type] = $class; - $this->container->set('notification.type.' . $type, $class); - } - - $this->notifications->set_var('notification_types', $types); - } - - protected function build_type($type) - { - global $phpbb_root_path, $phpEx; - - 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'); - } - public function test_get_notification_type_id() { // They should be inserted the first time |