mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-31 22:10:45 +02:00
[ticket/8116] Improve code and add tests for helper functions
PHPBB3-8116
This commit is contained in:
73
tests/mcp/fixtures/post_ip.xml
Normal file
73
tests/mcp/fixtures/post_ip.xml
Normal file
@@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<dataset>
|
||||
<table name="phpbb_posts">
|
||||
<column>post_id</column>
|
||||
<column>poster_id</column>
|
||||
<column>post_edit_user</column>
|
||||
<column>post_delete_user</column>
|
||||
<column>post_username</column>
|
||||
<column>topic_id</column>
|
||||
<column>forum_id</column>
|
||||
<column>post_visibility</column>
|
||||
<column>post_time</column>
|
||||
<column>post_text</column>
|
||||
<column>post_reported</column>
|
||||
<column>poster_ip</column>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>2</value>
|
||||
<value>2</value>
|
||||
<value>2</value>
|
||||
<value></value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value></value>
|
||||
<value>1</value>
|
||||
<value>127.0.0.1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>2</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>Other</value>
|
||||
<value>2</value>
|
||||
<value>2</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value></value>
|
||||
<value>1</value>
|
||||
<value>127.0.0.2</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>3</value>
|
||||
<value>2</value>
|
||||
<value>2</value>
|
||||
<value>2</value>
|
||||
<value></value>
|
||||
<value>3</value>
|
||||
<value>3</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value></value>
|
||||
<value>1</value>
|
||||
<value>127.0.0.3</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>4</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>Other</value>
|
||||
<value>4</value>
|
||||
<value>4</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value></value>
|
||||
<value>1</value>
|
||||
<value>127.0.0.1</value>
|
||||
</row>
|
||||
</table>
|
||||
</dataset>
|
67
tests/mcp/post_ip_test.php
Normal file
67
tests/mcp/post_ip_test.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user