Merge pull request #282 from marc1706/ticket/281
[ticket/281] Run calendar tests and extend calendar testing
This commit is contained in:
123
tests/unit/functions/functions_test.php
Normal file
123
tests/unit/functions/functions_test.php
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
<?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');
|
||||||
|
require_once(dirname(__FILE__) . '/../../../../../../includes/utf/utf_tools.php');
|
||||||
|
|
||||||
|
class phpbb_unit_functions_functions_test extends \board3\portal\tests\testframework\database_test_case
|
||||||
|
{
|
||||||
|
public function getDataSet()
|
||||||
|
{
|
||||||
|
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/styles.xml');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function data_sql_table_exists()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array(true, 'phpbb_config'),
|
||||||
|
array(true, 'phpbb_styles'),
|
||||||
|
array(false, 'phpbb_foobar'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider data_sql_table_exists
|
||||||
|
*/
|
||||||
|
public function test_sql_table_exists($expected, $table)
|
||||||
|
{
|
||||||
|
$this->assertEquals($expected, sql_table_exists($table));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function data_character_limit()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array('test', 'test', 5),
|
||||||
|
array('foooo...', 'foooooooooobar', 5),
|
||||||
|
array('wee', 'wee disallowed_word', 5),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider data_character_limit
|
||||||
|
*/
|
||||||
|
public function test_character_limit($expected, $input, $length)
|
||||||
|
{
|
||||||
|
$this->assertSame($expected, character_limit($input, $length));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function censor_text($text)
|
||||||
|
{
|
||||||
|
$text = trim(str_replace('disallowed_word', '', $text));
|
||||||
|
return $text;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Truncates string while retaining special characters if going over the max length
|
||||||
|
* The default max length is 60 at the moment
|
||||||
|
* The maximum storage length is there to fit the string within the given length. The string may be further truncated due to html entities.
|
||||||
|
* For example: string given is 'a "quote"' (length: 9), would be a stored as 'a "quote"' (length: 19)
|
||||||
|
*
|
||||||
|
* @param string $string The text to truncate to the given length. String is specialchared.
|
||||||
|
* @param int $max_length Maximum length of string (multibyte character count as 1 char / Html entity count as 1 char)
|
||||||
|
* @param int $max_store_length Maximum character length of string (multibyte character count as 1 char / Html entity count as entity chars).
|
||||||
|
* @param bool $allow_reply Allow Re: in front of string
|
||||||
|
* NOTE: This parameter can cause undesired behavior (returning strings longer than $max_store_length) and is deprecated.
|
||||||
|
* @param string $append String to be appended
|
||||||
|
*/
|
||||||
|
function truncate_string($string, $max_length = 60, $max_store_length = 255, $allow_reply = false, $append = '')
|
||||||
|
{
|
||||||
|
$chars = array();
|
||||||
|
|
||||||
|
$strip_reply = false;
|
||||||
|
$stripped = false;
|
||||||
|
if ($allow_reply && strpos($string, 'Re: ') === 0)
|
||||||
|
{
|
||||||
|
$strip_reply = true;
|
||||||
|
$string = substr($string, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
$_chars = utf8_str_split(htmlspecialchars_decode($string));
|
||||||
|
$chars = array_map('utf8_htmlspecialchars', $_chars);
|
||||||
|
|
||||||
|
// Now check the length ;)
|
||||||
|
if (sizeof($chars) > $max_length)
|
||||||
|
{
|
||||||
|
// Cut off the last elements from the array
|
||||||
|
$string = implode('', array_slice($chars, 0, $max_length - utf8_strlen($append)));
|
||||||
|
$stripped = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Due to specialchars, we may not be able to store the string...
|
||||||
|
if (utf8_strlen($string) > $max_store_length)
|
||||||
|
{
|
||||||
|
// let's split again, we do not want half-baked strings where entities are split
|
||||||
|
$_chars = utf8_str_split(htmlspecialchars_decode($string));
|
||||||
|
$chars = array_map('utf8_htmlspecialchars', $_chars);
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
array_pop($chars);
|
||||||
|
$string = implode('', $chars);
|
||||||
|
}
|
||||||
|
while (!empty($chars) && utf8_strlen($string) > $max_store_length);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($strip_reply)
|
||||||
|
{
|
||||||
|
$string = 'Re: ' . $string;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($append != '' && $stripped)
|
||||||
|
{
|
||||||
|
$string = $string . $append;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $string;
|
||||||
|
}
|
||||||
@@ -15,5 +15,4 @@ class phpbb_functions_simple_test extends PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$this->assertEquals('<br/>woot<br/><ul><li>test</li></ul>', ap_validate('<br />woot<br/><ul><li>test</li><br /></ul>'));
|
$this->assertEquals('<br/>woot<br/><ul><li>test</li></ul>', ap_validate('<br />woot<br/><ul><li>test</li><br /></ul>'));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,52 +0,0 @@
|
|||||||
<?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_functions_simple_test extends \board3\portal\tests\testframework\test_case
|
|
||||||
{
|
|
||||||
protected $path_helper;
|
|
||||||
protected $calendar;
|
|
||||||
|
|
||||||
public function setUp()
|
|
||||||
{
|
|
||||||
parent::setUp();
|
|
||||||
global $phpbb_root_path;
|
|
||||||
|
|
||||||
$this->path_helper = new \phpbb\path_helper(
|
|
||||||
new \phpbb\symfony_request(
|
|
||||||
new phpbb_mock_request()
|
|
||||||
),
|
|
||||||
new \phpbb\filesystem(),
|
|
||||||
$phpbb_root_path,
|
|
||||||
'php'
|
|
||||||
);
|
|
||||||
$this->calendar = new \board3\portal\modules\calendar(array(), null, null, null, dirname(__FILE__) . '/../../../', 'php', null, $this->path_helper);
|
|
||||||
$this->offset = strtotime('17.06.1990') - 645580800;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function data_date_to_time()
|
|
||||||
{
|
|
||||||
return array(
|
|
||||||
array(1402855200, '2014-06-15 18:00'),
|
|
||||||
array(1402855200, '15.06.2014 18:00'),
|
|
||||||
array(1402855200, '06/15/2014 6:00 PM'),
|
|
||||||
array(false, '15/06'),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @dataProvider data_date_to_time
|
|
||||||
*/
|
|
||||||
public function test_date_to_time($expected, $date)
|
|
||||||
{
|
|
||||||
$this->assertEquals($expected, $this->calendar->date_to_time($date) + $this->offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
120
tests/unit/modules/calendar_test.php
Normal file
120
tests/unit/modules/calendar_test.php
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package testing
|
||||||
|
* @copyright (c) Board3 Group ( www.board3.de )
|
||||||
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace board3\portal\modules;
|
||||||
|
|
||||||
|
require_once(dirname(__FILE__) . '/../../../includes/functions.php');
|
||||||
|
|
||||||
|
class phpbb_unit_modules_calendar_test extends \board3\portal\tests\testframework\database_test_case
|
||||||
|
{
|
||||||
|
protected $path_helper;
|
||||||
|
protected $calendar;
|
||||||
|
static $config;
|
||||||
|
|
||||||
|
protected $expected_config = array();
|
||||||
|
protected $expected_portal_config = array();
|
||||||
|
|
||||||
|
public function getDataSet()
|
||||||
|
{
|
||||||
|
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/configs.xml');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
global $cache, $phpbb_root_path;
|
||||||
|
|
||||||
|
$this->path_helper = new \phpbb\path_helper(
|
||||||
|
new \phpbb\symfony_request(
|
||||||
|
new \phpbb_mock_request()
|
||||||
|
),
|
||||||
|
new \phpbb\filesystem(),
|
||||||
|
$phpbb_root_path,
|
||||||
|
'php'
|
||||||
|
);
|
||||||
|
self::$config = new \phpbb\config\config(array());
|
||||||
|
$this->calendar = new \board3\portal\modules\calendar(array(), null, null, null, dirname(__FILE__) . '/../../../', 'php', null, $this->path_helper);
|
||||||
|
define('PORTAL_MODULES_TABLE', 'phpbb_portal_modules');
|
||||||
|
define('PORTAL_CONFIG_TABLE', 'phpbb_portal_config');
|
||||||
|
$cache = $this->getMock('\phpbb\cache\cache', array('destroy', 'sql_exists', 'get', 'put'));
|
||||||
|
$cache->expects($this->any())
|
||||||
|
->method('destroy')
|
||||||
|
->with($this->equalTo('portal_config'));
|
||||||
|
$cache->expects($this->any())
|
||||||
|
->method('get')
|
||||||
|
->with($this->anything())
|
||||||
|
->will($this->returnValue(false));
|
||||||
|
$cache->expects($this->any())
|
||||||
|
->method('sql_exists')
|
||||||
|
->with($this->anything());
|
||||||
|
$cache->expects($this->any())
|
||||||
|
->method('put')
|
||||||
|
->with($this->anything());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function data_date_to_time()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array(strtotime('2014-06-15 18:00'), '2014-06-15 18:00'),
|
||||||
|
array(strtotime('2014-06-15 18:00'), '15.06.2014 18:00'),
|
||||||
|
array(strtotime('2014-06-15 18:00'), '06/15/2014 6:00 PM'),
|
||||||
|
array(false, '15/06'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider data_date_to_time
|
||||||
|
*/
|
||||||
|
public function test_date_to_time($expected, $date)
|
||||||
|
{
|
||||||
|
$this->assertEquals($expected, $this->calendar->date_to_time($date));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_install()
|
||||||
|
{
|
||||||
|
$this->assertTrue($this->calendar->install(1));
|
||||||
|
|
||||||
|
foreach (self::$config as $key => $value)
|
||||||
|
{
|
||||||
|
$this->expected_config[$key] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
$portal_config = obtain_portal_config();
|
||||||
|
|
||||||
|
foreach ($portal_config as $key => $value)
|
||||||
|
{
|
||||||
|
$this->expected_portal_config[$key] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dependsOn test_install
|
||||||
|
*/
|
||||||
|
public function test_uninstall()
|
||||||
|
{
|
||||||
|
$this->assertNotEmpty($this->calendar->uninstall(1, $this->db));
|
||||||
|
|
||||||
|
foreach ($this->expected_config as $key => $value)
|
||||||
|
{
|
||||||
|
$this->assertFalse(isset(self::$config[$key]));
|
||||||
|
}
|
||||||
|
|
||||||
|
$portal_config = obtain_portal_config();
|
||||||
|
|
||||||
|
foreach ($this->expected_config as $key => $value)
|
||||||
|
{
|
||||||
|
$this->assertFalse(isset($portal_config[$key]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function set_config($config_name, $config_value, $is_dynamic = false)
|
||||||
|
{
|
||||||
|
phpbb_unit_modules_calendar_test::$config->set($config_name, $config_value, !$is_dynamic);
|
||||||
|
}
|
||||||
11
tests/unit/modules/fixtures/configs.xml
Normal file
11
tests/unit/modules/fixtures/configs.xml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<dataset>
|
||||||
|
<table name="phpbb_portal_config">
|
||||||
|
<column>config_name</column>
|
||||||
|
<column>config_value</column>
|
||||||
|
</table>
|
||||||
|
<table name="phpbb_config">
|
||||||
|
<column>config_name</column>
|
||||||
|
<column>config_value</column>
|
||||||
|
</table>
|
||||||
|
</dataset>
|
||||||
Reference in New Issue
Block a user