mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 06:08:52 +00:00
[ticket/11405] Add unit tests for quoted users notifications
PHPBB3-11405
This commit is contained in:
parent
7d5949ae3d
commit
499eded880
3 changed files with 279 additions and 1 deletions
|
@ -33,6 +33,13 @@
|
||||||
<value>1</value>
|
<value>1</value>
|
||||||
<value></value>
|
<value></value>
|
||||||
</row>
|
</row>
|
||||||
|
<row>
|
||||||
|
<value>quote</value>
|
||||||
|
<value>5</value>
|
||||||
|
<value>1</value>
|
||||||
|
<value>1</value>
|
||||||
|
<value></value>
|
||||||
|
</row>
|
||||||
<row>
|
<row>
|
||||||
<value>post</value>
|
<value>post</value>
|
||||||
<value>8</value>
|
<value>8</value>
|
||||||
|
@ -73,6 +80,62 @@
|
||||||
<value>0</value>
|
<value>0</value>
|
||||||
</row>
|
</row>
|
||||||
</table>
|
</table>
|
||||||
|
<table name="phpbb_users">
|
||||||
|
<column>user_id</column>
|
||||||
|
<column>username_clean</column>
|
||||||
|
<column>user_permissions</column>
|
||||||
|
<column>user_sig</column>
|
||||||
|
<column>user_occ</column>
|
||||||
|
<column>user_interests</column>
|
||||||
|
<row>
|
||||||
|
<value>2</value>
|
||||||
|
<value>poster</value>
|
||||||
|
<value></value>
|
||||||
|
<value></value>
|
||||||
|
<value></value>
|
||||||
|
<value></value>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<value>3</value>
|
||||||
|
<value>test</value>
|
||||||
|
<value></value>
|
||||||
|
<value></value>
|
||||||
|
<value></value>
|
||||||
|
<value></value>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<value>4</value>
|
||||||
|
<value>unauthorized</value>
|
||||||
|
<value></value>
|
||||||
|
<value></value>
|
||||||
|
<value></value>
|
||||||
|
<value></value>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<value>5</value>
|
||||||
|
<value>notified</value>
|
||||||
|
<value></value>
|
||||||
|
<value></value>
|
||||||
|
<value></value>
|
||||||
|
<value></value>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<value>6</value>
|
||||||
|
<value>disabled</value>
|
||||||
|
<value></value>
|
||||||
|
<value></value>
|
||||||
|
<value></value>
|
||||||
|
<value></value>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<value>7</value>
|
||||||
|
<value>default</value>
|
||||||
|
<value></value>
|
||||||
|
<value></value>
|
||||||
|
<value></value>
|
||||||
|
<value></value>
|
||||||
|
</row>
|
||||||
|
</table>
|
||||||
<table name="phpbb_user_notifications">
|
<table name="phpbb_user_notifications">
|
||||||
<column>item_type</column>
|
<column>item_type</column>
|
||||||
<column>item_id</column>
|
<column>item_id</column>
|
||||||
|
@ -86,6 +149,13 @@
|
||||||
<value></value>
|
<value></value>
|
||||||
<value>1</value>
|
<value>1</value>
|
||||||
</row>
|
</row>
|
||||||
|
<row>
|
||||||
|
<value>quote</value>
|
||||||
|
<value>0</value>
|
||||||
|
<value>2</value>
|
||||||
|
<value></value>
|
||||||
|
<value>1</value>
|
||||||
|
</row>
|
||||||
<row>
|
<row>
|
||||||
<value>post</value>
|
<value>post</value>
|
||||||
<value>0</value>
|
<value>0</value>
|
||||||
|
@ -93,6 +163,13 @@
|
||||||
<value></value>
|
<value></value>
|
||||||
<value>1</value>
|
<value>1</value>
|
||||||
</row>
|
</row>
|
||||||
|
<row>
|
||||||
|
<value>quote</value>
|
||||||
|
<value>0</value>
|
||||||
|
<value>3</value>
|
||||||
|
<value></value>
|
||||||
|
<value>1</value>
|
||||||
|
</row>
|
||||||
<row>
|
<row>
|
||||||
<value>post</value>
|
<value>post</value>
|
||||||
<value>0</value>
|
<value>0</value>
|
||||||
|
@ -100,6 +177,13 @@
|
||||||
<value></value>
|
<value></value>
|
||||||
<value>1</value>
|
<value>1</value>
|
||||||
</row>
|
</row>
|
||||||
|
<row>
|
||||||
|
<value>quote</value>
|
||||||
|
<value>0</value>
|
||||||
|
<value>4</value>
|
||||||
|
<value></value>
|
||||||
|
<value>1</value>
|
||||||
|
</row>
|
||||||
<row>
|
<row>
|
||||||
<value>post</value>
|
<value>post</value>
|
||||||
<value>0</value>
|
<value>0</value>
|
||||||
|
@ -107,6 +191,13 @@
|
||||||
<value></value>
|
<value></value>
|
||||||
<value>1</value>
|
<value>1</value>
|
||||||
</row>
|
</row>
|
||||||
|
<row>
|
||||||
|
<value>quote</value>
|
||||||
|
<value>0</value>
|
||||||
|
<value>5</value>
|
||||||
|
<value></value>
|
||||||
|
<value>1</value>
|
||||||
|
</row>
|
||||||
<row>
|
<row>
|
||||||
<value>post</value>
|
<value>post</value>
|
||||||
<value>0</value>
|
<value>0</value>
|
||||||
|
@ -114,6 +205,13 @@
|
||||||
<value></value>
|
<value></value>
|
||||||
<value>1</value>
|
<value>1</value>
|
||||||
</row>
|
</row>
|
||||||
|
<row>
|
||||||
|
<value>quote</value>
|
||||||
|
<value>0</value>
|
||||||
|
<value>6</value>
|
||||||
|
<value></value>
|
||||||
|
<value>0</value>
|
||||||
|
</row>
|
||||||
<row>
|
<row>
|
||||||
<value>post</value>
|
<value>post</value>
|
||||||
<value>0</value>
|
<value>0</value>
|
||||||
|
|
|
@ -12,7 +12,7 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php';
|
||||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_posting.php';
|
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_posting.php';
|
||||||
require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
|
require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
|
||||||
|
|
||||||
class phpbb_notification_submit_post_notifications_test extends phpbb_database_test_case
|
class phpbb_notification_submit_post_type_post_test extends phpbb_database_test_case
|
||||||
{
|
{
|
||||||
protected $notifications, $db, $container, $user, $config, $auth, $cache;
|
protected $notifications, $db, $container, $user, $config, $auth, $cache;
|
||||||
|
|
180
tests/notification/submit_post_type_quote_test.php
Normal file
180
tests/notification/submit_post_type_quote_test.php
Normal file
|
@ -0,0 +1,180 @@
|
||||||
|
<?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_type_quote_test 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),
|
||||||
|
)));
|
||||||
|
|
||||||
|
$auth->expects($this->any())
|
||||||
|
->method('acl_get_list')
|
||||||
|
->with($this->anything(),
|
||||||
|
$this->stringContains('_'),
|
||||||
|
$this->greaterThan(0))
|
||||||
|
->will($this->returnValueMap(array(
|
||||||
|
array(
|
||||||
|
array('3', '4', '5', '6', '7'),
|
||||||
|
'f_read',
|
||||||
|
1,
|
||||||
|
array(
|
||||||
|
1 => array(
|
||||||
|
'f_read' => array(3, 5, 6, 7),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)));
|
||||||
|
|
||||||
|
// 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* submit_post() Notifications test
|
||||||
|
*
|
||||||
|
* submit_post() $mode = 'reply'
|
||||||
|
* Notification item_type = 'quote'
|
||||||
|
*
|
||||||
|
* User => State description
|
||||||
|
* 2 => Poster, should NOT receive a notification
|
||||||
|
* 3 => Quoted, should receive a notification
|
||||||
|
* 4 => Quoted, but unauthed to read, should NOT receive a notification
|
||||||
|
* 5 => Quoted, but already notified, should NOT receive a new notification
|
||||||
|
* 6 => Quoted, but option disabled, should NOT receive a notification
|
||||||
|
* 7 => Quoted, option set to default, should receive a notification
|
||||||
|
*/
|
||||||
|
public function test_type_quote()
|
||||||
|
{
|
||||||
|
$sql = 'SELECT user_id, item_id, item_parent_id
|
||||||
|
FROM ' . NOTIFICATIONS_TABLE . "
|
||||||
|
WHERE item_type = 'quote'
|
||||||
|
ORDER BY user_id, item_id ASC";
|
||||||
|
$result = $this->db->sql_query($sql);
|
||||||
|
$this->assertEquals(array(
|
||||||
|
array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1),
|
||||||
|
), $this->db->sql_fetchrowset($result));
|
||||||
|
$this->db->sql_freeresult($result);
|
||||||
|
|
||||||
|
$poll = array();
|
||||||
|
$data = array(
|
||||||
|
'forum_id' => 1,
|
||||||
|
'topic_id' => 1,
|
||||||
|
'topic_title' => 'topic_title',
|
||||||
|
'icon_id' => 0,
|
||||||
|
'enable_bbcode' => 0,
|
||||||
|
'enable_smilies' => 0,
|
||||||
|
'enable_urls' => 0,
|
||||||
|
'enable_sig' => 0,
|
||||||
|
'message' => implode(' ', array(
|
||||||
|
'[quote="poster":uid]poster should not be notified[/quote:uid]',
|
||||||
|
'[quote="test":uid]test should be notified[/quote:uid]',
|
||||||
|
'[quote="unauthorized":uid]unauthorized to read, should not receive a notification[/quote:uid]',
|
||||||
|
'[quote="notified":uid]already notified, should not receive a new notification[/quote:uid]',
|
||||||
|
'[quote="disabled":uid]option disabled, should not receive a notification[/quote:uid]',
|
||||||
|
'[quote="default":uid]option set to default, should receive a notification[/quote:uid]',
|
||||||
|
'[quote="doesn\'t exist":uid]user does not exist, should not receive a notification[/quote:uid]',
|
||||||
|
)),
|
||||||
|
'message_md5' => '',
|
||||||
|
'attachment_data' => array(),
|
||||||
|
'bbcode_bitfield' => '',
|
||||||
|
'bbcode_uid' => 'uid',
|
||||||
|
'post_edit_locked' => false,
|
||||||
|
//'force_approved_state' => 1,
|
||||||
|
);
|
||||||
|
|
||||||
|
submit_post('reply', '', 'poster-name', POST_NORMAL, $poll, $data, false, false);
|
||||||
|
|
||||||
|
$sql = 'SELECT user_id, item_id, item_parent_id
|
||||||
|
FROM ' . NOTIFICATIONS_TABLE . "
|
||||||
|
WHERE item_type = 'quote'
|
||||||
|
ORDER BY user_id ASC, item_id ASC";
|
||||||
|
$result = $this->db->sql_query($sql);
|
||||||
|
$this->assertEquals(array(
|
||||||
|
array('user_id' => 3, 'item_id' => 1, 'item_parent_id' => 1),
|
||||||
|
array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1),
|
||||||
|
array('user_id' => 7, 'item_id' => 1, 'item_parent_id' => 1),
|
||||||
|
), $this->db->sql_fetchrowset($result));
|
||||||
|
$this->db->sql_freeresult($result);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue