Test unicode handling features implemented in unicode.inc.
Expanded class hierarchy of UnicodeUnitTest
class UnicodeUnitTest extends UnitTestBase {
/**
* Whether to run the extended version of the tests (including non latin1 characters).
*
* @var boolean
*/
protected $extendedMode = FALSE;
public static function getInfo() {
return array(
'name' => 'Unicode handling',
'description' => 'Tests Drupal Unicode handling.',
'group' => 'System',
);
}
/**
* Test full unicode features implemented using the mbstring extension.
*/
function testMbStringUnicode() {
global $multibyte;
// mbstring was not detected on this installation, there is no way to test
// multibyte features. Treat that as an exception.
if ($multibyte == UNICODE_SINGLEBYTE) {
$this
->error(t('Unable to test Multibyte features: mbstring extension was not detected.'));
}
$multibyte = UNICODE_MULTIBYTE;
$this->extendedMode = TRUE;
$this
->pass(t('Testing in mbstring mode'));
$this
->helperTestStrToLower();
$this
->helperTestStrToUpper();
$this
->helperTestUcFirst();
$this
->helperTestStrLen();
$this
->helperTestSubStr();
$this
->helperTestTruncate();
}
/**
* Test emulated unicode features.
*/
function testEmulatedUnicode() {
global $multibyte;
$multibyte = UNICODE_SINGLEBYTE;
$this->extendedMode = FALSE;
$this
->pass(t('Testing in emulated (best-effort) mode'));
$this
->helperTestStrToLower();
$this
->helperTestStrToUpper();
$this
->helperTestUcFirst();
$this
->helperTestStrLen();
$this
->helperTestSubStr();
$this
->helperTestTruncate();
}
function helperTestStrToLower() {
$testcase = array(
'tHe QUIcK bRoWn' => 'the quick brown',
'FrançAIS is ÜBER-åwesome' => 'français is über-åwesome',
);
if ($this->extendedMode) {
$testcase['ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΣὨ'] = 'αβγδεζηθικλμνξοσὠ';
}
foreach ($testcase as $input => $output) {
$this
->assertEqual(drupal_strtolower($input), $output, format_string('%input is lowercased as %output', array(
'%input' => $input,
'%output' => $output,
)));
}
}
function helperTestStrToUpper() {
$testcase = array(
'tHe QUIcK bRoWn' => 'THE QUICK BROWN',
'FrançAIS is ÜBER-åwesome' => 'FRANÇAIS IS ÜBER-ÅWESOME',
);
if ($this->extendedMode) {
$testcase['αβγδεζηθικλμνξοσὠ'] = 'ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΣὨ';
}
foreach ($testcase as $input => $output) {
$this
->assertEqual(drupal_strtoupper($input), $output, format_string('%input is uppercased as %output', array(
'%input' => $input,
'%output' => $output,
)));
}
}
function helperTestUcFirst() {
$testcase = array(
'tHe QUIcK bRoWn' => 'THe QUIcK bRoWn',
'françAIS' => 'FrançAIS',
'über' => 'Über',
'åwesome' => 'Åwesome',
);
if ($this->extendedMode) {
$testcase['σion'] = 'Σion';
}
foreach ($testcase as $input => $output) {
$this
->assertEqual(drupal_ucfirst($input), $output, format_string('%input is ucfirst-ed as %output', array(
'%input' => $input,
'%output' => $output,
)));
}
}
function helperTestStrLen() {
$testcase = array(
'tHe QUIcK bRoWn' => 15,
'ÜBER-åwesome' => 12,
);
foreach ($testcase as $input => $output) {
$this
->assertEqual(drupal_strlen($input), $output, format_string('%input length is %output', array(
'%input' => $input,
'%output' => $output,
)));
}
}
function helperTestSubStr() {
$testcase = array(
// 012345678901234567890123
array(
'frànçAIS is über-åwesome',
0,
0,
'',
),
array(
'frànçAIS is über-åwesome',
0,
1,
'f',
),
array(
'frànçAIS is über-åwesome',
0,
8,
'frànçAIS',
),
array(
'frànçAIS is über-åwesome',
0,
23,
'frànçAIS is über-åwesom',
),
array(
'frànçAIS is über-åwesome',
0,
24,
'frànçAIS is über-åwesome',
),
array(
'frànçAIS is über-åwesome',
0,
25,
'frànçAIS is über-åwesome',
),
array(
'frànçAIS is über-åwesome',
0,
100,
'frànçAIS is über-åwesome',
),
array(
'frànçAIS is über-åwesome',
4,
4,
'çAIS',
),
array(
'frànçAIS is über-åwesome',
1,
0,
'',
),
array(
'frànçAIS is über-åwesome',
100,
0,
'',
),
array(
'frànçAIS is über-åwesome',
-4,
2,
'so',
),
array(
'frànçAIS is über-åwesome',
-4,
3,
'som',
),
array(
'frànçAIS is über-åwesome',
-4,
4,
'some',
),
array(
'frànçAIS is über-åwesome',
-4,
5,
'some',
),
array(
'frànçAIS is über-åwesome',
-7,
10,
'åwesome',
),
array(
'frànçAIS is über-åwesome',
5,
-10,
'AIS is üb',
),
array(
'frànçAIS is über-åwesome',
0,
-10,
'frànçAIS is üb',
),
array(
'frànçAIS is über-åwesome',
0,
-1,
'frànçAIS is über-åwesom',
),
array(
'frànçAIS is über-åwesome',
-7,
-2,
'åweso',
),
array(
'frànçAIS is über-åwesome',
-7,
-6,
'å',
),
array(
'frànçAIS is über-åwesome',
-7,
-7,
'',
),
array(
'frànçAIS is über-åwesome',
-7,
-8,
'',
),
array(
'...',
0,
2,
'..',
),
array(
'以呂波耳・ほへとち。リヌルヲ。',
1,
3,
'呂波耳',
),
);
foreach ($testcase as $test) {
list($input, $start, $length, $output) = $test;
$result = drupal_substr($input, $start, $length);
$this
->assertEqual($result, $output, format_string('%input substring at offset %offset for %length characters is %output (got %result)', array(
'%input' => $input,
'%offset' => $start,
'%length' => $length,
'%output' => $output,
'%result' => $result,
)));
}
}
/**
* Test decode_entities().
*/
function testDecodeEntities() {
$testcase = array(
'Drupal' => 'Drupal',
'<script>' => '<script>',
'<script>' => '<script>',
'<script>' => '<script>',
'&lt;script&gt;' => '<script>',
'"' => '"',
'"' => '"',
'&#34;' => '"',
'"' => '"',
'&quot;' => '"',
"'" => "'",
''' => "'",
'&#39;' => ''',
'©' => '©',
'©' => '©',
'©' => '©',
'→' => '→',
'→' => '→',
'➼' => '➼',
'➼' => '➼',
'€' => '€',
);
foreach ($testcase as $input => $output) {
$this
->assertEqual(decode_entities($input), $output, format_string('Make sure the decoded entity of @input is @output', array(
'@input' => $input,
'@output' => $output,
)));
}
}
/**
* Tests truncate_utf8().
*/
function helperTestTruncate() {
// Each case is an array with input string, length to truncate to, and
// expected return value.
// Test non-wordsafe, non-ellipsis cases.
$non_wordsafe_non_ellipsis_cases = array(
array(
'frànçAIS is über-åwesome',
24,
'frànçAIS is über-åwesome',
),
array(
'frànçAIS is über-åwesome',
23,
'frànçAIS is über-åwesom',
),
array(
'frànçAIS is über-åwesome',
17,
'frànçAIS is über-',
),
array(
'以呂波耳・ほへとち。リヌルヲ。',
6,
'以呂波耳・ほ',
),
);
$this
->runTruncateTests($non_wordsafe_non_ellipsis_cases, FALSE, FALSE);
// Test non-wordsafe, ellipsis cases.
$non_wordsafe_ellipsis_cases = array(
array(
'frànçAIS is über-åwesome',
24,
'frànçAIS is über-åwesome',
),
array(
'frànçAIS is über-åwesome',
23,
'frànçAIS is über-åweso…',
),
array(
'frànçAIS is über-åwesome',
17,
'frànçAIS is über…',
),
);
$this
->runTruncateTests($non_wordsafe_ellipsis_cases, FALSE, TRUE);
// Test wordsafe, ellipsis cases.
$wordsafe_ellipsis_cases = array(
array(
'123',
1,
'…',
),
array(
'123',
2,
'1…',
),
array(
'123',
3,
'123',
),
array(
'1234',
3,
'12…',
),
array(
'1234567890',
10,
'1234567890',
),
array(
'12345678901',
10,
'123456789…',
),
array(
'12345678901',
11,
'12345678901',
),
array(
'123456789012',
11,
'1234567890…',
),
array(
'12345 7890',
10,
'12345 7890',
),
array(
'12345 7890',
9,
'12345…',
),
array(
'123 567 90',
10,
'123 567 90',
),
array(
'123 567 901',
10,
'123 567…',
),
array(
'Stop. Hammertime.',
17,
'Stop. Hammertime.',
),
array(
'Stop. Hammertime.',
16,
'Stop…',
),
array(
'frànçAIS is über-åwesome',
24,
'frànçAIS is über-åwesome',
),
array(
'frànçAIS is über-åwesome',
23,
'frànçAIS is über…',
),
array(
'frànçAIS is über-åwesome',
17,
'frànçAIS is über…',
),
array(
'¿Dónde está el niño?',
20,
'¿Dónde está el niño?',
),
array(
'¿Dónde está el niño?',
19,
'¿Dónde está el…',
),
array(
'¿Dónde está el niño?',
13,
'¿Dónde está…',
),
array(
'¿Dónde está el niño?',
10,
'¿Dónde…',
),
array(
'Help! Help! Help!',
17,
'Help! Help! Help!',
),
array(
'Help! Help! Help!',
16,
'Help! Help!…',
),
array(
'Help! Help! Help!',
15,
'Help! Help!…',
),
array(
'Help! Help! Help!',
14,
'Help! Help!…',
),
array(
'Help! Help! Help!',
13,
'Help! Help!…',
),
array(
'Help! Help! Help!',
12,
'Help! Help!…',
),
array(
'Help! Help! Help!',
11,
'Help! Help…',
),
array(
'Help! Help! Help!',
10,
'Help!…',
),
array(
'Help! Help! Help!',
9,
'Help!…',
),
array(
'Help! Help! Help!',
8,
'Help!…',
),
array(
'Help! Help! Help!',
7,
'Help!…',
),
array(
'Help! Help! Help!',
6,
'Help!…',
),
array(
'Help! Help! Help!',
5,
'Help…',
),
array(
'Help! Help! Help!',
4,
'Hel…',
),
array(
'Help! Help! Help!',
3,
'He…',
),
array(
'Help! Help! Help!',
2,
'H…',
),
);
$this
->runTruncateTests($wordsafe_ellipsis_cases, TRUE, TRUE);
}
/**
* Runs test cases for helperTestTruncate().
*
* Runs each test case through truncate_utf8() and compares the output
* to the expected output.
*
* @param $cases
* Cases array. Each case is an array with the input string, length to
* truncate to, and expected output.
* @param $wordsafe
* TRUE to use word-safe truncation, FALSE to not use word-safe truncation.
* @param $ellipsis
* TRUE to append ... if the input is truncated, FALSE to not append ....
*/
function runTruncateTests($cases, $wordsafe, $ellipsis) {
foreach ($cases as $case) {
list($input, $max_length, $expected) = $case;
$output = truncate_utf8($input, $max_length, $wordsafe, $ellipsis);
$this
->assertEqual($output, $expected, format_string('%input truncate to %length characters with %wordsafe, %ellipsis is %expected (got %output)', array(
'%input' => $input,
'%length' => $max_length,
'%output' => $output,
'%expected' => $expected,
'%wordsafe' => $wordsafe ? 'word-safe' : 'not word-safe',
'%ellipsis' => $ellipsis ? 'ellipsis' : 'not ellipsis',
)));
}
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
TestBase:: |
protected | property | Assertions thrown in that test case. | |
TestBase:: |
protected | property | The database prefix of this test run. | |
TestBase:: |
protected | property | The original file directory, before it was changed for testing purposes. | |
TestBase:: |
protected | property | The original database prefix when running inside Simpletest. | |
TestBase:: |
public | property | Current results of this test case. | |
TestBase:: |
protected | property | Flag to indicate whether the test has been set up. | |
TestBase:: |
protected | property | ||
TestBase:: |
protected | property | ||
TestBase:: |
protected | property | This class is skipped when looking for the source of an assertion. | |
TestBase:: |
protected | property | The test run ID. | |
TestBase:: |
protected | property | Time limit for the test. | |
TestBase:: |
protected | property | TRUE if verbose debugging is enabled. | |
TestBase:: |
protected | property | Safe class name for use in verbose output filenames. | |
TestBase:: |
protected | property | Directory where verbose output files are put. | |
TestBase:: |
protected | property | URL to the verbose output file directory. | |
TestBase:: |
protected | property | Incrementing identifier for verbose output filenames. | |
TestBase:: |
protected | function | Internal helper: stores the assert. | |
TestBase:: |
protected | function | Check to see if two values are equal. | |
TestBase:: |
protected | function | Check to see if a value is false (an empty string, 0, NULL, or FALSE). | |
TestBase:: |
protected | function | Check to see if two values are identical. | |
TestBase:: |
protected | function | Checks to see if two objects are identical. | |
TestBase:: |
protected | function | Check to see if two values are not equal. | |
TestBase:: |
protected | function | Check to see if two values are not identical. | |
TestBase:: |
protected | function | Check to see if a value is not NULL. | |
TestBase:: |
protected | function | Check to see if a value is NULL. | |
TestBase:: |
protected | function | Check to see if a value is not false (not an empty string, 0, NULL, or FALSE). | |
TestBase:: |
protected | function | Changes the database connection to the prefixed one. | |
TestBase:: |
protected | function | Checks the matching requirements for Test. | 3 |
TestBase:: |
public static | function | Delete an assertion record by message ID. | |
TestBase:: |
protected | function | Fire an error assertion. | 1 |
TestBase:: |
public | function | Handle errors during test runs. | |
TestBase:: |
protected | function | Handle exceptions. | |
TestBase:: |
protected | function | Fire an assertion that is always negative. | |
TestBase:: |
public static | function | Ensures test files are deletable within file_unmanaged_delete_recursive(). | |
TestBase:: |
public static | function | Converts a list of possible parameters into a stack of permutations. | |
TestBase:: |
protected | function | Cycles through backtrace until the first non-assertion method is found. | |
TestBase:: |
public static | function | Returns the database connection to the site running Simpletest. | |
TestBase:: |
public static | function | Store an assertion from outside the testing context. | |
TestBase:: |
protected | function | Fire an assertion that is always positive. | |
TestBase:: |
protected | function | Generates a database prefix for running tests. | |
TestBase:: |
protected | function | Prepares the current environment for running the test. | |
TestBase:: |
public static | function | Generates a random string containing letters and numbers. | |
TestBase:: |
public static | function | Generates a random PHP object. | |
TestBase:: |
public static | function | Generates a random string of ASCII characters of codes 32 to 126. | |
TestBase:: |
protected | function | Rebuild drupal_container(). | |
TestBase:: |
public | function | Run all tests in this class. | |
TestBase:: |
protected | function | Deletes created files, database tables, and reverts all environment changes. | 10 |
TestBase:: |
protected | function | Logs verbose message in a text file. | |
UnicodeUnitTest:: |
protected | property | Whether to run the extended version of the tests (including non latin1 characters). | |
UnicodeUnitTest:: |
public static | function | ||
UnicodeUnitTest:: |
function | |||
UnicodeUnitTest:: |
function | |||
UnicodeUnitTest:: |
function | |||
UnicodeUnitTest:: |
function | |||
UnicodeUnitTest:: |
function | Tests truncate_utf8(). | ||
UnicodeUnitTest:: |
function | |||
UnicodeUnitTest:: |
function | Runs test cases for helperTestTruncate(). | ||
UnicodeUnitTest:: |
function | Test decode_entities(). | ||
UnicodeUnitTest:: |
function | Test emulated unicode features. | ||
UnicodeUnitTest:: |
function | Test full unicode features implemented using the mbstring extension. | ||
UnitTestBase:: |
protected | property | ||
UnitTestBase:: |
protected | function | Sets up unit test environment. | 22 |
UnitTestBase:: |
function |
Constructor for UnitTestBase. Overrides TestBase:: |
6 |