aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDavid King <imkingdavid@gmail.com>2013-05-20 11:54:39 -0400
committerDavid King <imkingdavid@gmail.com>2013-05-20 11:54:39 -0400
commitfedd9d18d2ab2c06fd584f599e685014783b9655 (patch)
tree352ca31c2a003d91a0101176c8ab92ca1021dcb0 /tests
parent9fab868f0f0a420b4eb7efb42e9c4cf27e66e9b3 (diff)
parent05cd045923068b08962856ec5e0c36f72f8f831c (diff)
downloadforums-fedd9d18d2ab2c06fd584f599e685014783b9655.tar
forums-fedd9d18d2ab2c06fd584f599e685014783b9655.tar.gz
forums-fedd9d18d2ab2c06fd584f599e685014783b9655.tar.bz2
forums-fedd9d18d2ab2c06fd584f599e685014783b9655.tar.xz
forums-fedd9d18d2ab2c06fd584f599e685014783b9655.zip
Merge remote-tracking branch 'EXreaction/ticket/11413' into develop
* EXreaction/ticket/11413: (23 commits) [ticket/11413] Revert some cache service related changes from earlier [ticket/11413] Use phpbb_user in test [ticket/11413] $user should have been $this->user [ticket/11413] Fix unit tests [ticket/11413] Translate the error [ticket/11413] Rename file to something more helpful [ticket/11413] Remove remaining irrelevant code to this PR [ticket/11413] Remove mock sql_insert_buffer.php (not relevant to PR) [ticket/11413] Remove conversion of user_notifications [ticket/11413] Correct copyright year [ticket/11413] Remove changes for ticket 11420 from this branch [ticket/11413] Include mock class [ticket/11413] Don't use the database for the convert test [ticket/11413] Test get_notification_type_id and _ids functions [ticket/11413] Use sql_insert_buffer [ticket/11413] Create test for notification conversion [ticket/11413] Fix test fixtures and tests [ticket/11413] Fix some more tests [ticket/11413] Fix notification tests [ticket/11413] Prevent recursive function calls ...
Diffstat (limited to 'tests')
-rw-r--r--tests/notification/fixtures/submit_post_bookmark.xml8
-rw-r--r--tests/notification/fixtures/submit_post_post.xml10
-rw-r--r--tests/notification/fixtures/submit_post_post_in_queue.xml8
-rw-r--r--tests/notification/fixtures/submit_post_quote.xml8
-rw-r--r--tests/notification/manager_helper.php (renamed from tests/mock/notifications_notification_manager.php)10
-rw-r--r--tests/notification/notification_test.php82
-rw-r--r--tests/notification/submit_post_base.php48
7 files changed, 122 insertions, 52 deletions
diff --git a/tests/notification/fixtures/submit_post_bookmark.xml b/tests/notification/fixtures/submit_post_bookmark.xml
index b669d4c1b6..d4bf8df73f 100644
--- a/tests/notification/fixtures/submit_post_bookmark.xml
+++ b/tests/notification/fixtures/submit_post_bookmark.xml
@@ -29,14 +29,14 @@
</row>
</table>
<table name="phpbb_notifications">
- <column>item_type</column>
+ <column>notification_type_id</column>
<column>user_id</column>
<column>item_id</column>
<column>item_parent_id</column>
<column>notification_read</column>
<column>notification_data</column>
<row>
- <value>bookmark</value>
+ <value>1</value>
<value>5</value>
<value>1</value>
<value>1</value>
@@ -45,9 +45,11 @@
</row>
</table>
<table name="phpbb_notification_types">
- <column>notification_type</column>
+ <column>notification_type_id</column>
+ <column>notification_type_name</column>
<column>notification_type_enabled</column>
<row>
+ <value>1</value>
<value>bookmark</value>
<value>1</value>
</row>
diff --git a/tests/notification/fixtures/submit_post_post.xml b/tests/notification/fixtures/submit_post_post.xml
index cead4f7c26..b0ffa042c5 100644
--- a/tests/notification/fixtures/submit_post_post.xml
+++ b/tests/notification/fixtures/submit_post_post.xml
@@ -21,14 +21,14 @@
</row>
</table>
<table name="phpbb_notifications">
- <column>item_type</column>
+ <column>notification_type_id</column>
<column>user_id</column>
<column>item_id</column>
<column>item_parent_id</column>
<column>notification_read</column>
<column>notification_data</column>
<row>
- <value>post</value>
+ <value>1</value>
<value>5</value>
<value>1</value>
<value>1</value>
@@ -36,7 +36,7 @@
<value></value>
</row>
<row>
- <value>post</value>
+ <value>1</value>
<value>8</value>
<value>1</value>
<value>1</value>
@@ -45,9 +45,11 @@
</row>
</table>
<table name="phpbb_notification_types">
- <column>notification_type</column>
+ <column>notification_type_id</column>
+ <column>notification_type_name</column>
<column>notification_type_enabled</column>
<row>
+ <value>1</value>
<value>post</value>
<value>1</value>
</row>
diff --git a/tests/notification/fixtures/submit_post_post_in_queue.xml b/tests/notification/fixtures/submit_post_post_in_queue.xml
index eedcebf71d..090e90ea49 100644
--- a/tests/notification/fixtures/submit_post_post_in_queue.xml
+++ b/tests/notification/fixtures/submit_post_post_in_queue.xml
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<dataset>
<table name="phpbb_notifications">
- <column>item_type</column>
+ <column>notification_type_id</column>
<column>user_id</column>
<column>item_id</column>
<column>item_parent_id</column>
<column>notification_read</column>
<column>notification_data</column>
<row>
- <value>post_in_queue</value>
+ <value>1</value>
<value>6</value>
<value>1</value>
<value>1</value>
@@ -17,9 +17,11 @@
</row>
</table>
<table name="phpbb_notification_types">
- <column>notification_type</column>
+ <column>notification_type_id</column>
+ <column>notification_type_name</column>
<column>notification_type_enabled</column>
<row>
+ <value>1</value>
<value>post_in_queue</value>
<value>1</value>
</row>
diff --git a/tests/notification/fixtures/submit_post_quote.xml b/tests/notification/fixtures/submit_post_quote.xml
index 884a84af4a..f22ed97d91 100644
--- a/tests/notification/fixtures/submit_post_quote.xml
+++ b/tests/notification/fixtures/submit_post_quote.xml
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<dataset>
<table name="phpbb_notifications">
- <column>item_type</column>
+ <column>notification_type_id</column>
<column>user_id</column>
<column>item_id</column>
<column>item_parent_id</column>
<column>notification_read</column>
<column>notification_data</column>
<row>
- <value>quote</value>
+ <value>1</value>
<value>5</value>
<value>1</value>
<value>1</value>
@@ -17,9 +17,11 @@
</row>
</table>
<table name="phpbb_notification_types">
- <column>notification_type</column>
+ <column>notification_type_id</column>
+ <column>notification_type_name</column>
<column>notification_type_enabled</column>
<row>
+ <value>1</value>
<value>quote</value>
<value>1</value>
</row>
diff --git a/tests/mock/notifications_notification_manager.php b/tests/notification/manager_helper.php
index c995afb9ab..7a794f922f 100644
--- a/tests/mock/notifications_notification_manager.php
+++ b/tests/notification/manager_helper.php
@@ -19,7 +19,7 @@ if (!defined('IN_PHPBB'))
* Notifications service class
* @package notifications
*/
-class phpbb_mock_notifications_notification_manager extends phpbb_notification_manager
+class phpbb_notification_manager_helper extends phpbb_notification_manager
{
public function set_var($name, $value)
{
@@ -28,12 +28,10 @@ class phpbb_mock_notifications_notification_manager extends phpbb_notification_m
// Extra dependencies for get_*_class functions
protected $auth = null;
- protected $cache = null;
protected $config = null;
- public function setDependencies($auth, $cache, $config)
+ public function setDependencies($auth, $config)
{
$this->auth = $auth;
- $this->cache = $cache;
$this->config = $config;
}
@@ -44,7 +42,7 @@ class phpbb_mock_notifications_notification_manager extends phpbb_notification_m
{
$item_type = 'phpbb_notification_type_' . $item_type;
- $item = new $item_type($this->user_loader, $this->db, $this->cache, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notification_types_table, $this->notifications_table, $this->user_notifications_table);
+ $item = new $item_type($this->user_loader, $this->db, $this->cache->get_driver(), $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notification_types_table, $this->notifications_table, $this->user_notifications_table);
$item->set_notification_manager($this);
@@ -60,7 +58,7 @@ class phpbb_mock_notifications_notification_manager extends phpbb_notification_m
{
$method_name = 'phpbb_notification_method_' . $method_name;
- $method = new $method_name($this->user_loader, $this->db, $this->cache, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notification_types_table, $this->notifications_table, $this->user_notifications_table);
+ $method = new $method_name($this->user_loader, $this->db, $this->cache->get_driver(), $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notification_types_table, $this->notifications_table, $this->user_notifications_table);
$method->set_notification_manager($this);
diff --git a/tests/notification/notification_test.php b/tests/notification/notification_test.php
index beccf55371..8f7eb3b8a8 100644
--- a/tests/notification/notification_test.php
+++ b/tests/notification/notification_test.php
@@ -7,6 +7,8 @@
*
*/
+require_once dirname(__FILE__) . '/manager_helper.php';
+
class phpbb_notification_test extends phpbb_database_test_case
{
protected $notifications, $db, $container, $user, $config, $auth, $cache;
@@ -31,19 +33,26 @@ class phpbb_notification_test extends phpbb_database_test_case
'allow_topic_notify' => true,
'allow_forum_notify' => true,
));
- $this->user = new phpbb_mock_user();
+ $this->user = new phpbb_user();
$this->user_loader = new phpbb_user_loader($this->db, $phpbb_root_path, $phpEx, 'phpbb_users');
$this->auth = new phpbb_mock_notifications_auth();
- $this->cache = new phpbb_mock_cache();
+ $this->cache = new phpbb_cache_service(
+ new phpbb_cache_driver_null(),
+ $this->config,
+ $this->db,
+ $phpbb_root_path,
+ $phpEx
+ );
$this->container = new phpbb_mock_container_builder();
- $this->notifications = new phpbb_mock_notifications_notification_manager(
+ $this->notifications = new phpbb_notification_manager_helper(
array(),
array(),
$this->container,
$this->user_loader,
$this->db,
+ $this->cache,
$this->user,
$phpbb_root_path,
$phpEx,
@@ -52,7 +61,7 @@ class phpbb_notification_test extends phpbb_database_test_case
'phpbb_user_notifications'
);
- $this->notifications->setDependencies($this->auth, $this->cache, $this->config);
+ $this->notifications->setDependencies($this->auth, $this->config);
$types = array();
foreach (array(
@@ -87,7 +96,36 @@ class phpbb_notification_test extends phpbb_database_test_case
{
global $phpbb_root_path, $phpEx;
- return new $type($this->user_loader, $this->db, $this->cache, $this->user, $this->auth, $this->config, $phpbb_root_path, $phpEx, 'phpbb_notification_types', 'phpbb_notifications', 'phpbb_user_notifications');
+ return new $type($this->user_loader, $this->db, $this->cache->get_driver(), $this->user, $this->auth, $this->config, $phpbb_root_path, $phpEx, 'phpbb_notification_types', 'phpbb_notifications', 'phpbb_user_notifications');
+ }
+
+ public function test_get_notification_type_id()
+ {
+ // They should be inserted the first time
+ $this->assertEquals(1, $this->notifications->get_notification_type_id('post'));
+ $this->assertEquals(2, $this->notifications->get_notification_type_id('quote'));
+ $this->assertEquals(3, $this->notifications->get_notification_type_id('test'));
+
+ $this->assertEquals(array(
+ 'test' => 3,
+ 'quote' => 2,
+ 'post' => 1,
+ ),
+ $this->notifications->get_notification_type_ids(array(
+ 'test',
+ 'quote',
+ 'post',
+ )
+ ));
+ $this->assertEquals(2, $this->notifications->get_notification_type_id('quote'));
+
+ try
+ {
+ $this->assertEquals(3, $this->notifications->get_notification_type_id('fail'));
+
+ $this->fail('Non-existent type should throw an exception');
+ }
+ catch (Exception $e) {}
}
public function test_get_subscription_types()
@@ -121,6 +159,20 @@ class phpbb_notification_test extends phpbb_database_test_case
public function test_notifications()
{
+ $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,
+ ))
+ );
+ }
+
// Used to test post notifications later
$this->db->sql_query('INSERT INTO ' . TOPICS_WATCH_TABLE . ' ' . $this->db->sql_build_array('INSERT', array(
'topic_id' => 2,
@@ -195,7 +247,7 @@ class phpbb_notification_test extends phpbb_database_test_case
$expected = array(
1 => array(
- 'item_type' => 'test',
+ 'notification_type_id' => 4,
'item_id' => 1,
'item_parent_id' => 1,
'user_id' => 0,
@@ -204,7 +256,7 @@ class phpbb_notification_test extends phpbb_database_test_case
'notification_data' => array(),
),
2 => array(
- 'item_type' => 'test',
+ 'notification_type_id' => 4,
'item_id' => 2,
'item_parent_id' => 2,
'user_id' => 0,
@@ -213,7 +265,7 @@ class phpbb_notification_test extends phpbb_database_test_case
'notification_data' => array(),
),
3 => array(
- 'item_type' => 'test',
+ 'notification_type_id' => 4,
'item_id' => 3,
'item_parent_id' => 2,
'user_id' => 0,
@@ -222,7 +274,7 @@ class phpbb_notification_test extends phpbb_database_test_case
'notification_data' => array(),
),
4 => array(
- 'item_type' => 'post',
+ 'notification_type_id' => 3,
'item_id' => 4,
'item_parent_id' => 2,
'user_id' => 0,
@@ -238,7 +290,7 @@ class phpbb_notification_test extends phpbb_database_test_case
),
),
5 => array(
- 'item_type' => 'bookmark',
+ 'notification_type_id' => 2,
'item_id' => 5,
'item_parent_id' => 2,
'user_id' => 0,
@@ -301,7 +353,7 @@ class phpbb_notification_test extends phpbb_database_test_case
$expected = array(
1 => array(
- 'item_type' => 'test',
+ 'notification_type_id' => 4,
'item_id' => 1,
'item_parent_id' => 2,
'user_id' => 0,
@@ -310,7 +362,7 @@ class phpbb_notification_test extends phpbb_database_test_case
'notification_data' => array(),
),
2 => array(
- 'item_type' => 'test',
+ 'notification_type_id' => 4,
'item_id' => 2,
'item_parent_id' => 2,
'user_id' => 0,
@@ -319,7 +371,7 @@ class phpbb_notification_test extends phpbb_database_test_case
'notification_data' => array(),
),
3 => array(
- 'item_type' => 'test',
+ 'notification_type_id' => 4,
'item_id' => 3,
'item_parent_id' => 2,
'user_id' => 0,
@@ -328,7 +380,7 @@ class phpbb_notification_test extends phpbb_database_test_case
'notification_data' => array(),
),
4 => array(
- 'item_type' => 'post',
+ 'notification_type_id' => 3,
'item_id' => 4,
'item_parent_id' => 2,
'user_id' => 0,
@@ -344,7 +396,7 @@ class phpbb_notification_test extends phpbb_database_test_case
),
),
5 => array(
- 'item_type' => 'bookmark',
+ 'notification_type_id' => 2,
'item_id' => 5,
'item_parent_id' => 2,
'user_id' => 0,
diff --git a/tests/notification/submit_post_base.php b/tests/notification/submit_post_base.php
index 953bedac80..59daf6c9cb 100644
--- a/tests/notification/submit_post_base.php
+++ b/tests/notification/submit_post_base.php
@@ -52,9 +52,6 @@ class phpbb_notification_submit_post_base extends phpbb_database_test_case
$this->db = $this->new_dbal();
$db = $this->db;
- // Cache
- $cache = new phpbb_mock_cache();
-
// Auth
$auth = $this->getMock('phpbb_auth');
$auth->expects($this->any())
@@ -72,6 +69,14 @@ class phpbb_notification_submit_post_base extends phpbb_database_test_case
set_config(null, null, null, $config);
set_config_count(null, null, null, $config);
+ $cache = new phpbb_cache_service(
+ new phpbb_cache_driver_null(),
+ $config,
+ $db,
+ $phpbb_root_path,
+ $phpEx
+ );
+
// Event dispatcher
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
@@ -94,23 +99,28 @@ class phpbb_notification_submit_post_base extends phpbb_database_test_case
$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', 'post_in_queue');
+ $notification_types = array('quote', 'bookmark', 'post', 'post_in_queue', 'topic', 'approve_topic', 'approve_post');
+ $notification_types_array = array();
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,
+ $class = new $class_name(
+ $user_loader, $db, $cache->get_driver(), $user, $auth, $config,
$phpbb_root_path, $phpEx,
- NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE));
+ NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE);
+
+ $phpbb_container->set('notification.type.' . $type, $class);
+
+ $notification_types_array['notification.type.' . $type] = $class;
}
+
+ // Notification Manager
+ $phpbb_notifications = new phpbb_notification_manager($notification_types_array, array(),
+ $phpbb_container, $user_loader, $db, $cache, $user,
+ $phpbb_root_path, $phpEx,
+ NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE);
+ $phpbb_container->set('notification_manager', $phpbb_notifications);
}
/**
@@ -119,8 +129,9 @@ class phpbb_notification_submit_post_base extends phpbb_database_test_case
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 . "'
+ FROM ' . NOTIFICATIONS_TABLE . ' n, ' . NOTIFICATION_TYPES_TABLE . " nt
+ WHERE nt.notification_type_name = '" . $this->item_type . "'
+ AND n.notification_type_id = nt.notification_type_id
ORDER BY user_id, item_id ASC";
$result = $this->db->sql_query($sql);
$this->assertEquals($expected_before, $this->db->sql_fetchrowset($result));
@@ -131,8 +142,9 @@ class phpbb_notification_submit_post_base extends phpbb_database_test_case
submit_post('reply', '', 'poster-name', POST_NORMAL, $poll_data, $post_data, false, false);
$sql = 'SELECT user_id, item_id, item_parent_id
- FROM ' . NOTIFICATIONS_TABLE . "
- WHERE item_type = '" . $this->item_type . "'
+ FROM ' . NOTIFICATIONS_TABLE . ' n, ' . NOTIFICATION_TYPES_TABLE . " nt
+ WHERE nt.notification_type_name = '" . $this->item_type . "'
+ AND n.notification_type_id = nt.notification_type_id
ORDER BY user_id ASC, item_id ASC";
$result = $this->db->sql_query($sql);
$this->assertEquals($expected_after, $this->db->sql_fetchrowset($result));