Merge pull request #304 from marc1706/ticket/303

[ticket/303] Fix character_limit() tests
This commit is contained in:
Marc Alexander
2014-07-10 00:20:10 +02:00
3 changed files with 91 additions and 2 deletions

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8" ?>
<dataset>
<table name="phpbb_user_group">
<column>group_id</column>
<column>user_id</column>
<row>
<value>1</value>
<value>2</value>
</row>
<row>
<value>2</value>
<value>2</value>
</row>
<row>
<value>3</value>
<value>2</value>
</row>
<row>
<value>5</value>
<value>3</value>
</row>
</table>
</dataset>

View File

@@ -9,6 +9,7 @@
require_once(dirname(__FILE__) . '/../../../includes/functions.php');
require_once(dirname(__FILE__) . '/../../../../../../includes/utf/utf_tools.php');
require_once(dirname(__FILE__) . '/../../../../../../includes/functions_content.php');
class phpbb_unit_functions_functions_test extends \board3\portal\tests\testframework\database_test_case
{
@@ -17,6 +18,20 @@ class phpbb_unit_functions_functions_test extends \board3\portal\tests\testframe
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/styles.xml');
}
public function setUp()
{
global $cache, $user;
parent::setUp();
$user = $this->getMock('\phpbb\user', array('optionget'));
$cache = $this->getMock('\phpbb\cache\cache', array('obtain_word_list', 'sql_exists'));
$cache->expects($this->any())
->method('obtain_word_list')
->with()
->will($this->returnValue(array('match' => array('/disallowed_word/'), 'replace' => array(''))));
}
public function data_sql_table_exists()
{
return array(
@@ -39,7 +54,8 @@ class phpbb_unit_functions_functions_test extends \board3\portal\tests\testframe
return array(
array('test', 'test', 5),
array('foooo...', 'foooooooooobar', 5),
array('wee', 'wee disallowed_word', 5),
array('wee d...', 'wee disallowed_word', 5),
array('test', 'test', 0),
);
}
@@ -48,7 +64,6 @@ class phpbb_unit_functions_functions_test extends \board3\portal\tests\testframe
*/
public function test_character_limit($expected, $input, $length)
{
$this->markTestIncomplete('Cannot test this due to issues with censor_text() and truncate_string()');
$this->assertSame($expected, character_limit($input, $length));
}
}

View File

@@ -0,0 +1,51 @@
<?php
/**
*
* @package testing
* @copyright (c) Board3 Group ( www.board3.de )
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
require_once(dirname(__FILE__) . '/../../../includes/functions.php');
class phpbb_unit_functions_get_user_groups_test extends \board3\portal\tests\testframework\database_test_case
{
public function getDataSet()
{
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/user_groups.xml');
}
public function setUp()
{
global $cache, $user;
parent::setUp();
$user = $this->getMock('\phpbb\user', array('optionget'));
$cache = $this->getMock('\phpbb\cache\cache', array('get', 'put', 'sql_exists'));
$cache->expects($this->any())
->method('get')
->with($this->anything())
->will($this->returnValue(false));
}
public function data_get_user_groups()
{
return array(
array(array(1, 2, 3), 2),
array(array(5), 3),
);
}
/**
* @dataProvider data_get_user_groups
*/
public function test_get_user_groups($expected, $user_id)
{
global $user;
$user->data['user_id'] = $user_id;
$this->assertEquals($expected, get_user_groups());
}
}