1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-09 18:26:32 +02:00

[ticket/11444] Update tests and cleanup types/methods

PHPBB3-11444
This commit is contained in:
Tristan Darricau
2015-07-09 17:04:40 +02:00
parent f29b12e353
commit fc34057f28
18 changed files with 309 additions and 356 deletions

View File

@@ -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(

View File

@@ -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 }

View File

@@ -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;
}
}

View File

@@ -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]);
}

View File

@@ -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');
}
}

View File

@@ -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(
/**