mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 14:18:52 +00:00
[ticket/11103] Working on test case
Fixing extension type/method naming scheme so they can be autoloaded. Other bugs PHPBB3-11103
This commit is contained in:
parent
ceb56da965
commit
3f2e3ad633
7 changed files with 460 additions and 19 deletions
|
@ -466,11 +466,6 @@ class phpbb_notification_manager
|
|||
{
|
||||
$class_name = $this->get_item_type_class_name($class_name);
|
||||
|
||||
if (!class_exists($class_name))
|
||||
{
|
||||
include($file);
|
||||
}
|
||||
|
||||
$class = $this->get_item_type_class($class_name);
|
||||
|
||||
if ($class->is_available() && method_exists($class_name, 'get_item_type'))
|
||||
|
@ -502,11 +497,6 @@ class phpbb_notification_manager
|
|||
{
|
||||
$class_name = 'phpbb_notification_method_' . $method_name;
|
||||
|
||||
if (!class_exists($class_name))
|
||||
{
|
||||
include($file);
|
||||
}
|
||||
|
||||
$method = $this->get_method_class($class_name);
|
||||
|
||||
if ($method->is_available())
|
||||
|
@ -652,7 +642,14 @@ class phpbb_notification_manager
|
|||
{
|
||||
if (!$safe)
|
||||
{
|
||||
$item_type = preg_replace('#[^a-z_]#', '', $item_type);
|
||||
$item_type = preg_replace('#[^a-z_-]#', '', $item_type);
|
||||
}
|
||||
|
||||
if (strpos($item_type, 'ext_') === 0)
|
||||
{
|
||||
$item_type_ary = explode('-', substr($item_type, 4), 2);
|
||||
|
||||
return 'phpbb_ext_' . $item_type_ary[0] . '_notification_type_' . $item_type_ary[1];
|
||||
}
|
||||
|
||||
return 'phpbb_notification_type_' . $item_type;
|
||||
|
@ -661,7 +658,7 @@ class phpbb_notification_manager
|
|||
/**
|
||||
* Helper to get the notifications item type class and set it up
|
||||
*/
|
||||
private function get_item_type_class($item_type, $data = array())
|
||||
public function get_item_type_class($item_type, $data = array())
|
||||
{
|
||||
$item = new $item_type($this, $this->db, $this->cache, $this->template, $this->extension_manager, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext);
|
||||
|
||||
|
@ -673,7 +670,7 @@ class phpbb_notification_manager
|
|||
/**
|
||||
* Helper to get the notifications method class and set it up
|
||||
*/
|
||||
private function get_method_class($method_name)
|
||||
public function get_method_class($method_name)
|
||||
{
|
||||
return new $method_name($this, $this->db, $this->cache, $this->template, $this->extension_manager, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext);
|
||||
}
|
||||
|
@ -693,15 +690,23 @@ class phpbb_notification_manager
|
|||
->get_files();
|
||||
foreach ($files as $file)
|
||||
{
|
||||
$class = substr($file, strrpos($file, '/'));
|
||||
$class = substr($class, 1, (strpos($class, '.' . $this->php_ext) - 1));
|
||||
$name = substr($file, strrpos($file, '/'));
|
||||
$name = substr($name, 1, (strpos($name, '.' . $this->php_ext) - 1));
|
||||
|
||||
if ($class == 'interface' || $class == 'base')
|
||||
if ($name == 'interface' || $name == 'base')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$subscription_files[$class] = $file;
|
||||
if (!strpos($file, 'includes/')) // is an extension
|
||||
{
|
||||
$ext_name = substr($file, (strpos($file, 'ext/') + 4));
|
||||
$ext_name = substr($ext_name, 0, strpos($ext_name, '/'));
|
||||
|
||||
$name = 'ext_' . $ext_name . '-' . $name;
|
||||
}
|
||||
|
||||
$subscription_files[$name] = $file;
|
||||
}
|
||||
|
||||
return $subscription_files;
|
||||
|
|
|
@ -50,7 +50,7 @@ abstract class phpbb_notification_method_base implements phpbb_notification_meth
|
|||
*/
|
||||
protected $queue = array();
|
||||
|
||||
public function __construct(phpbb_notification_manager $notification_manager, dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, phpbb_user $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext)
|
||||
public function __construct(phpbb_notification_manager $notification_manager, dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext)
|
||||
{
|
||||
$this->notification_manager = $notification_manager;
|
||||
$this->db = $db;
|
||||
|
|
|
@ -55,7 +55,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
|
|||
*/
|
||||
private $data = array();
|
||||
|
||||
public function __construct(phpbb_notification_manager $notification_manager, dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, phpbb_user $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext)
|
||||
public function __construct(phpbb_notification_manager $notification_manager, dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext)
|
||||
{
|
||||
$this->notification_manager = $notification_manager;
|
||||
$this->db = $db;
|
||||
|
@ -91,6 +91,11 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
|
|||
$this->data[$name] = $value;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return (!empty($this->data)) ? var_export($this->data, true) : static::get_item_type();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get special data (only important for the classes that extend this)
|
||||
*
|
||||
|
|
|
@ -43,6 +43,8 @@ interface phpbb_notification_type_interface
|
|||
|
||||
public function create_insert_array($type_data);
|
||||
|
||||
public function users_to_query();
|
||||
|
||||
public function get_load_special();
|
||||
|
||||
public function load_special($data, $notifications);
|
||||
|
|
72
tests/notification/ext/test/notification/type/test.php
Normal file
72
tests/notification/ext/test/notification/type/test.php
Normal file
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* @package notifications
|
||||
* @copyright (c) 2012 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
class phpbb_ext_test_notification_type_test extends phpbb_notification_type_base
|
||||
{
|
||||
public $email_template = 'topic_notify';
|
||||
|
||||
public static function get_item_type()
|
||||
{
|
||||
return 'ext_test-test';
|
||||
}
|
||||
|
||||
public static function get_item_id($post)
|
||||
{
|
||||
return (int) $post['post_id'];
|
||||
}
|
||||
|
||||
public static function get_item_parent_id($post)
|
||||
{
|
||||
return (int) $post['topic_id'];
|
||||
}
|
||||
|
||||
public function find_users_for_notification($post, $options = array())
|
||||
{
|
||||
return array(
|
||||
0 => array(''),
|
||||
//2 => array('', 'email'),
|
||||
//3 => array('', 'email', 'jabber'),
|
||||
);
|
||||
}
|
||||
|
||||
public function create_insert_array($post)
|
||||
{
|
||||
$this->time = $post['post_time'];
|
||||
|
||||
return parent::create_insert_array($post);
|
||||
}
|
||||
|
||||
public function get_title()
|
||||
{
|
||||
return 'test title';
|
||||
}
|
||||
|
||||
public function users_to_query()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
public function get_url()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function get_email_template_variables()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
}
|
5
tests/notification/fixtures/notification.xml
Normal file
5
tests/notification/fixtures/notification.xml
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<dataset>
|
||||
<table name="phpbb_notifications">
|
||||
</table>
|
||||
</dataset>
|
352
tests/notification/notification.php
Normal file
352
tests/notification/notification.php
Normal file
|
@ -0,0 +1,352 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2012 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
class phpbb_notification_test extends phpbb_database_test_case
|
||||
{
|
||||
protected $notifications;
|
||||
static private $copied_files = array();
|
||||
static private $helper;
|
||||
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/notification.xml');
|
||||
}
|
||||
|
||||
/**
|
||||
* This should only be called once before the tests are run.
|
||||
* This is used to copy the extensions to the phpBB install
|
||||
*/
|
||||
static public function setUpBeforeClass()
|
||||
{
|
||||
global $phpbb_root_path;
|
||||
|
||||
parent::setUpBeforeClass();
|
||||
|
||||
self::$helper = new phpbb_test_case_helpers(self);
|
||||
|
||||
// First, move any extensions setup on the board to a temp directory
|
||||
self::$copied_files = self::$helper->copy_dir($phpbb_root_path . 'ext/', $phpbb_root_path . 'store/temp_ext/');
|
||||
|
||||
// Then empty the ext/ directory on the board (for accurate test cases)
|
||||
self::$helper->empty_dir($phpbb_root_path . 'ext/');
|
||||
|
||||
// Copy our ext/ files from the test case to the board
|
||||
self::$copied_files = array_merge(self::$copied_files, self::$helper->copy_dir(dirname(__FILE__) . '/ext/', $phpbb_root_path . 'ext/'));
|
||||
}
|
||||
|
||||
/**
|
||||
* This should only be called once after the tests are run.
|
||||
* This is used to remove the files copied to the phpBB install
|
||||
*/
|
||||
static public function tearDownAfterClass()
|
||||
{
|
||||
global $phpbb_root_path;
|
||||
|
||||
// Copy back the board installed extensions from the temp directory
|
||||
self::$helper->copy_dir($phpbb_root_path . 'store/temp_ext/', $phpbb_root_path . 'ext/');
|
||||
|
||||
self::$copied_files[] = $phpbb_root_path . 'store/temp_ext/';
|
||||
|
||||
// Remove all of the files we copied around (from board ext -> temp_ext, from test ext -> board ext)
|
||||
self::$helper->remove_files(self::$copied_files);
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
global $phpbb_root_path, $db, $phpEx;
|
||||
|
||||
if (!function_exists('set_var'))
|
||||
{
|
||||
include($phpbb_root_path . 'includes/functions.' . $phpEx);
|
||||
}
|
||||
|
||||
$db = $this->new_dbal();
|
||||
$config = new phpbb_config(array());
|
||||
$user = new phpbb_mock_user();
|
||||
|
||||
$this->notifications = new phpbb_notification_manager(
|
||||
$db,
|
||||
new phpbb_mock_cache(),
|
||||
new phpbb_template($phpbb_root_path, $phpEx, $config, $user, new phpbb_style_resource_locator()),
|
||||
new phpbb_mock_extension_manager($phpbb_root_path,
|
||||
array(
|
||||
'test' => array(
|
||||
'ext_name' => 'test',
|
||||
'ext_active' => '1',
|
||||
'ext_path' => 'ext/test/',
|
||||
),
|
||||
)
|
||||
),
|
||||
$user,
|
||||
new phpbb_auth(),
|
||||
$config,
|
||||
$phpbb_root_path,
|
||||
$phpEx
|
||||
);
|
||||
}
|
||||
|
||||
public function test_get_subscription_types()
|
||||
{
|
||||
$this->assertArrayHasKey('ext_test-test', $this->notifications->get_subscription_types());
|
||||
$this->assertArrayHasKey('moderation_queue', $this->notifications->get_subscription_types());
|
||||
$this->assertArrayHasKey('bookmark', $this->notifications->get_subscription_types());
|
||||
$this->assertArrayHasKey('pm', $this->notifications->get_subscription_types());
|
||||
$this->assertArrayHasKey('post', $this->notifications->get_subscription_types());
|
||||
$this->assertArrayHasKey('quote', $this->notifications->get_subscription_types());
|
||||
$this->assertArrayHasKey('topic', $this->notifications->get_subscription_types());
|
||||
|
||||
//get_subscription_types
|
||||
//get_subscription_methods
|
||||
}
|
||||
|
||||
public function test_subscriptions()
|
||||
{
|
||||
$this->notifications->add_subscription('post', 0, '');
|
||||
$this->notifications->add_subscription('post', 0, '', 1);
|
||||
$this->notifications->add_subscription('quote', 0, '', 1);
|
||||
|
||||
$this->notifications->add_subscription('post', 0, '', 2);
|
||||
$this->notifications->add_subscription('post', 0, 'email', 2);
|
||||
$this->notifications->add_subscription('post', 0, 'jabber', 2);
|
||||
$this->notifications->add_subscription('post', 1, '', 2);
|
||||
$this->notifications->add_subscription('post', 1, 'email', 2);
|
||||
$this->notifications->add_subscription('post', 1, 'jabber', 2);
|
||||
$this->notifications->add_subscription('post', 2, '', 2);
|
||||
$this->notifications->add_subscription('post', 2, 'email', 2);
|
||||
$this->notifications->add_subscription('post', 2, 'jabber', 2);
|
||||
|
||||
$this->assertEquals(array(
|
||||
array(
|
||||
'item_type' => 'post',
|
||||
'item_id' => 0,
|
||||
'user_id' => 0,
|
||||
'method' => '',
|
||||
),
|
||||
), $this->notifications->get_subscriptions());
|
||||
|
||||
$this->assertEquals(array(
|
||||
array(
|
||||
'item_type' => 'post',
|
||||
'item_id' => 0,
|
||||
'user_id' => 1,
|
||||
'method' => '',
|
||||
),
|
||||
array(
|
||||
'item_type' => 'quote',
|
||||
'item_id' => 0,
|
||||
'user_id' => 1,
|
||||
'method' => '',
|
||||
),
|
||||
), $this->notifications->get_subscriptions(1));
|
||||
|
||||
$this->assertEquals(array(
|
||||
array(
|
||||
'item_type' => 'post',
|
||||
'item_id' => 0,
|
||||
'user_id' => 2,
|
||||
'method' => '',
|
||||
),
|
||||
array(
|
||||
'item_type' => 'post',
|
||||
'item_id' => 0,
|
||||
'user_id' => 2,
|
||||
'method' => 'email',
|
||||
),
|
||||
array(
|
||||
'item_type' => 'post',
|
||||
'item_id' => 0,
|
||||
'user_id' => 2,
|
||||
'method' => 'jabber',
|
||||
),
|
||||
array(
|
||||
'item_type' => 'post',
|
||||
'item_id' => 1,
|
||||
'user_id' => 2,
|
||||
'method' => '',
|
||||
),
|
||||
array(
|
||||
'item_type' => 'post',
|
||||
'item_id' => 1,
|
||||
'user_id' => 2,
|
||||
'method' => 'email',
|
||||
),
|
||||
array(
|
||||
'item_type' => 'post',
|
||||
'item_id' => 1,
|
||||
'user_id' => 2,
|
||||
'method' => 'jabber',
|
||||
),
|
||||
array(
|
||||
'item_type' => 'post',
|
||||
'item_id' => 2,
|
||||
'user_id' => 2,
|
||||
'method' => '',
|
||||
),
|
||||
array(
|
||||
'item_type' => 'post',
|
||||
'item_id' => 2,
|
||||
'user_id' => 2,
|
||||
'method' => 'email',
|
||||
),
|
||||
array(
|
||||
'item_type' => 'post',
|
||||
'item_id' => 2,
|
||||
'user_id' => 2,
|
||||
'method' => 'jabber',
|
||||
),
|
||||
), $this->notifications->get_subscriptions(2));
|
||||
|
||||
$this->assertEquals(array(
|
||||
'post' => array(
|
||||
'',
|
||||
'email',
|
||||
'jabber',
|
||||
),
|
||||
), $this->notifications->get_subscriptions(2, true));
|
||||
|
||||
$this->notifications->delete_subscription('post', 0, '', 2);
|
||||
$this->notifications->delete_subscription('post', 1, 'email', 2);
|
||||
$this->notifications->delete_subscription('post', 2, 'jabber', 2);
|
||||
|
||||
$this->assertEquals(array(
|
||||
array(
|
||||
'item_type' => 'post',
|
||||
'item_id' => 0,
|
||||
'user_id' => 2,
|
||||
'method' => 'email',
|
||||
),
|
||||
array(
|
||||
'item_type' => 'post',
|
||||
'item_id' => 0,
|
||||
'user_id' => 2,
|
||||
'method' => 'jabber',
|
||||
),
|
||||
array(
|
||||
'item_type' => 'post',
|
||||
'item_id' => 1,
|
||||
'user_id' => 2,
|
||||
'method' => '',
|
||||
),
|
||||
array(
|
||||
'item_type' => 'post',
|
||||
'item_id' => 1,
|
||||
'user_id' => 2,
|
||||
'method' => 'jabber',
|
||||
),
|
||||
array(
|
||||
'item_type' => 'post',
|
||||
'item_id' => 2,
|
||||
'user_id' => 2,
|
||||
'method' => '',
|
||||
),
|
||||
array(
|
||||
'item_type' => 'post',
|
||||
'item_id' => 2,
|
||||
'user_id' => 2,
|
||||
'method' => 'email',
|
||||
),
|
||||
), $this->notifications->get_subscriptions(2));
|
||||
}
|
||||
|
||||
public function test_notifications()
|
||||
{
|
||||
$this->assertEquals(array(
|
||||
'notifications' => array(),
|
||||
'unread_count' => 0,
|
||||
), $this->notifications->load_notifications(array(
|
||||
'count_unread' => true,
|
||||
)));
|
||||
|
||||
$this->notifications->add_notifications('ext_test-test', array(
|
||||
'post_id' => '1',
|
||||
'topic_id' => '1',
|
||||
'post_time' => 1349413321,
|
||||
));
|
||||
|
||||
$notifications = $this->notifications->load_notifications(array(
|
||||
'count_unread' => true,
|
||||
));
|
||||
|
||||
$this->assertEquals(1, $notifications['unread_count']);
|
||||
|
||||
$notifications = $notifications['notifications'];
|
||||
|
||||
$expected = array(
|
||||
1 => array(
|
||||
'item_type' => 'ext_test-test',
|
||||
'item_id' => 1,
|
||||
'item_parent_id' => 1,
|
||||
'user_id' => 0,
|
||||
'unread' => 1,
|
||||
'time' => 1349413321,
|
||||
'data' => array(),
|
||||
),
|
||||
);
|
||||
|
||||
$i = 0;
|
||||
foreach ($expected as $notification_id => $notification_data)
|
||||
{
|
||||
//echo $notifications[$i];
|
||||
|
||||
$this->assertEquals($notification_id, $notifications[$i]->notification_id);
|
||||
|
||||
foreach ($notification_data as $key => $value)
|
||||
{
|
||||
$this->assertEquals($value, $notifications[$i]->$key);
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
$notification = $this->notifications->get_item_type_class('phpbb_ext_test_notification_type_test');
|
||||
$notification->set_initial_data(array(
|
||||
'notification_id' => '1',
|
||||
));
|
||||
$notification->create_insert_array($notification_data);
|
||||
|
||||
$this->dump($this->notifications->load_notifications());
|
||||
$this->dump(array('notifications' => $notification));
|
||||
|
||||
$this->assertEquals(array(
|
||||
'notifications' => array(
|
||||
$notification,
|
||||
),
|
||||
'unread_count' => 0,
|
||||
), $this->notifications->load_notifications());*/
|
||||
}
|
||||
|
||||
private function dump($array, $pre = '')
|
||||
{
|
||||
echo ($pre == '') ? "\n------------------------------------------------\n" : '';
|
||||
|
||||
foreach ($array as $key => $value)
|
||||
{
|
||||
echo $pre . $key . ' => ';
|
||||
|
||||
if (is_array($value))
|
||||
{
|
||||
echo "\n";
|
||||
|
||||
$this->dump($value, $pre . "\t");
|
||||
}
|
||||
else
|
||||
{
|
||||
echo (string) $value;
|
||||
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue