2012-10-05 00:07:48 -05:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
*
|
2014-05-27 20:18:06 +02:00
|
|
|
* This file is part of the phpBB Forum Software package.
|
|
|
|
*
|
|
|
|
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
|
|
|
* @license GNU General Public License, version 2 (GPL-2.0)
|
|
|
|
*
|
|
|
|
* For full copyright and license information, please see
|
|
|
|
* the docs/CREDITS.txt file.
|
2012-10-05 00:07:48 -05:00
|
|
|
*
|
|
|
|
*/
|
2013-01-15 12:10:07 -06:00
|
|
|
|
2013-07-26 13:08:53 -05:00
|
|
|
require_once dirname(__FILE__) . '/base.php';
|
2013-04-29 22:16:46 -05:00
|
|
|
|
2013-07-26 13:08:53 -05:00
|
|
|
class phpbb_notification_test extends phpbb_tests_notification_base
|
2012-10-05 00:07:48 -05:00
|
|
|
{
|
2012-11-20 18:14:48 -06:00
|
|
|
protected $notifications, $db, $container, $user, $config, $auth, $cache;
|
2012-10-05 00:07:48 -05:00
|
|
|
|
|
|
|
public function getDataSet()
|
|
|
|
{
|
|
|
|
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/notification.xml');
|
|
|
|
}
|
|
|
|
|
2013-04-30 21:10:04 -05:00
|
|
|
public function test_get_notification_type_id()
|
|
|
|
{
|
|
|
|
// They should be inserted the first time
|
2013-07-26 14:51:46 -05:00
|
|
|
$post_type_id = $this->notifications->get_notification_type_id('post');
|
|
|
|
$quote_type_id = $this->notifications->get_notification_type_id('quote');
|
|
|
|
$test_type_id = $this->notifications->get_notification_type_id('test');
|
2013-04-30 21:10:04 -05:00
|
|
|
|
|
|
|
$this->assertEquals(array(
|
2013-07-26 14:51:46 -05:00
|
|
|
'test' => $test_type_id,
|
|
|
|
'quote' => $quote_type_id,
|
|
|
|
'post' => $post_type_id,
|
2013-04-30 21:10:04 -05:00
|
|
|
),
|
|
|
|
$this->notifications->get_notification_type_ids(array(
|
|
|
|
'test',
|
|
|
|
'quote',
|
|
|
|
'post',
|
|
|
|
)
|
|
|
|
));
|
2013-07-26 14:51:46 -05:00
|
|
|
$this->assertEquals($quote_type_id, $this->notifications->get_notification_type_id('quote'));
|
2013-04-30 21:10:04 -05:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2013-07-26 14:51:46 -05:00
|
|
|
$this->assertEquals(false, $this->notifications->get_notification_type_id('fail'));
|
2013-04-30 21:10:04 -05:00
|
|
|
|
2013-05-03 08:50:27 -05:00
|
|
|
$this->fail('Non-existent type should throw an exception');
|
2013-04-30 21:10:04 -05:00
|
|
|
}
|
|
|
|
catch (Exception $e) {}
|
|
|
|
}
|
|
|
|
|
2012-10-05 00:07:48 -05:00
|
|
|
public function test_get_subscription_types()
|
|
|
|
{
|
2012-10-20 20:54:18 -05:00
|
|
|
$subscription_types = $this->notifications->get_subscription_types();
|
|
|
|
|
|
|
|
$this->assertArrayHasKey('NOTIFICATION_GROUP_MISCELLANEOUS', $subscription_types);
|
|
|
|
$this->assertArrayHasKey('NOTIFICATION_GROUP_POSTING', $subscription_types);
|
|
|
|
|
2012-11-20 18:14:48 -06:00
|
|
|
$this->assertArrayHasKey('bookmark', $subscription_types['NOTIFICATION_GROUP_POSTING']);
|
|
|
|
$this->assertArrayHasKey('post', $subscription_types['NOTIFICATION_GROUP_POSTING']);
|
|
|
|
$this->assertArrayHasKey('quote', $subscription_types['NOTIFICATION_GROUP_POSTING']);
|
|
|
|
$this->assertArrayHasKey('topic', $subscription_types['NOTIFICATION_GROUP_POSTING']);
|
2012-10-20 20:54:18 -05:00
|
|
|
|
2012-11-20 18:14:48 -06:00
|
|
|
$this->assertArrayHasKey('pm', $subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']);
|
2012-10-05 00:07:48 -05:00
|
|
|
|
|
|
|
//get_subscription_types
|
|
|
|
//get_subscription_methods
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test_subscriptions()
|
|
|
|
{
|
2012-11-20 18:14:48 -06:00
|
|
|
$this->notifications->delete_subscription('post', 0, '', 2);
|
2012-10-05 00:07:48 -05:00
|
|
|
|
2012-11-20 18:14:48 -06:00
|
|
|
$this->assertArrayNotHasKey('post', $this->notifications->get_global_subscriptions(2));
|
2012-10-05 00:07:48 -05:00
|
|
|
|
2012-11-20 18:14:48 -06:00
|
|
|
$this->notifications->add_subscription('post', 0, '', 2);
|
2012-10-05 00:07:48 -05:00
|
|
|
|
2012-11-20 18:14:48 -06:00
|
|
|
$this->assertArrayHasKey('post', $this->notifications->get_global_subscriptions(2));
|
2012-10-05 00:07:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public function test_notifications()
|
|
|
|
{
|
2013-04-29 22:16:46 -05:00
|
|
|
$this->db->sql_query('DELETE FROM phpbb_notification_types');
|
|
|
|
|
|
|
|
$types = array('quote', 'bookmark', 'post', 'test');
|
|
|
|
foreach ($types as $id => $type)
|
|
|
|
{
|
|
|
|
$this->db->sql_query('INSERT INTO phpbb_notification_types ' .
|
|
|
|
$this->db->sql_build_array('INSERT', array(
|
|
|
|
'notification_type_id' => ($id + 1),
|
|
|
|
'notification_type_name' => $type,
|
|
|
|
'notification_type_enabled' => 1,
|
|
|
|
))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-10-05 15:09:29 -05:00
|
|
|
// Used to test post notifications later
|
2012-12-26 11:05:12 -06:00
|
|
|
$this->db->sql_query('INSERT INTO ' . TOPICS_WATCH_TABLE . ' ' . $this->db->sql_build_array('INSERT', array(
|
2012-10-05 15:09:29 -05:00
|
|
|
'topic_id' => 2,
|
|
|
|
'notify_status' => NOTIFY_YES,
|
|
|
|
'user_id' => 0,
|
|
|
|
)));
|
|
|
|
|
2012-10-05 00:07:48 -05:00
|
|
|
$this->assertEquals(array(
|
|
|
|
'notifications' => array(),
|
|
|
|
'unread_count' => 0,
|
2012-10-13 20:02:38 -05:00
|
|
|
'total_count' => 0,
|
2012-10-05 00:07:48 -05:00
|
|
|
), $this->notifications->load_notifications(array(
|
|
|
|
'count_unread' => true,
|
|
|
|
)));
|
|
|
|
|
2012-11-20 18:14:48 -06:00
|
|
|
$this->notifications->add_notifications('test', array(
|
2012-10-05 00:07:48 -05:00
|
|
|
'post_id' => '1',
|
|
|
|
'topic_id' => '1',
|
|
|
|
'post_time' => 1349413321,
|
|
|
|
));
|
|
|
|
|
2012-11-20 18:14:48 -06:00
|
|
|
$this->notifications->add_notifications('test', array(
|
2012-10-05 15:09:29 -05:00
|
|
|
'post_id' => '2',
|
|
|
|
'topic_id' => '2',
|
|
|
|
'post_time' => 1349413322,
|
|
|
|
));
|
|
|
|
|
2012-11-20 18:14:48 -06:00
|
|
|
$this->notifications->add_notifications('test', array(
|
2012-10-05 15:09:29 -05:00
|
|
|
'post_id' => '3',
|
|
|
|
'topic_id' => '2',
|
|
|
|
'post_time' => 1349413323,
|
2012-10-05 00:07:48 -05:00
|
|
|
));
|
|
|
|
|
2012-11-20 18:14:48 -06:00
|
|
|
$this->notifications->add_notifications(array('quote', 'bookmark', 'post', 'test'), array(
|
2012-10-05 15:09:29 -05:00
|
|
|
'post_id' => '4',
|
|
|
|
'topic_id' => '2',
|
|
|
|
'post_time' => 1349413324,
|
|
|
|
'poster_id' => 2,
|
|
|
|
'topic_title' => 'test-title',
|
|
|
|
'post_subject' => 'Re: test-title',
|
|
|
|
'forum_id' => 2,
|
|
|
|
'forum_name' => 'Your first forum',
|
|
|
|
));
|
2012-10-05 00:07:48 -05:00
|
|
|
|
2012-12-26 11:05:12 -06:00
|
|
|
$this->db->sql_query('INSERT INTO ' . BOOKMARKS_TABLE . ' ' . $this->db->sql_build_array('INSERT', array(
|
2012-10-05 15:09:29 -05:00
|
|
|
'topic_id' => 2,
|
|
|
|
'user_id' => 0,
|
|
|
|
)));
|
|
|
|
|
2012-11-20 18:14:48 -06:00
|
|
|
$this->notifications->add_notifications(array('quote', 'bookmark', 'post', 'test'), array(
|
2012-10-05 15:09:29 -05:00
|
|
|
'post_id' => '5',
|
|
|
|
'topic_id' => '2',
|
|
|
|
'post_time' => 1349413325,
|
|
|
|
'poster_id' => 2,
|
|
|
|
'topic_title' => 'test-title',
|
|
|
|
'post_subject' => 'Re: test-title',
|
|
|
|
'forum_id' => 2,
|
|
|
|
'forum_name' => 'Your first forum',
|
|
|
|
));
|
|
|
|
|
2012-11-20 18:14:48 -06:00
|
|
|
$this->notifications->delete_subscription('test');
|
2012-10-05 15:09:29 -05:00
|
|
|
|
2012-11-20 18:14:48 -06:00
|
|
|
$this->notifications->add_notifications('test', array(
|
2012-10-05 15:09:29 -05:00
|
|
|
'post_id' => '6',
|
|
|
|
'topic_id' => '2',
|
|
|
|
'post_time' => 1349413326,
|
|
|
|
));
|
|
|
|
|
2013-07-27 19:31:31 -05:00
|
|
|
$this->assert_notifications(
|
2013-07-26 17:27:52 -05:00
|
|
|
array(
|
2013-07-27 19:31:31 -05:00
|
|
|
array(
|
|
|
|
'item_id' => 1,
|
|
|
|
'item_parent_id' => 1,
|
|
|
|
'user_id' => 0,
|
|
|
|
'notification_read' => 0,
|
|
|
|
'notification_time' => 1349413321,
|
|
|
|
'notification_data' => array(),
|
2012-10-05 15:09:29 -05:00
|
|
|
),
|
2013-07-27 19:31:31 -05:00
|
|
|
array(
|
|
|
|
'item_id' => 2,
|
|
|
|
'item_parent_id' => 2,
|
|
|
|
'user_id' => 0,
|
|
|
|
'notification_read' => 0,
|
|
|
|
'notification_time' => 1349413322,
|
|
|
|
'notification_data' => array(),
|
2012-10-05 15:09:29 -05:00
|
|
|
),
|
2013-07-27 19:31:31 -05:00
|
|
|
array(
|
|
|
|
'item_id' => 3,
|
|
|
|
'item_parent_id' => 2,
|
|
|
|
'user_id' => 0,
|
|
|
|
'notification_read' => 0,
|
|
|
|
'notification_time' => 1349413323,
|
|
|
|
'notification_data' => array(),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'item_id' => 4,
|
|
|
|
'item_parent_id' => 2,
|
|
|
|
'user_id' => 0,
|
|
|
|
'notification_read' => 0,
|
|
|
|
'notification_time' => 1349413324,
|
|
|
|
'notification_data' => array(
|
|
|
|
'poster_id' => 2,
|
|
|
|
'topic_title' => 'test-title',
|
|
|
|
'post_subject' => 'Re: test-title',
|
|
|
|
'post_username' => '',
|
|
|
|
'forum_id' => 2,
|
|
|
|
'forum_name' => 'Your first forum',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'item_id' => 5,
|
|
|
|
'item_parent_id' => 2,
|
|
|
|
'user_id' => 0,
|
|
|
|
'notification_read' => 0,
|
|
|
|
'notification_time' => 1349413325,
|
|
|
|
'notification_data' => array(
|
|
|
|
'poster_id' => 2,
|
|
|
|
'topic_title' => 'test-title',
|
|
|
|
'post_subject' => 'Re: test-title',
|
|
|
|
'post_username' => '',
|
|
|
|
'forum_id' => 2,
|
|
|
|
'forum_name' => 'Your first forum',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
2012-10-05 00:07:48 -05:00
|
|
|
);
|
|
|
|
|
2012-10-05 15:09:29 -05:00
|
|
|
// Now test updating -------------------------------
|
2012-10-05 00:07:48 -05:00
|
|
|
|
2012-11-20 18:14:48 -06:00
|
|
|
$this->notifications->update_notifications('test', array(
|
2012-10-05 15:09:29 -05:00
|
|
|
'post_id' => '1',
|
|
|
|
'topic_id' => '2', // change parent_id
|
|
|
|
'post_time' => 1349413321,
|
|
|
|
));
|
2012-10-05 00:07:48 -05:00
|
|
|
|
2012-11-20 18:14:48 -06:00
|
|
|
$this->notifications->update_notifications('test', array(
|
2012-10-05 15:09:29 -05:00
|
|
|
'post_id' => '3',
|
|
|
|
'topic_id' => '2',
|
2012-10-20 20:54:18 -05:00
|
|
|
'post_time' => 1234, // change time
|
2012-10-05 15:09:29 -05:00
|
|
|
));
|
2012-10-05 00:07:48 -05:00
|
|
|
|
2012-11-20 18:14:48 -06:00
|
|
|
$this->notifications->update_notifications(array('quote', 'bookmark', 'post', 'test'), array(
|
2012-10-05 15:09:29 -05:00
|
|
|
'post_id' => '5',
|
|
|
|
'topic_id' => '2',
|
|
|
|
'poster_id' => 2,
|
|
|
|
'topic_title' => 'test-title2', // change topic_title
|
|
|
|
'post_subject' => 'Re: test-title2', // change post_subject
|
|
|
|
'forum_id' => 3, // change forum_id
|
|
|
|
'forum_name' => 'Your second forum', // change forum_name
|
2012-10-05 00:07:48 -05:00
|
|
|
));
|
|
|
|
|
2013-07-27 19:31:31 -05:00
|
|
|
$this->assert_notifications(
|
2013-07-26 17:27:52 -05:00
|
|
|
array(
|
2013-07-27 19:31:31 -05:00
|
|
|
array(
|
|
|
|
'item_id' => 3,
|
|
|
|
'item_parent_id' => 2,
|
|
|
|
'user_id' => 0,
|
|
|
|
'notification_read' => 0,
|
|
|
|
'notification_time' => 1234,
|
|
|
|
'notification_data' => array(),
|
2012-10-20 20:54:18 -05:00
|
|
|
),
|
2013-07-27 19:31:31 -05:00
|
|
|
array(
|
|
|
|
'item_id' => 1,
|
|
|
|
'item_parent_id' => 2,
|
|
|
|
'user_id' => 0,
|
|
|
|
'notification_read' => 0,
|
|
|
|
'notification_time' => 1349413321,
|
|
|
|
'notification_data' => array(),
|
2012-10-05 15:09:29 -05:00
|
|
|
),
|
2013-07-27 19:31:31 -05:00
|
|
|
array(
|
|
|
|
'item_id' => 2,
|
|
|
|
'item_parent_id' => 2,
|
|
|
|
'user_id' => 0,
|
|
|
|
'notification_read' => 0,
|
|
|
|
'notification_time' => 1349413322,
|
|
|
|
'notification_data' => array(),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'item_id' => 4,
|
|
|
|
'item_parent_id' => 2,
|
|
|
|
'user_id' => 0,
|
|
|
|
'notification_read' => 0,
|
|
|
|
'notification_time' => 1349413324,
|
|
|
|
'notification_data' => array(
|
|
|
|
'poster_id' => 2,
|
|
|
|
'topic_title' => 'test-title',
|
|
|
|
'post_subject' => 'Re: test-title',
|
|
|
|
'post_username' => '',
|
|
|
|
'forum_id' => 2,
|
|
|
|
'forum_name' => 'Your first forum',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'item_id' => 5,
|
|
|
|
'item_parent_id' => 2,
|
|
|
|
'user_id' => 0,
|
|
|
|
'notification_read' => 0,
|
|
|
|
'notification_time' => 1349413325,
|
|
|
|
'notification_data' => array(
|
|
|
|
'poster_id' => 2,
|
|
|
|
'topic_title' => 'test-title2',
|
|
|
|
'post_subject' => 'Re: test-title2',
|
|
|
|
'post_username' => '',
|
|
|
|
'forum_id' => 3,
|
|
|
|
'forum_name' => 'Your second forum',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
2012-10-05 15:09:29 -05:00
|
|
|
);
|
2012-10-05 00:07:48 -05:00
|
|
|
}
|
|
|
|
}
|