mirror of
https://github.com/phpbb/phpbb.git
synced 2025-04-20 07:42:09 +02:00
- merge r9084 and r9085
- added tests for make_clickable git-svn-id: file:///svn/phpbb/trunk@9086 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
parent
04f7c1da69
commit
efe06af913
@ -496,7 +496,8 @@ function generate_text_for_edit($text, $uid, $flags)
|
||||
*/
|
||||
function make_clickable_callback($type, $whitespace, $url, $relative_url, $class)
|
||||
{
|
||||
$orig_url = $url . $relative_url;
|
||||
$orig_url = $url;
|
||||
$orig_relative = $relative_url;
|
||||
$append = '';
|
||||
$url = htmlspecialchars_decode($url);
|
||||
$relative_url = htmlspecialchars_decode($relative_url);
|
||||
@ -561,6 +562,12 @@ function make_clickable_callback($type, $whitespace, $url, $relative_url, $class
|
||||
$url = substr($url, 0, -1);
|
||||
}
|
||||
break;
|
||||
|
||||
// set last_char to empty here, so the variable can be used later to
|
||||
// check whether a character was removed
|
||||
default:
|
||||
$last_char = '';
|
||||
break;
|
||||
}
|
||||
|
||||
$short_url = (strlen($url) > 55) ? substr($url, 0, 39) . ' ... ' . substr($url, -10) : $url;
|
||||
@ -578,7 +585,7 @@ function make_clickable_callback($type, $whitespace, $url, $relative_url, $class
|
||||
// don't touch it and let MAGIC_URL_FULL take care of it.
|
||||
if (!$relative_url)
|
||||
{
|
||||
return $whitespace . $orig_url . '/'; // slash is taken away by relative url pattern
|
||||
return $whitespace . $orig_url . '/' . $orig_relative; // slash is taken away by relative url pattern
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -23,6 +23,7 @@ require_once 'utf/all_tests.php';
|
||||
require_once 'request/all_tests.php';
|
||||
require_once 'security/all_tests.php';
|
||||
require_once 'template/all_tests.php';
|
||||
require_once 'text_processing/all_tests.php';
|
||||
|
||||
// exclude the test directory from code coverage reports
|
||||
PHPUnit_Util_Filter::addDirectoryToFilter('./');
|
||||
@ -39,10 +40,11 @@ class phpbb_all_tests
|
||||
$suite = new PHPUnit_Framework_TestSuite('phpBB');
|
||||
|
||||
$suite->addTest(phpbb_bbcode_all_tests::suite());
|
||||
$suite->addTest(phpbb_utf_all_tests::suite());
|
||||
$suite->addTest(phpbb_request_all_tests::suite());
|
||||
$suite->addTest(phpbb_security_all_tests::suite());
|
||||
$suite->addTest(phpbb_template_all_tests::suite());
|
||||
$suite->addTest(phpbb_text_processing_all_tests::suite());
|
||||
$suite->addTest(phpbb_utf_all_tests::suite());
|
||||
|
||||
return $suite;
|
||||
}
|
||||
|
44
tests/text_processing/all_tests.php
Normal file
44
tests/text_processing/all_tests.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @version $Id$
|
||||
* @copyright (c) 2008 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
*
|
||||
*/
|
||||
|
||||
define('IN_PHPBB', true);
|
||||
|
||||
if (!defined('PHPUnit_MAIN_METHOD'))
|
||||
{
|
||||
define('PHPUnit_MAIN_METHOD', 'phpbb_text_processing_all_tests::main');
|
||||
}
|
||||
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
require_once 'PHPUnit/TextUI/TestRunner.php';
|
||||
|
||||
require_once 'text_processing/make_clickable.php';
|
||||
|
||||
class phpbb_text_processing_all_tests
|
||||
{
|
||||
public static function main()
|
||||
{
|
||||
PHPUnit_TextUI_TestRunner::run(self::suite());
|
||||
}
|
||||
|
||||
public static function suite()
|
||||
{
|
||||
$suite = new PHPUnit_Framework_TestSuite('phpBB Text Processing Tools');
|
||||
|
||||
$suite->addTestSuite('phpbb_text_processing_make_clickable_test');
|
||||
|
||||
return $suite;
|
||||
}
|
||||
}
|
||||
|
||||
if (PHPUnit_MAIN_METHOD == 'phpbb_text_processing_all_tests::main')
|
||||
{
|
||||
phpbb_text_processing_all_tests::main();
|
||||
}
|
||||
?>
|
109
tests/text_processing/make_clickable.php
Normal file
109
tests/text_processing/make_clickable.php
Normal file
@ -0,0 +1,109 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @version $Id$
|
||||
* @copyright (c) 2008 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
*
|
||||
*/
|
||||
|
||||
define('IN_PHPBB', true);
|
||||
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
|
||||
require_once '../phpBB/includes/functions.php';
|
||||
require_once '../phpBB/includes/functions_content.php';
|
||||
|
||||
class phpbb_text_processing_make_clickable_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public static function make_clickable_data()
|
||||
{
|
||||
// value => whether it should work
|
||||
$prefix_texts = array(
|
||||
'' => true,
|
||||
"np \n" => true,
|
||||
'bp text ' => true,
|
||||
'cp text>' => true,
|
||||
'ep text.' => array('w' => false), // doesn't work for www. type urls, but for everything else
|
||||
);
|
||||
$suffix_texts = array(
|
||||
'' => true,
|
||||
"\n ns" => true,
|
||||
' bs text.' => true,
|
||||
'>cs text' => true,
|
||||
'"ds text' => true,
|
||||
'. es text.' => true,
|
||||
', fs text.' => true,
|
||||
);
|
||||
|
||||
$urls = array(
|
||||
'http://example.com' => array('tag' => 'm', 'url' => false, 'text' => false), // false means same as key
|
||||
'http://example.com/' => array('tag' => 'm', 'url' => false, 'text' => false),
|
||||
'http://example.com/path?query=abc' => array('tag' => 'm', 'url' => false, 'text' => false),
|
||||
'http://example.com/1' => array('tag' => 'm', 'url' => false, 'text' => false),
|
||||
'http://example.com/some/very/long/path/with/over/55/characters?and=a&long=query&too=1' => array('tag' => 'm', 'url' => false, 'text' => 'http://example.com/some/very/long/path/ ... uery&too=1'),
|
||||
'http://localhost' => array('tag' => 'm', 'url' => false, 'text' => false),
|
||||
'http://localhost/#abc' => array('tag' => 'm', 'url' => false, 'text' => false),
|
||||
|
||||
'www.example.com/path/' => array('tag' => 'w', 'url' => 'http://www.example.com/path/', 'text' => false),
|
||||
'randomwww.example.com/path/' => false,
|
||||
|
||||
'http://thisdomain.org' => array('tag' => 'm', 'url' => false, 'text' => false),
|
||||
'http://thisdomain.org/' => array('tag' => 'm', 'url' => false, 'text' => false),
|
||||
'http://thisdomain.org/1' => array('tag' => 'l', 'url' => false, 'text' => '1'),
|
||||
'http://thisdomain.org/path/some?query=abc#test' => array('tag' => 'l', 'url' => false, 'text' => 'path/some?query=abc#test'),
|
||||
|
||||
'javascript:www.example.com/' => false,
|
||||
);
|
||||
|
||||
$test_data = array();
|
||||
|
||||
// run the test for each combination
|
||||
foreach ($prefix_texts as $prefix => $prefix_success)
|
||||
{
|
||||
foreach ($suffix_texts as $suffix => $suffix_success)
|
||||
{
|
||||
foreach ($urls as $url => $url_type)
|
||||
{
|
||||
$input = $prefix . $schema . $url . $suffix;
|
||||
// no valid url => no change
|
||||
$output = $input;
|
||||
|
||||
if (
|
||||
($prefix_success && $suffix_success && is_array($url_type)) &&
|
||||
// handle except syntax for prefix/suffix
|
||||
(!is_array($prefix_success) || !isset($prefix_success[$url_type['tag']]) || $prefix_success[$url_type['tag']] == true) &&
|
||||
(!is_array($suffix_success) || !isset($suffix_success[$url_type['tag']]) || $suffix_success[$url_type['tag']] == true)
|
||||
)
|
||||
{
|
||||
// false means it's the same as the url, less typing
|
||||
$url_type['url'] = ($url_type['url']) ? $url_type['url'] : $url;
|
||||
$url_type['text'] = ($url_type['text']) ? $url_type['text'] : $url;
|
||||
|
||||
$class = ($url_type['tag'] === 'l') ? 'postlink-local' : 'postlink';
|
||||
|
||||
// replace the url with the desired output format
|
||||
$output = $prefix . '<!-- ' . $url_type['tag'] . ' --><a class="' . $class . '" href="' . $url_type['url'] . '">' . $url_type['text'] . '</a><!-- ' . $url_type['tag'] . ' -->' . $suffix;
|
||||
}
|
||||
$test_data[] = array($input, $output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $test_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider make_clickable_data
|
||||
*/
|
||||
public function test_make_clickable($input, $expected)
|
||||
{
|
||||
$result = make_clickable($input, 'http://thisdomain.org');
|
||||
|
||||
$label = 'Making text clickable: ' . $input;
|
||||
$this->assertEquals($expected, $result, $label);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user