aboutsummaryrefslogtreecommitdiffstats
path: root/tests/notification/notification.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/notification/notification.php')
-rw-r--r--tests/notification/notification.php285
1 files changed, 131 insertions, 154 deletions
diff --git a/tests/notification/notification.php b/tests/notification/notification.php
index 13fc99bed3..0bb69dc2c5 100644
--- a/tests/notification/notification.php
+++ b/tests/notification/notification.php
@@ -95,13 +95,20 @@ class phpbb_notification_test extends phpbb_database_test_case
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());
+ $subscription_types = $this->notifications->get_subscription_types();
+
+ $this->assertArrayHasKey('NOTIFICATION_GROUP_MISCELLANEOUS', $subscription_types);
+ $this->assertArrayHasKey('NOTIFICATION_GROUP_POSTING', $subscription_types);
+
+ $this->assertArrayHasKey('phpbb_notification_type_bookmark', $subscription_types['NOTIFICATION_GROUP_POSTING']);
+ $this->assertArrayHasKey('phpbb_notification_type_post', $subscription_types['NOTIFICATION_GROUP_POSTING']);
+ $this->assertArrayHasKey('phpbb_notification_type_quote', $subscription_types['NOTIFICATION_GROUP_POSTING']);
+ $this->assertArrayHasKey('phpbb_notification_type_topic', $subscription_types['NOTIFICATION_GROUP_POSTING']);
+
+ $this->assertArrayHasKey('moderation_queue', $subscription_types['NOTIFICATION_GROUP_POSTING']);
+
+ $this->assertArrayHasKey('phpbb_notification_type_pm', $subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']);
+ $this->assertArrayHasKey('phpbb_ext_test_notification_type_test', $subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']);
//get_subscription_types
//get_subscription_methods
@@ -109,23 +116,23 @@ class phpbb_notification_test extends phpbb_database_test_case
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->notifications->add_subscription('phpbb_notification_type_post', 0, '');
+ $this->notifications->add_subscription('phpbb_notification_type_post', 0, '', 1);
+ $this->notifications->add_subscription('phpbb_notification_type_quote', 0, '', 1);
+
+ $this->notifications->add_subscription('phpbb_notification_type_post', 0, '', 2);
+ $this->notifications->add_subscription('phpbb_notification_type_post', 0, 'email', 2);
+ $this->notifications->add_subscription('phpbb_notification_type_post', 0, 'jabber', 2);
+ $this->notifications->add_subscription('phpbb_notification_type_post', 1, '', 2);
+ $this->notifications->add_subscription('phpbb_notification_type_post', 1, 'email', 2);
+ $this->notifications->add_subscription('phpbb_notification_type_post', 1, 'jabber', 2);
+ $this->notifications->add_subscription('phpbb_notification_type_post', 2, '', 2);
+ $this->notifications->add_subscription('phpbb_notification_type_post', 2, 'email', 2);
+ $this->notifications->add_subscription('phpbb_notification_type_post', 2, 'jabber', 2);
$this->assertEquals(array(
array(
- 'item_type' => 'post',
+ 'item_type' => 'phpbb_notification_type_post',
'item_id' => 0,
'user_id' => 0,
'method' => '',
@@ -134,13 +141,13 @@ class phpbb_notification_test extends phpbb_database_test_case
$this->assertEquals(array(
array(
- 'item_type' => 'post',
+ 'item_type' => 'phpbb_notification_type_post',
'item_id' => 0,
'user_id' => 1,
'method' => '',
),
array(
- 'item_type' => 'quote',
+ 'item_type' => 'phpbb_notification_type_quote',
'item_id' => 0,
'user_id' => 1,
'method' => '',
@@ -149,55 +156,55 @@ class phpbb_notification_test extends phpbb_database_test_case
$this->assertEquals(array(
array(
- 'item_type' => 'post',
+ 'item_type' => 'phpbb_notification_type_post',
'item_id' => 0,
'user_id' => 2,
'method' => '',
),
array(
- 'item_type' => 'post',
+ 'item_type' => 'phpbb_notification_type_post',
'item_id' => 0,
'user_id' => 2,
'method' => 'email',
),
array(
- 'item_type' => 'post',
+ 'item_type' => 'phpbb_notification_type_post',
'item_id' => 0,
'user_id' => 2,
'method' => 'jabber',
),
array(
- 'item_type' => 'post',
+ 'item_type' => 'phpbb_notification_type_post',
'item_id' => 1,
'user_id' => 2,
'method' => '',
),
array(
- 'item_type' => 'post',
+ 'item_type' => 'phpbb_notification_type_post',
'item_id' => 1,
'user_id' => 2,
'method' => 'email',
),
array(
- 'item_type' => 'post',
+ 'item_type' => 'phpbb_notification_type_post',
'item_id' => 1,
'user_id' => 2,
'method' => 'jabber',
),
array(
- 'item_type' => 'post',
+ 'item_type' => 'phpbb_notification_type_post',
'item_id' => 2,
'user_id' => 2,
'method' => '',
),
array(
- 'item_type' => 'post',
+ 'item_type' => 'phpbb_notification_type_post',
'item_id' => 2,
'user_id' => 2,
'method' => 'email',
),
array(
- 'item_type' => 'post',
+ 'item_type' => 'phpbb_notification_type_post',
'item_id' => 2,
'user_id' => 2,
'method' => 'jabber',
@@ -205,50 +212,50 @@ class phpbb_notification_test extends phpbb_database_test_case
), $this->notifications->get_subscriptions(2));
$this->assertEquals(array(
- 'post' => array(
+ 'phpbb_notification_type_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->notifications->delete_subscription('phpbb_notification_type_post', 0, '', 2);
+ $this->notifications->delete_subscription('phpbb_notification_type_post', 1, 'email', 2);
+ $this->notifications->delete_subscription('phpbb_notification_type_post', 2, 'jabber', 2);
$this->assertEquals(array(
array(
- 'item_type' => 'post',
+ 'item_type' => 'phpbb_notification_type_post',
'item_id' => 0,
'user_id' => 2,
'method' => 'email',
),
array(
- 'item_type' => 'post',
+ 'item_type' => 'phpbb_notification_type_post',
'item_id' => 0,
'user_id' => 2,
'method' => 'jabber',
),
array(
- 'item_type' => 'post',
+ 'item_type' => 'phpbb_notification_type_post',
'item_id' => 1,
'user_id' => 2,
'method' => '',
),
array(
- 'item_type' => 'post',
+ 'item_type' => 'phpbb_notification_type_post',
'item_id' => 1,
'user_id' => 2,
'method' => 'jabber',
),
array(
- 'item_type' => 'post',
+ 'item_type' => 'phpbb_notification_type_post',
'item_id' => 2,
'user_id' => 2,
'method' => '',
),
array(
- 'item_type' => 'post',
+ 'item_type' => 'phpbb_notification_type_post',
'item_id' => 2,
'user_id' => 2,
'method' => 'email',
@@ -260,7 +267,7 @@ class phpbb_notification_test extends phpbb_database_test_case
{
global $db;
- $this->notifications->add_subscription('ext_test-test');
+ $this->notifications->add_subscription('phpbb_ext_test_notification_type_test');
// Used to test post notifications later
$db->sql_query('INSERT INTO ' . TOPICS_WATCH_TABLE . ' ' . $db->sql_build_array('INSERT', array(
@@ -277,25 +284,25 @@ class phpbb_notification_test extends phpbb_database_test_case
'count_unread' => true,
)));
- $this->notifications->add_notifications('ext_test-test', array(
+ $this->notifications->add_notifications('phpbb_ext_test_notification_type_test', array(
'post_id' => '1',
'topic_id' => '1',
'post_time' => 1349413321,
));
- $this->notifications->add_notifications('ext_test-test', array(
+ $this->notifications->add_notifications('phpbb_ext_test_notification_type_test', array(
'post_id' => '2',
'topic_id' => '2',
'post_time' => 1349413322,
));
- $this->notifications->add_notifications('ext_test-test', array(
+ $this->notifications->add_notifications('phpbb_ext_test_notification_type_test', array(
'post_id' => '3',
'topic_id' => '2',
'post_time' => 1349413323,
));
- $this->notifications->add_notifications(array('quote', 'bookmark', 'post', 'ext_test-test'), array(
+ $this->notifications->add_notifications(array('phpbb_notification_type_quote', 'phpbb_notification_type_bookmark', 'phpbb_notification_type_post', 'phpbb_ext_test_notification_type_test'), array(
'post_id' => '4',
'topic_id' => '2',
'post_time' => 1349413324,
@@ -310,9 +317,9 @@ class phpbb_notification_test extends phpbb_database_test_case
'topic_id' => 2,
'user_id' => 0,
)));
- $this->notifications->add_subscription('bookmark');
+ $this->notifications->add_subscription('phpbb_notification_type_bookmark');
- $this->notifications->add_notifications(array('quote', 'bookmark', 'post', 'ext_test-test'), array(
+ $this->notifications->add_notifications(array('phpbb_notification_type_quote', 'phpbb_notification_type_bookmark', 'phpbb_notification_type_post', 'phpbb_ext_test_notification_type_test'), array(
'post_id' => '5',
'topic_id' => '2',
'post_time' => 1349413325,
@@ -323,9 +330,9 @@ class phpbb_notification_test extends phpbb_database_test_case
'forum_name' => 'Your first forum',
));
- $this->notifications->delete_subscription('ext_test-test');
+ $this->notifications->delete_subscription('phpbb_ext_test_notification_type_test');
- $this->notifications->add_notifications('ext_test-test', array(
+ $this->notifications->add_notifications('phpbb_ext_test_notification_type_test', array(
'post_id' => '6',
'topic_id' => '2',
'post_time' => 1349413326,
@@ -336,13 +343,40 @@ class phpbb_notification_test extends phpbb_database_test_case
));
$expected = array(
- 5 => array(
- 'item_type' => 'bookmark',
- 'item_id' => 5,
+ 1 => array(
+ 'item_type' => 'phpbb_ext_test_notification_type_test',
+ 'item_id' => 1,
+ 'item_parent_id' => 1,
+ 'user_id' => 0,
+ 'unread' => 1,
+ 'time' => 1349413321,
+ 'data' => array(),
+ ),
+ 2 => array(
+ 'item_type' => 'phpbb_ext_test_notification_type_test',
+ 'item_id' => 2,
'item_parent_id' => 2,
'user_id' => 0,
'unread' => 1,
- 'time' => 1349413325,
+ 'time' => 1349413322,
+ 'data' => array(),
+ ),
+ 3 => array(
+ 'item_type' => 'phpbb_ext_test_notification_type_test',
+ 'item_id' => 3,
+ 'item_parent_id' => 2,
+ 'user_id' => 0,
+ 'unread' => 1,
+ 'time' => 1349413323,
+ 'data' => array(),
+ ),
+ 4 => array(
+ 'item_type' => 'phpbb_notification_type_post',
+ 'item_id' => 4,
+ 'item_parent_id' => 2,
+ 'user_id' => 0,
+ 'unread' => 1,
+ 'time' => 1349413324,
'data' => array(
'poster_id' => 2,
'topic_title' => 'test-title',
@@ -352,13 +386,13 @@ class phpbb_notification_test extends phpbb_database_test_case
'forum_name' => 'Your first forum',
),
),
- 4 => array(
- 'item_type' => 'post',
- 'item_id' => 4,
+ 5 => array(
+ 'item_type' => 'phpbb_notification_type_bookmark',
+ 'item_id' => 5,
'item_parent_id' => 2,
'user_id' => 0,
'unread' => 1,
- 'time' => 1349413324,
+ 'time' => 1349413325,
'data' => array(
'poster_id' => 2,
'topic_title' => 'test-title',
@@ -368,72 +402,41 @@ class phpbb_notification_test extends phpbb_database_test_case
'forum_name' => 'Your first forum',
),
),
- 3 => array(
- 'item_type' => 'ext_test-test',
- 'item_id' => 3,
- 'item_parent_id' => 2,
- 'user_id' => 0,
- 'unread' => 1,
- 'time' => 1349413323,
- 'data' => array(),
- ),
- 2 => array(
- 'item_type' => 'ext_test-test',
- 'item_id' => 2,
- 'item_parent_id' => 2,
- 'user_id' => 0,
- 'unread' => 1,
- 'time' => 1349413322,
- 'data' => array(),
- ),
- 1 => array(
- 'item_type' => 'ext_test-test',
- 'item_id' => 1,
- 'item_parent_id' => 1,
- 'user_id' => 0,
- 'unread' => 1,
- 'time' => 1349413321,
- 'data' => array(),
- ),
);
$this->assertEquals(sizeof($expected), $notifications['unread_count']);
$notifications = $notifications['notifications'];
- $i = 0;
foreach ($expected as $notification_id => $notification_data)
{
- //echo $notifications[$i];
+ //echo $notifications[$notification_id];
- $this->assertEquals($notification_id, $notifications[$i]->notification_id, 'notification_id');
+ $this->assertEquals($notification_id, $notifications[$notification_id]->notification_id, 'notification_id');
foreach ($notification_data as $key => $value)
{
- $this->assertEquals($value, $notifications[$i]->$key, $key . ' ' . $notification_id);
+ $this->assertEquals($value, $notifications[$notification_id]->$key, $key . ' ' . $notification_id);
}
-
- $i++;
}
// Now test updating -------------------------------
- $this->notifications->update_notifications('ext_test-test', array(
+ $this->notifications->update_notifications('phpbb_ext_test_notification_type_test', array(
'post_id' => '1',
'topic_id' => '2', // change parent_id
'post_time' => 1349413321,
));
- $this->notifications->update_notifications('ext_test-test', array(
+ $this->notifications->update_notifications('phpbb_ext_test_notification_type_test', array(
'post_id' => '3',
'topic_id' => '2',
- 'post_time' => 1234, // change post_time
+ 'post_time' => 1234, // change time
));
- $this->notifications->update_notifications(array('quote', 'bookmark', 'post', 'ext_test-test'), array(
+ $this->notifications->update_notifications(array('phpbb_notification_type_quote', 'phpbb_notification_type_bookmark', 'phpbb_notification_type_post', 'phpbb_ext_test_notification_type_test'), array(
'post_id' => '5',
'topic_id' => '2',
- 'post_time' => 12345, // change post_time
'poster_id' => 2,
'topic_title' => 'test-title2', // change topic_title
'post_subject' => 'Re: test-title2', // change post_subject
@@ -446,24 +449,17 @@ class phpbb_notification_test extends phpbb_database_test_case
));
$expected = array(
- 4 => array(
- 'item_type' => 'post',
- 'item_id' => 4,
+ 1 => array(
+ 'item_type' => 'phpbb_ext_test_notification_type_test',
+ 'item_id' => 1,
'item_parent_id' => 2,
'user_id' => 0,
'unread' => 1,
- 'time' => 1349413324,
- 'data' => array(
- 'poster_id' => 2,
- 'topic_title' => 'test-title',
- 'post_subject' => 'Re: test-title',
- 'post_username' => '',
- 'forum_id' => 2,
- 'forum_name' => 'Your first forum',
- ),
+ 'time' => 1349413321,
+ 'data' => array(),
),
2 => array(
- 'item_type' => 'ext_test-test',
+ 'item_type' => 'phpbb_ext_test_notification_type_test',
'item_id' => 2,
'item_parent_id' => 2,
'user_id' => 0,
@@ -471,22 +467,38 @@ class phpbb_notification_test extends phpbb_database_test_case
'time' => 1349413322,
'data' => array(),
),
- 1 => array(
- 'item_type' => 'ext_test-test',
- 'item_id' => 1,
+ 3 => array(
+ 'item_type' => 'phpbb_ext_test_notification_type_test',
+ 'item_id' => 3,
'item_parent_id' => 2,
'user_id' => 0,
'unread' => 1,
- 'time' => 1349413321,
+ 'time' => 1234,
'data' => array(),
),
+ 4 => array(
+ 'item_type' => 'phpbb_notification_type_post',
+ 'item_id' => 4,
+ 'item_parent_id' => 2,
+ 'user_id' => 0,
+ 'unread' => 1,
+ 'time' => 1349413324,
+ 'data' => array(
+ 'poster_id' => 2,
+ 'topic_title' => 'test-title',
+ 'post_subject' => 'Re: test-title',
+ 'post_username' => '',
+ 'forum_id' => 2,
+ 'forum_name' => 'Your first forum',
+ ),
+ ),
5 => array(
- 'item_type' => 'bookmark',
+ 'item_type' => 'phpbb_notification_type_bookmark',
'item_id' => 5,
'item_parent_id' => 2,
'user_id' => 0,
'unread' => 1,
- 'time' => 12345,
+ 'time' => 1349413325,
'data' => array(
'poster_id' => 2,
'topic_title' => 'test-title2',
@@ -496,56 +508,21 @@ class phpbb_notification_test extends phpbb_database_test_case
'forum_name' => 'Your second forum',
),
),
- 3 => array(
- 'item_type' => 'ext_test-test',
- 'item_id' => 3,
- 'item_parent_id' => 2,
- 'user_id' => 0,
- 'unread' => 1,
- 'time' => 1234,
- 'data' => array(),
- ),
);
$this->assertEquals(sizeof($expected), $notifications['unread_count']);
$notifications = $notifications['notifications'];
- $i = 0;
foreach ($expected as $notification_id => $notification_data)
{
- //echo $notifications[$i];
+ //echo $notifications[$notification_id];
- $this->assertEquals($notification_id, $notifications[$i]->notification_id, 'notification_id');
+ $this->assertEquals($notification_id, $notifications[$notification_id]->notification_id, 'notification_id');
foreach ($notification_data as $key => $value)
{
- $this->assertEquals($value, $notifications[$i]->$key, $key . ' ' . $notification_id);
- }
-
- $i++;
- }
- }
-
- 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";
+ $this->assertEquals($value, $notifications[$notification_id]->$key, $key . ' ' . $notification_id);
}
}
}