From e6a0e4caed0262507926bf70c86533efd2512e26 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 29 Mar 2017 19:53:58 +0200 Subject: [ticket/8116] Improve code and add tests for helper functions PHPBB3-8116 --- tests/mcp/fixtures/post_ip.xml | 73 ++++++++++++++++++++++++++++++++++++++++++ tests/mcp/post_ip_test.php | 67 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+) create mode 100644 tests/mcp/fixtures/post_ip.xml create mode 100644 tests/mcp/post_ip_test.php (limited to 'tests/mcp') diff --git a/tests/mcp/fixtures/post_ip.xml b/tests/mcp/fixtures/post_ip.xml new file mode 100644 index 0000000000..fad2193396 --- /dev/null +++ b/tests/mcp/fixtures/post_ip.xml @@ -0,0 +1,73 @@ + + + + post_id + poster_id + post_edit_user + post_delete_user + post_username + topic_id + forum_id + post_visibility + post_time + post_text + post_reported + poster_ip + + 1 + 2 + 2 + 2 + + 1 + 1 + 1 + 1 + + 1 + 127.0.0.1 + + + 2 + 1 + 1 + 1 + Other + 2 + 2 + 1 + 1 + + 1 + 127.0.0.2 + + + 3 + 2 + 2 + 2 + + 3 + 3 + 1 + 1 + + 1 + 127.0.0.3 + + + 4 + 1 + 1 + 1 + Other + 4 + 4 + 1 + 1 + + 1 + 127.0.0.1 + +
+
diff --git a/tests/mcp/post_ip_test.php b/tests/mcp/post_ip_test.php new file mode 100644 index 0000000000..865b15bcb2 --- /dev/null +++ b/tests/mcp/post_ip_test.php @@ -0,0 +1,67 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +require_once dirname(__FILE__) . '/../../phpBB/includes/mcp/mcp_post.php'; + +class phpbb_mcp_post_ip_test extends phpbb_database_test_case +{ + /** @var \phpbb\db\driver\driver_interface */ + protected $db; + + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/post_ip.xml'); + } + + protected function setUp() + { + parent::setUp(); + + $this->db = $this->new_dbal(); + } + + public function data_get_num_ips() + { + return array( + array(2, 1), + array(2, 2), + array(0, 3), + ); + } + + /** + * @dataProvider data_get_num_ips + */ + public function test_get_num_ips($expected, $poster_id) + { + $this->assertSame($expected, phpbb_get_num_ips_for_poster($this->db, $poster_id)); + } + + public function data_get_num_posters() + { + return array( + array(2, '127.0.0.1'), + array(1, '127.0.0.2'), + array(1, '127.0.0.3'), + array(0, '127.0.0.4'), + ); + } + + /** + * @dataProvider data_get_num_posters + */ + public function test_get_num_posters($expected, $ip) + { + $this->assertSame($expected, phpbb_get_num_posters_for_ip($this->db, $ip)); + } +} \ No newline at end of file -- cgit v1.2.1