mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 14:18:52 +00:00
[ticket/11405] Move test to submit_post_base.php and use data sets for testing
PHPBB3-11405
This commit is contained in:
parent
053c75543d
commit
cdd45cb8ba
3 changed files with 155 additions and 111 deletions
|
@ -16,6 +16,27 @@ class phpbb_notification_submit_post_base extends phpbb_database_test_case
|
||||||
{
|
{
|
||||||
protected $notifications, $db, $container, $user, $config, $auth, $cache;
|
protected $notifications, $db, $container, $user, $config, $auth, $cache;
|
||||||
|
|
||||||
|
protected $item_type = '';
|
||||||
|
|
||||||
|
protected $poll_data = array();
|
||||||
|
protected $post_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' => '',
|
||||||
|
'message_md5' => '',
|
||||||
|
'attachment_data' => array(),
|
||||||
|
'bbcode_bitfield' => '',
|
||||||
|
'bbcode_uid' => '',
|
||||||
|
'post_edit_locked' => false,
|
||||||
|
//'force_approved_state' => 1,
|
||||||
|
);
|
||||||
|
|
||||||
public function getDataSet()
|
public function getDataSet()
|
||||||
{
|
{
|
||||||
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/submit_post_notification.xml');
|
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/submit_post_notification.xml');
|
||||||
|
@ -81,7 +102,7 @@ class phpbb_notification_submit_post_base extends phpbb_database_test_case
|
||||||
$phpbb_container->set('notification_manager', $phpbb_notifications);
|
$phpbb_container->set('notification_manager', $phpbb_notifications);
|
||||||
|
|
||||||
// Notification Types
|
// Notification Types
|
||||||
$notification_types = array('quote', 'bookmark', 'post');
|
$notification_types = array('quote', 'bookmark', 'post', 'post_in_queue');
|
||||||
foreach ($notification_types as $type)
|
foreach ($notification_types as $type)
|
||||||
{
|
{
|
||||||
$class_name = 'phpbb_notification_type_' . $type;
|
$class_name = 'phpbb_notification_type_' . $type;
|
||||||
|
@ -91,4 +112,28 @@ class phpbb_notification_submit_post_base extends phpbb_database_test_case
|
||||||
NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE));
|
NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider submit_post_data
|
||||||
|
*/
|
||||||
|
public function test_submit_post($additional_post_data, $expected_before, $expected_after)
|
||||||
|
{
|
||||||
|
$sql = 'SELECT user_id, item_id, item_parent_id
|
||||||
|
FROM ' . NOTIFICATIONS_TABLE . "
|
||||||
|
WHERE item_type = '" . $this->item_type . "'
|
||||||
|
ORDER BY user_id, item_id ASC";
|
||||||
|
$result = $this->db->sql_query($sql);
|
||||||
|
$this->assertEquals($expected_before, $this->db->sql_fetchrowset($result));
|
||||||
|
$this->db->sql_freeresult($result);
|
||||||
|
|
||||||
|
submit_post('reply', '', 'poster-name', POST_NORMAL, $this->poll_data, array_merge($this->post_data, $additional_post_data), false, false);
|
||||||
|
|
||||||
|
$sql = 'SELECT user_id, item_id, item_parent_id
|
||||||
|
FROM ' . NOTIFICATIONS_TABLE . "
|
||||||
|
WHERE item_type = '" . $this->item_type . "'
|
||||||
|
ORDER BY user_id ASC, item_id ASC";
|
||||||
|
$result = $this->db->sql_query($sql);
|
||||||
|
$this->assertEquals($expected_after, $this->db->sql_fetchrowset($result));
|
||||||
|
$this->db->sql_freeresult($result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@ require_once dirname(__FILE__) . '/submit_post_base.php';
|
||||||
|
|
||||||
class phpbb_notification_submit_post_type_post_test extends phpbb_notification_submit_post_base
|
class phpbb_notification_submit_post_type_post_test extends phpbb_notification_submit_post_base
|
||||||
{
|
{
|
||||||
|
protected $item_type = 'post';
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
@ -42,6 +44,12 @@ class phpbb_notification_submit_post_type_post_test extends phpbb_notification_s
|
||||||
*
|
*
|
||||||
* submit_post() $mode = 'reply'
|
* submit_post() $mode = 'reply'
|
||||||
* Notification item_type = 'post'
|
* Notification item_type = 'post'
|
||||||
|
*/
|
||||||
|
public function submit_post_data()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
/**
|
||||||
|
* Normal post
|
||||||
*
|
*
|
||||||
* User => State description
|
* User => State description
|
||||||
* 2 => Poster, should NOT receive a notification
|
* 2 => Poster, should NOT receive a notification
|
||||||
|
@ -52,52 +60,37 @@ class phpbb_notification_submit_post_type_post_test extends phpbb_notification_s
|
||||||
* 7 => Forum subscribed, should receive a notification
|
* 7 => Forum subscribed, should receive a notification
|
||||||
* 8 => Forum subscribed, but already notified, should NOT receive a new notification
|
* 8 => Forum subscribed, but already notified, should NOT receive a new notification
|
||||||
*/
|
*/
|
||||||
public function test_type_post()
|
array(
|
||||||
{
|
array(),
|
||||||
$sql = 'SELECT user_id, item_id, item_parent_id
|
array(
|
||||||
FROM ' . NOTIFICATIONS_TABLE . "
|
|
||||||
WHERE item_type = 'post'
|
|
||||||
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),
|
array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1),
|
||||||
array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1),
|
array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1),
|
||||||
), $this->db->sql_fetchrowset($result));
|
),
|
||||||
$this->db->sql_freeresult($result);
|
array(
|
||||||
|
|
||||||
$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' => '',
|
|
||||||
'message_md5' => '',
|
|
||||||
'attachment_data' => array(),
|
|
||||||
'bbcode_bitfield' => '',
|
|
||||||
'bbcode_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 = 'post'
|
|
||||||
ORDER BY user_id ASC, item_id ASC";
|
|
||||||
$result = $this->db->sql_query($sql);
|
|
||||||
$this->assertEquals(array(
|
|
||||||
array('user_id' => 3, 'item_id' => 2, 'item_parent_id' => 1),
|
array('user_id' => 3, 'item_id' => 2, 'item_parent_id' => 1),
|
||||||
array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1),
|
array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1),
|
||||||
array('user_id' => 6, 'item_id' => 2, 'item_parent_id' => 1),
|
array('user_id' => 6, 'item_id' => 2, 'item_parent_id' => 1),
|
||||||
array('user_id' => 7, 'item_id' => 2, 'item_parent_id' => 1),
|
array('user_id' => 7, 'item_id' => 2, 'item_parent_id' => 1),
|
||||||
array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1),
|
array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1),
|
||||||
), $this->db->sql_fetchrowset($result));
|
),
|
||||||
$this->db->sql_freeresult($result);
|
),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unapproved post
|
||||||
|
*
|
||||||
|
* No new notifications
|
||||||
|
*/
|
||||||
|
array(
|
||||||
|
array('force_approved_state' => false),
|
||||||
|
array(
|
||||||
|
array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1),
|
||||||
|
array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1),
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1),
|
||||||
|
array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@ require_once dirname(__FILE__) . '/submit_post_base.php';
|
||||||
|
|
||||||
class phpbb_notification_submit_post_type_quote_test extends phpbb_notification_submit_post_base
|
class phpbb_notification_submit_post_type_quote_test extends phpbb_notification_submit_post_base
|
||||||
{
|
{
|
||||||
|
protected $item_type = 'quote';
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
@ -42,6 +44,12 @@ class phpbb_notification_submit_post_type_quote_test extends phpbb_notification_
|
||||||
*
|
*
|
||||||
* submit_post() $mode = 'reply'
|
* submit_post() $mode = 'reply'
|
||||||
* Notification item_type = 'quote'
|
* Notification item_type = 'quote'
|
||||||
|
*/
|
||||||
|
public function submit_post_data()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
/**
|
||||||
|
* Normal post
|
||||||
*
|
*
|
||||||
* User => State description
|
* User => State description
|
||||||
* 2 => Poster, should NOT receive a notification
|
* 2 => Poster, should NOT receive a notification
|
||||||
|
@ -51,28 +59,8 @@ class phpbb_notification_submit_post_type_quote_test extends phpbb_notification_
|
||||||
* 6 => Quoted, but option disabled, should NOT receive a notification
|
* 6 => Quoted, but option disabled, should NOT receive a notification
|
||||||
* 7 => Quoted, option set to default, should receive a notification
|
* 7 => Quoted, option set to default, should receive a notification
|
||||||
*/
|
*/
|
||||||
public function test_type_quote()
|
array(
|
||||||
{
|
array(
|
||||||
$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(
|
'message' => implode(' ', array(
|
||||||
'[quote="poster":uid]poster should not be notified[/quote:uid]',
|
'[quote="poster":uid]poster should not be notified[/quote:uid]',
|
||||||
'[quote="test":uid]test should be notified[/quote:uid]',
|
'[quote="test":uid]test should be notified[/quote:uid]',
|
||||||
|
@ -82,26 +70,44 @@ class phpbb_notification_submit_post_type_quote_test extends phpbb_notification_
|
||||||
'[quote="default":uid]option set to default, should 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]',
|
'[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',
|
'bbcode_uid' => 'uid',
|
||||||
'post_edit_locked' => false,
|
),
|
||||||
//'force_approved_state' => 1,
|
array(
|
||||||
);
|
array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1),
|
||||||
|
),
|
||||||
submit_post('reply', '', 'poster-name', POST_NORMAL, $poll, $data, false, false);
|
array(
|
||||||
|
|
||||||
$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' => 2, 'item_parent_id' => 1),
|
array('user_id' => 3, 'item_id' => 2, 'item_parent_id' => 1),
|
||||||
array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1),
|
array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1),
|
||||||
array('user_id' => 7, 'item_id' => 2, 'item_parent_id' => 1),
|
array('user_id' => 7, 'item_id' => 2, 'item_parent_id' => 1),
|
||||||
), $this->db->sql_fetchrowset($result));
|
),
|
||||||
$this->db->sql_freeresult($result);
|
),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unapproved post
|
||||||
|
*
|
||||||
|
* No new notifications
|
||||||
|
*/
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
'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]',
|
||||||
|
)),
|
||||||
|
'bbcode_uid' => 'uid',
|
||||||
|
'force_approved_state' => false,
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1),
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue