From 7e80e4004e92ddcf3ad147d05d43bb411010e9e0 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 18 Mar 2012 12:07:41 +0100 Subject: [ticket/10714] Add unit tests for add_log function PHPBB3-10714 --- tests/log/function_add_log_test.php | 151 ++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 tests/log/function_add_log_test.php (limited to 'tests/log/function_add_log_test.php') diff --git a/tests/log/function_add_log_test.php b/tests/log/function_add_log_test.php new file mode 100644 index 0000000000..05fae0f916 --- /dev/null +++ b/tests/log/function_add_log_test.php @@ -0,0 +1,151 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/empty_log.xml'); + } + + public static function test_add_log_function_critical_data() + { + return array( + array( + array( + array( + 'user_id' => 2, + 'log_type' => LOG_CRITICAL, + 'log_operation' => 'LOG_NO_ADDITIONAL', + 'log_data' => '', + 'reportee_id' => 0, + 'forum_id' => 0, + 'topic_id' => 0, + ), + ), + 2, 'critical', 'LOG_NO_ADDITIONAL', + ), + array( + array( + array( + 'user_id' => 2, + 'log_type' => LOG_CRITICAL, + 'log_operation' => 'LOG_ONE_ADDITIONAL', + 'log_data' => 'a:1:{i:0;s:9:"argument1";}', + 'reportee_id' => 0, + 'forum_id' => 0, + 'topic_id' => 0, + ), + ), + 2, 'critical', 'LOG_ONE_ADDITIONAL', 'argument1', + ), + array( + array( + array( + 'user_id' => ANONYMOUS, + 'log_type' => LOG_ADMIN, + 'log_operation' => 'LOG_TWO_ADDITIONAL', + 'log_data' => 'a:2:{i:0;s:9:"argument1";i:1;s:9:"argument2";}', + 'reportee_id' => 0, + 'forum_id' => 0, + 'topic_id' => 0, + ), + ), + false, 'admin', 'LOG_TWO_ADDITIONAL', 'argument1', 'argument2', + ), + array( + array( + array( + 'user_id' => ANONYMOUS, + 'log_type' => LOG_USERS, + 'log_operation' => 'LOG_USERS_ADDITIONAL', + 'log_data' => 'a:1:{i:0;s:9:"argument2";}', + 'reportee_id' => 2, + 'forum_id' => 0, + 'topic_id' => 0, + ), + ), + false, 'user', 2, 'LOG_USERS_ADDITIONAL', 'argument2', + ), + array( + array( + array( + 'user_id' => ANONYMOUS, + 'log_type' => LOG_MOD, + 'log_operation' => 'LOG_MOD_TOPIC_AND_FORUM', + 'log_data' => '', + 'reportee_id' => 0, + 'forum_id' => 12, + 'topic_id' => 34, + ), + ), + false, 'mod', 12, 34, 'LOG_MOD_TOPIC_AND_FORUM', + ), + array( + array( + array( + 'user_id' => ANONYMOUS, + 'log_type' => LOG_MOD, + 'log_operation' => 'LOG_MOD_ADDITIONAL', + 'log_data' => 'a:1:{i:0;s:9:"argument3";}', + 'reportee_id' => 0, + 'forum_id' => 56, + 'topic_id' => 78, + ), + ), + false, 'mod', 56, 78, 'LOG_MOD_ADDITIONAL', 'argument3', + ), + array( + array( + ), + false, 'mode_does_not_exist', 'LOG_MOD_ADDITIONAL', 'argument1', + ), + ); + } + + /** + * @dataProvider test_add_log_function_critical_data + */ + public function test_add_log_function_critical($expected, $user_id, $mode, $required1, $additional1 = null, $additional2 = null, $additional3 = null) + { + global $db, $user; + + $db = $this->new_dbal(); + + $user->ip = 'user_ip'; + if ($user_id) + { + $user->data['user_id'] = $user_id; + } + + if ($additional3 != null) + { + add_log($mode, $required1, $additional1, $additional2, $additional3); + } + else if ($additional2 != null) + { + add_log($mode, $required1, $additional1, $additional2); + } + else if ($additional1 != null) + { + add_log($mode, $required1, $additional1); + } + else + { + add_log($mode, $required1); + } + + $result = $db->sql_query('SELECT user_id, log_type, log_operation, log_data, reportee_id, forum_id, topic_id + FROM ' . LOG_TABLE); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } +} -- cgit v1.2.1 From 31e18f31a6139cddb32520aa6ed020dc8f80f70a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 18 Mar 2012 13:40:56 +0100 Subject: [ticket/10714] Serialize the log_data in the testinsteadof hardcoding it PHPBB3-10714 --- tests/log/function_add_log_test.php | 107 +++++++++++++++++++----------------- 1 file changed, 57 insertions(+), 50 deletions(-) (limited to 'tests/log/function_add_log_test.php') diff --git a/tests/log/function_add_log_test.php b/tests/log/function_add_log_test.php index 05fae0f916..407aeb9ad1 100644 --- a/tests/log/function_add_log_test.php +++ b/tests/log/function_add_log_test.php @@ -21,85 +21,82 @@ class phpbb_log_function_add_log_test extends phpbb_database_test_case return array( array( array( - array( - 'user_id' => 2, - 'log_type' => LOG_CRITICAL, - 'log_operation' => 'LOG_NO_ADDITIONAL', - 'log_data' => '', - 'reportee_id' => 0, - 'forum_id' => 0, - 'topic_id' => 0, - ), + 'user_id' => 2, + 'log_type' => LOG_CRITICAL, + 'log_operation' => 'LOG_NO_ADDITIONAL', + 'log_data' => '', + 'reportee_id' => 0, + 'forum_id' => 0, + 'topic_id' => 0, ), 2, 'critical', 'LOG_NO_ADDITIONAL', ), array( array( - array( - 'user_id' => 2, - 'log_type' => LOG_CRITICAL, - 'log_operation' => 'LOG_ONE_ADDITIONAL', - 'log_data' => 'a:1:{i:0;s:9:"argument1";}', - 'reportee_id' => 0, - 'forum_id' => 0, - 'topic_id' => 0, + 'user_id' => 2, + 'log_type' => LOG_CRITICAL, + 'log_operation' => 'LOG_ONE_ADDITIONAL', + 'log_data' => array( + 'argument1', ), + 'reportee_id' => 0, + 'forum_id' => 0, + 'topic_id' => 0, ), 2, 'critical', 'LOG_ONE_ADDITIONAL', 'argument1', ), array( array( - array( - 'user_id' => ANONYMOUS, - 'log_type' => LOG_ADMIN, - 'log_operation' => 'LOG_TWO_ADDITIONAL', - 'log_data' => 'a:2:{i:0;s:9:"argument1";i:1;s:9:"argument2";}', - 'reportee_id' => 0, - 'forum_id' => 0, - 'topic_id' => 0, + 'user_id' => ANONYMOUS, + 'log_type' => LOG_ADMIN, + 'log_operation' => 'LOG_TWO_ADDITIONAL', + 'log_data' => array( + 'argument1', + 'argument2', ), + 'reportee_id' => 0, + 'forum_id' => 0, + 'topic_id' => 0, ), false, 'admin', 'LOG_TWO_ADDITIONAL', 'argument1', 'argument2', ), array( array( - array( - 'user_id' => ANONYMOUS, - 'log_type' => LOG_USERS, - 'log_operation' => 'LOG_USERS_ADDITIONAL', - 'log_data' => 'a:1:{i:0;s:9:"argument2";}', - 'reportee_id' => 2, - 'forum_id' => 0, - 'topic_id' => 0, + 'user_id' => ANONYMOUS, + 'log_type' => LOG_USERS, + 'log_operation' => 'LOG_USERS_ADDITIONAL', + 'log_data' => array( + 'argument2', ), + 'reportee_id' => 2, + 'forum_id' => 0, + 'topic_id' => 0, ), false, 'user', 2, 'LOG_USERS_ADDITIONAL', 'argument2', ), array( array( - array( - 'user_id' => ANONYMOUS, - 'log_type' => LOG_MOD, - 'log_operation' => 'LOG_MOD_TOPIC_AND_FORUM', - 'log_data' => '', - 'reportee_id' => 0, - 'forum_id' => 12, - 'topic_id' => 34, - ), + 'user_id' => ANONYMOUS, + 'log_type' => LOG_MOD, + 'log_operation' => 'LOG_MOD_TOPIC_AND_FORUM', + 'log_data' => '', + 'reportee_id' => 0, + 'forum_id' => 12, + 'topic_id' => 34, ), false, 'mod', 12, 34, 'LOG_MOD_TOPIC_AND_FORUM', ), array( array( - array( - 'user_id' => ANONYMOUS, - 'log_type' => LOG_MOD, - 'log_operation' => 'LOG_MOD_ADDITIONAL', - 'log_data' => 'a:1:{i:0;s:9:"argument3";}', - 'reportee_id' => 0, - 'forum_id' => 56, - 'topic_id' => 78, + 'user_id' => ANONYMOUS, + 'log_type' => LOG_MOD, + 'log_operation' => 'LOG_MOD_ADDITIONAL', + 'log_data' => array( + 'argument3', ), + 'reportee_id' => 0, + 'forum_id' => 56, + 'topic_id' => 78, ), false, 'mod', 56, 78, 'LOG_MOD_ADDITIONAL', 'argument3', ), @@ -118,6 +115,16 @@ class phpbb_log_function_add_log_test extends phpbb_database_test_case { global $db, $user; + if ($expected) + { + // Serialize the log data if we have some + if (is_array($expected['log_data'])) + { + $expected['log_data'] = serialize($expected['log_data']); + } + $expected = array($expected); + } + $db = $this->new_dbal(); $user->ip = 'user_ip'; -- cgit v1.2.1 From ea652f0ec9e7046f329e692fc355e64836f9bf9d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 21 Mar 2012 13:33:25 +0100 Subject: [ticket/10714] Rename add_log_function test PHPBB3-10714 --- tests/log/function_add_log_test.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/log/function_add_log_test.php') diff --git a/tests/log/function_add_log_test.php b/tests/log/function_add_log_test.php index 407aeb9ad1..1f54f66d2d 100644 --- a/tests/log/function_add_log_test.php +++ b/tests/log/function_add_log_test.php @@ -16,7 +16,7 @@ class phpbb_log_function_add_log_test extends phpbb_database_test_case return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/empty_log.xml'); } - public static function test_add_log_function_critical_data() + public static function test_add_log_function_data() { return array( array( @@ -109,9 +109,9 @@ class phpbb_log_function_add_log_test extends phpbb_database_test_case } /** - * @dataProvider test_add_log_function_critical_data + * @dataProvider test_add_log_function_data */ - public function test_add_log_function_critical($expected, $user_id, $mode, $required1, $additional1 = null, $additional2 = null, $additional3 = null) + public function test_add_log_function($expected, $user_id, $mode, $required1, $additional1 = null, $additional2 = null, $additional3 = null) { global $db, $user; -- cgit v1.2.1 From 1e00c697b766d1a8695c8e058334efe1dd3dbb7e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 24 Mar 2012 17:02:56 +0100 Subject: [ticket/10714] Add docblock for the test cases PHPBB3-10714 --- tests/log/function_add_log_test.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'tests/log/function_add_log_test.php') diff --git a/tests/log/function_add_log_test.php b/tests/log/function_add_log_test.php index 1f54f66d2d..e7b3c4335f 100644 --- a/tests/log/function_add_log_test.php +++ b/tests/log/function_add_log_test.php @@ -19,6 +19,35 @@ class phpbb_log_function_add_log_test extends phpbb_database_test_case public static function test_add_log_function_data() { return array( + /** + * Case documentation + array( + // Row that is in the database afterwards + array( + 'user_id' => ANONYMOUS, + 'log_type' => LOG_MOD, + 'log_operation' => 'LOG_MOD_ADDITIONAL', + // log_data will be serialized + 'log_data' => array( + 'argument3', + ), + 'reportee_id' => 0, + 'forum_id' => 56, + 'topic_id' => 78, + ), + // user_id Can also be false, than ANONYMOUS is used + false, + // log_mode Used to determinate the log_type + 'mod', + // Followed by some additional arguments + // forum_id, topic_id and reportee_id are specified before log_operation + // The rest is specified afterwards. + 56, + 78, + 'LOG_MOD_ADDITIONAL', // log_operation + 'argument3', + ), + */ array( array( 'user_id' => 2, -- cgit v1.2.1 From d828ef93f29eda5fe31a6f8291dd1e5b3cdfd97c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 21 Aug 2012 16:00:01 +0200 Subject: [ticket/10714] Fix unit test because of events and moved files PHPBB3-10714 --- tests/log/function_add_log_test.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests/log/function_add_log_test.php') diff --git a/tests/log/function_add_log_test.php b/tests/log/function_add_log_test.php index e7b3c4335f..77c4578baa 100644 --- a/tests/log/function_add_log_test.php +++ b/tests/log/function_add_log_test.php @@ -142,7 +142,7 @@ class phpbb_log_function_add_log_test extends phpbb_database_test_case */ public function test_add_log_function($expected, $user_id, $mode, $required1, $additional1 = null, $additional2 = null, $additional3 = null) { - global $db, $user; + global $db, $user, $phpbb_dispatcher; if ($expected) { @@ -155,6 +155,7 @@ class phpbb_log_function_add_log_test extends phpbb_database_test_case } $db = $this->new_dbal(); + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); $user->ip = 'user_ip'; if ($user_id) -- cgit v1.2.1 From 0f94ff91383ee0ed533048db96a34164ba94b0a4 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 7 Dec 2012 16:05:57 +0100 Subject: [ticket/10714] Add global variables for the unit tests PHPBB3-10714 --- tests/log/function_add_log_test.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tests/log/function_add_log_test.php') diff --git a/tests/log/function_add_log_test.php b/tests/log/function_add_log_test.php index 77c4578baa..7ed862c523 100644 --- a/tests/log/function_add_log_test.php +++ b/tests/log/function_add_log_test.php @@ -142,7 +142,7 @@ class phpbb_log_function_add_log_test extends phpbb_database_test_case */ public function test_add_log_function($expected, $user_id, $mode, $required1, $additional1 = null, $additional2 = null, $additional3 = null) { - global $db, $user, $phpbb_dispatcher; + global $db, $cache, $user, $phpbb_log, $phpbb_dispatcher; if ($expected) { @@ -155,7 +155,9 @@ class phpbb_log_function_add_log_test extends phpbb_database_test_case } $db = $this->new_dbal(); + $cache = new phpbb_mock_cache; $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + $phpbb_log = new phpbb_log(LOG_TABLE); $user->ip = 'user_ip'; if ($user_id) -- cgit v1.2.1 From f4bc9c1673c18ed24a2ba1680f6b9a5de5c491bf Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 11 Dec 2012 10:24:49 +0100 Subject: [ticket/10714] Fix dependency injections in unit tests with mocks PHPBB3-10714 --- tests/log/function_add_log_test.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'tests/log/function_add_log_test.php') diff --git a/tests/log/function_add_log_test.php b/tests/log/function_add_log_test.php index 7ed862c523..0a65ce3165 100644 --- a/tests/log/function_add_log_test.php +++ b/tests/log/function_add_log_test.php @@ -142,7 +142,7 @@ class phpbb_log_function_add_log_test extends phpbb_database_test_case */ public function test_add_log_function($expected, $user_id, $mode, $required1, $additional1 = null, $additional2 = null, $additional3 = null) { - global $db, $cache, $user, $phpbb_log, $phpbb_dispatcher; + global $db, $cache, $user, $phpbb_log, $phpbb_dispatcher, $phpbb_root_path, $phpEx; if ($expected) { @@ -157,7 +157,10 @@ class phpbb_log_function_add_log_test extends phpbb_database_test_case $db = $this->new_dbal(); $cache = new phpbb_mock_cache; $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); - $phpbb_log = new phpbb_log(LOG_TABLE); + $user = $this->getMock('phpbb_user'); + $auth = $this->getMock('phpbb_auth'); + + $phpbb_log = new phpbb_log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, $phpEx, LOG_TABLE); $user->ip = 'user_ip'; if ($user_id) -- cgit v1.2.1 From 2c4e7eabe248fc785cd2b43f57a42580361c599d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 22 Jan 2013 15:10:35 +0100 Subject: [ticket/10714] Fix missing 8th argument in unit tests PHPBB3-10714 --- tests/log/function_add_log_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/log/function_add_log_test.php') diff --git a/tests/log/function_add_log_test.php b/tests/log/function_add_log_test.php index 0a65ce3165..4e54a75dd6 100644 --- a/tests/log/function_add_log_test.php +++ b/tests/log/function_add_log_test.php @@ -160,7 +160,7 @@ class phpbb_log_function_add_log_test extends phpbb_database_test_case $user = $this->getMock('phpbb_user'); $auth = $this->getMock('phpbb_auth'); - $phpbb_log = new phpbb_log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, $phpEx, LOG_TABLE); + $phpbb_log = new phpbb_log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); $user->ip = 'user_ip'; if ($user_id) -- cgit v1.2.1 From c2504e9300608feea540ab162e4cc0ac79cda7a0 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 22 Jan 2013 15:56:34 +0100 Subject: [ticket/10714] Fix more comments PHPBB3-10714 --- tests/log/function_add_log_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/log/function_add_log_test.php') diff --git a/tests/log/function_add_log_test.php b/tests/log/function_add_log_test.php index 4e54a75dd6..864b364862 100644 --- a/tests/log/function_add_log_test.php +++ b/tests/log/function_add_log_test.php @@ -35,9 +35,9 @@ class phpbb_log_function_add_log_test extends phpbb_database_test_case 'forum_id' => 56, 'topic_id' => 78, ), - // user_id Can also be false, than ANONYMOUS is used + // user_id Can also be false, then ANONYMOUS is used false, - // log_mode Used to determinate the log_type + // log_mode Used to determine the log_type 'mod', // Followed by some additional arguments // forum_id, topic_id and reportee_id are specified before log_operation -- cgit v1.2.1