diff options
author | Joas Schilling <nickvergessen@gmx.de> | 2013-03-25 15:16:29 +0100 |
---|---|---|
committer | Joas Schilling <nickvergessen@gmx.de> | 2013-03-25 15:16:29 +0100 |
commit | 060876e627db127c72a953d37e83f5176a085e5d (patch) | |
tree | 35cae27d372a05712d284d87c3fc1fe0ee4576dc /tests/notification | |
parent | 1259117d213d9364ec7eaeb637f9a3fd8838e816 (diff) | |
download | forums-060876e627db127c72a953d37e83f5176a085e5d.tar forums-060876e627db127c72a953d37e83f5176a085e5d.tar.gz forums-060876e627db127c72a953d37e83f5176a085e5d.tar.bz2 forums-060876e627db127c72a953d37e83f5176a085e5d.tar.xz forums-060876e627db127c72a953d37e83f5176a085e5d.zip |
[ticket/11405] Add a base class to avoid duplicated setUp() code
PHPBB3-11405
Diffstat (limited to 'tests/notification')
-rw-r--r-- | tests/notification/submit_post_base.php | 94 | ||||
-rw-r--r-- | tests/notification/submit_post_type_post_test.php | 81 | ||||
-rw-r--r-- | tests/notification/submit_post_type_quote_test.php | 81 |
3 files changed, 102 insertions, 154 deletions
diff --git a/tests/notification/submit_post_base.php b/tests/notification/submit_post_base.php new file mode 100644 index 0000000000..60d0e798cb --- /dev/null +++ b/tests/notification/submit_post_base.php @@ -0,0 +1,94 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +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'; +require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; + +class phpbb_notification_submit_post_base extends phpbb_database_test_case +{ + protected $notifications, $db, $container, $user, $config, $auth, $cache; + + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/submit_post_notification.xml'); + } + + public function setUp() + { + parent::setUp(); + + global $auth, $cache, $config, $db, $phpbb_container, $phpbb_dispatcher, $user, $request, $phpEx, $phpbb_root_path; + + // Database + $this->db = $this->new_dbal(); + $db = $this->db; + + // Cache + $cache = new phpbb_mock_cache(); + + // Auth + $auth = $this->getMock('phpbb_auth'); + $auth->expects($this->any()) + ->method('acl_get') + ->with($this->stringContains('_'), + $this->anything()) + ->will($this->returnValueMap(array( + array('f_noapprove', 1, true), + array('f_postcount', 1, true), + array('m_edit', 1, false), + ))); + + // Config + $config = new phpbb_config(array('num_topics' => 1,'num_posts' => 1,)); + set_config(null, null, null, $config); + set_config_count(null, null, null, $config); + + // Event dispatcher + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + + // User + $user = $this->getMock('phpbb_user'); + $user->ip = ''; + $user->data = array( + 'user_id' => 2, + 'username' => 'user-name', + 'is_registered' => true, + 'user_colour' => '', + ); + + // Request + $type_cast_helper = $this->getMock('phpbb_request_type_cast_helper_interface'); + $request = $this->getMock('phpbb_request'); + + // Container + $phpbb_container = new phpbb_mock_container_builder(); + + $user_loader = new phpbb_user_loader($db, $phpbb_root_path, '.' . $phpEx, USERS_TABLE); + + // Notification Manager + $phpbb_notifications = new phpbb_notification_manager(array(), array(), + $phpbb_container, $user_loader, $db, $user, + $phpbb_root_path, '.' . $phpEx, + NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE); + $phpbb_container->set('notification_manager', $phpbb_notifications); + + // Notification Types + $notification_types = array('quote', 'bookmark', 'post'); + foreach ($notification_types as $type) + { + $class_name = 'phpbb_notification_type_' . $type; + $phpbb_container->set('notification.type.' . $type, new $class_name( + $user_loader, $db, $cache, $user, $auth, $config, + $phpbb_root_path, '.' . $phpEx, + NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE)); + } + } +} diff --git a/tests/notification/submit_post_type_post_test.php b/tests/notification/submit_post_type_post_test.php index b1e4b86b15..2e269ff080 100644 --- a/tests/notification/submit_post_type_post_test.php +++ b/tests/notification/submit_post_type_post_test.php @@ -7,45 +7,17 @@ * */ -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'; -require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; +require_once dirname(__FILE__) . '/submit_post_base.php'; -class phpbb_notification_submit_post_type_post_test extends phpbb_database_test_case +class phpbb_notification_submit_post_type_post_test extends phpbb_notification_submit_post_base { - protected $notifications, $db, $container, $user, $config, $auth, $cache; - - public function getDataSet() - { - return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/submit_post_notification.xml'); - } - public function setUp() { parent::setUp(); - global $auth, $cache, $config, $db, $phpbb_container, $phpbb_dispatcher, $user, $request, $phpEx, $phpbb_root_path; - - // Database - $this->db = $this->new_dbal(); - $db = $this->db; - - // Cache - $cache = new phpbb_mock_cache(); - - // Auth - $auth = $this->getMock('phpbb_auth'); - $auth->expects($this->any()) - ->method('acl_get') - ->with($this->stringContains('_'), - $this->anything()) - ->will($this->returnValueMap(array( - array('f_noapprove', 1, true), - array('f_postcount', 1, true), - array('m_edit', 1, false), - ))); + global $auth; + // Add additional permissions $auth->expects($this->any()) ->method('acl_get_list') ->with($this->anything(), @@ -63,51 +35,6 @@ class phpbb_notification_submit_post_type_post_test extends phpbb_database_test_ ), ), ))); - - // Config - $config = new phpbb_config(array('num_topics' => 1,'num_posts' => 1,)); - set_config(null, null, null, $config); - set_config_count(null, null, null, $config); - - // Event dispatcher - $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); - - // User - $user = $this->getMock('phpbb_user'); - $user->ip = ''; - $user->data = array( - 'user_id' => 2, - 'username' => 'user-name', - 'is_registered' => true, - 'user_colour' => '', - ); - - // Request - $type_cast_helper = $this->getMock('phpbb_request_type_cast_helper_interface'); - $request = $this->getMock('phpbb_request'); - - // Container - $phpbb_container = new phpbb_mock_container_builder(); - - $user_loader = new phpbb_user_loader($db, $phpbb_root_path, '.' . $phpEx, USERS_TABLE); - - // Notification Manager - $phpbb_notifications = new phpbb_notification_manager(array(), array(), - $phpbb_container, $user_loader, $db, $user, - $phpbb_root_path, '.' . $phpEx, - NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE); - $phpbb_container->set('notification_manager', $phpbb_notifications); - - // Notification Types - $notification_types = array('quote', 'bookmark', 'post'); - foreach ($notification_types as $type) - { - $class_name = 'phpbb_notification_type_' . $type; - $phpbb_container->set('notification.type.' . $type, new $class_name( - $user_loader, $db, $cache, $user, $auth, $config, - $phpbb_root_path, '.' . $phpEx, - NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE)); - } } /** diff --git a/tests/notification/submit_post_type_quote_test.php b/tests/notification/submit_post_type_quote_test.php index 82f4eaf189..603f7b2020 100644 --- a/tests/notification/submit_post_type_quote_test.php +++ b/tests/notification/submit_post_type_quote_test.php @@ -7,45 +7,17 @@ * */ -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'; -require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; +require_once dirname(__FILE__) . '/submit_post_base.php'; -class phpbb_notification_submit_post_type_quote_test extends phpbb_database_test_case +class phpbb_notification_submit_post_type_quote_test extends phpbb_notification_submit_post_base { - protected $notifications, $db, $container, $user, $config, $auth, $cache; - - public function getDataSet() - { - return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/submit_post_notification.xml'); - } - public function setUp() { parent::setUp(); - global $auth, $cache, $config, $db, $phpbb_container, $phpbb_dispatcher, $user, $request, $phpEx, $phpbb_root_path; - - // Database - $this->db = $this->new_dbal(); - $db = $this->db; - - // Cache - $cache = new phpbb_mock_cache(); - - // Auth - $auth = $this->getMock('phpbb_auth'); - $auth->expects($this->any()) - ->method('acl_get') - ->with($this->stringContains('_'), - $this->anything()) - ->will($this->returnValueMap(array( - array('f_noapprove', 1, true), - array('f_postcount', 1, true), - array('m_edit', 1, false), - ))); + global $auth; + // Add additional permissions $auth->expects($this->any()) ->method('acl_get_list') ->with($this->anything(), @@ -63,51 +35,6 @@ class phpbb_notification_submit_post_type_quote_test extends phpbb_database_test ), ), ))); - - // Config - $config = new phpbb_config(array('num_topics' => 1,'num_posts' => 1,)); - set_config(null, null, null, $config); - set_config_count(null, null, null, $config); - - // Event dispatcher - $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); - - // User - $user = $this->getMock('phpbb_user'); - $user->ip = ''; - $user->data = array( - 'user_id' => 2, - 'username' => 'user-name', - 'is_registered' => true, - 'user_colour' => '', - ); - - // Request - $type_cast_helper = $this->getMock('phpbb_request_type_cast_helper_interface'); - $request = $this->getMock('phpbb_request'); - - // Container - $phpbb_container = new phpbb_mock_container_builder(); - - $user_loader = new phpbb_user_loader($db, $phpbb_root_path, '.' . $phpEx, USERS_TABLE); - - // Notification Manager - $phpbb_notifications = new phpbb_notification_manager(array(), array(), - $phpbb_container, $user_loader, $db, $user, - $phpbb_root_path, '.' . $phpEx, - NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE); - $phpbb_container->set('notification_manager', $phpbb_notifications); - - // Notification Types - $notification_types = array('quote', 'bookmark', 'post'); - foreach ($notification_types as $type) - { - $class_name = 'phpbb_notification_type_' . $type; - $phpbb_container->set('notification.type.' . $type, new $class_name( - $user_loader, $db, $cache, $user, $auth, $config, - $phpbb_root_path, '.' . $phpEx, - NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE)); - } } /** |