[ticket/11405] Move test to submit_post_base.php and use data sets for testing

PHPBB3-11405
This commit is contained in:
Joas Schilling 2013-03-26 12:58:14 +01:00
parent 053c75543d
commit cdd45cb8ba
3 changed files with 155 additions and 111 deletions

View file

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

View file

@ -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,62 +44,53 @@ 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'
*
* User => State description
* 2 => Poster, should NOT receive a notification
* 3 => Topic subscribed, should receive a notification
* 4 => Topic subscribed, but unauthed to read, should NOT receive a notification
* 5 => Topic subscribed, but already notified, should NOT receive a new notification
* 6 => Topic and forum subscribed, should receive ONE notification
* 7 => Forum subscribed, should receive a notification
* 8 => Forum subscribed, but already notified, should NOT receive a new notification
*/ */
public function test_type_post() public function submit_post_data()
{ {
$sql = 'SELECT user_id, item_id, item_parent_id return array(
FROM ' . NOTIFICATIONS_TABLE . " /**
WHERE item_type = 'post' * Normal post
ORDER BY user_id, item_id ASC"; *
$result = $this->db->sql_query($sql); * User => State description
$this->assertEquals(array( * 2 => Poster, should NOT receive a notification
array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), * 3 => Topic subscribed, should receive a notification
array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1), * 4 => Topic subscribed, but unauthed to read, should NOT receive a notification
), $this->db->sql_fetchrowset($result)); * 5 => Topic subscribed, but already notified, should NOT receive a new notification
$this->db->sql_freeresult($result); * 6 => Topic and forum subscribed, should receive ONE notification
* 7 => Forum subscribed, should receive a notification
* 8 => Forum subscribed, but already notified, should NOT receive a new notification
*/
array(
array(),
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' => 3, 'item_id' => 2, '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' => 7, 'item_id' => 2, 'item_parent_id' => 1),
array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1),
),
),
$poll = array(); /**
$data = array( * Unapproved post
'forum_id' => 1, *
'topic_id' => 1, * No new notifications
'topic_title' => 'topic_title', */
'icon_id' => 0, array(
'enable_bbcode' => 0, array('force_approved_state' => false),
'enable_smilies' => 0, array(
'enable_urls' => 0, array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1),
'enable_sig' => 0, array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1),
'message' => '', ),
'message_md5' => '', array(
'attachment_data' => array(), array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1),
'bbcode_bitfield' => '', array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1),
'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' => 5, 'item_id' => 1, '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' => 8, 'item_id' => 1, 'item_parent_id' => 1),
), $this->db->sql_fetchrowset($result));
$this->db->sql_freeresult($result);
} }
} }

View file

@ -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,66 +44,70 @@ 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'
*
* 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() public function submit_post_data()
{ {
$sql = 'SELECT user_id, item_id, item_parent_id return array(
FROM ' . NOTIFICATIONS_TABLE . " /**
WHERE item_type = 'quote' * Normal post
ORDER BY user_id, item_id ASC"; *
$result = $this->db->sql_query($sql); * User => State description
$this->assertEquals(array( * 2 => Poster, should NOT receive a notification
array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), * 3 => Quoted, should receive a notification
), $this->db->sql_fetchrowset($result)); * 4 => Quoted, but unauthed to read, should NOT receive a notification
$this->db->sql_freeresult($result); * 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
*/
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',
),
array(
array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1),
),
array(
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' => 7, 'item_id' => 2, 'item_parent_id' => 1),
),
),
$poll = array(); /**
$data = array( * Unapproved post
'forum_id' => 1, *
'topic_id' => 1, * No new notifications
'topic_title' => 'topic_title', */
'icon_id' => 0, array(
'enable_bbcode' => 0, array(
'enable_smilies' => 0, 'message' => implode(' ', array(
'enable_urls' => 0, '[quote="poster":uid]poster should not be notified[/quote:uid]',
'enable_sig' => 0, '[quote="test":uid]test should be notified[/quote:uid]',
'message' => implode(' ', array( '[quote="unauthorized":uid]unauthorized to read, should not receive a notification[/quote:uid]',
'[quote="poster":uid]poster should not be notified[/quote:uid]', '[quote="notified":uid]already notified, should not receive a new notification[/quote:uid]',
'[quote="test":uid]test should be notified[/quote:uid]', '[quote="disabled":uid]option disabled, should not receive a notification[/quote:uid]',
'[quote="unauthorized":uid]unauthorized to read, should not receive a notification[/quote:uid]', '[quote="default":uid]option set to default, should receive a notification[/quote:uid]',
'[quote="notified":uid]already notified, should not receive a new notification[/quote:uid]', '[quote="doesn\'t exist":uid]user does not exist, should not receive a 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]', 'bbcode_uid' => 'uid',
'[quote="doesn\'t exist":uid]user does not exist, should not receive a notification[/quote:uid]', 'force_approved_state' => false,
)), ),
'message_md5' => '', array(
'attachment_data' => array(), array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1),
'bbcode_bitfield' => '', ),
'bbcode_uid' => 'uid', array(
'post_edit_locked' => false, array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1),
//'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' => 2, '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),
), $this->db->sql_fetchrowset($result));
$this->db->sql_freeresult($result);
} }
} }