| 1 |
<?php |
<?php |
| 2 |
// $Id: l10n_community.test,v 1.1.2.3 2009/09/08 11:23:30 goba Exp $ |
// $Id: potx.test,v 1.1.4.2 2009/11/17 12:33:17 goba Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 21 |
parent::setUp('locale', 'potx'); |
parent::setUp('locale', 'potx'); |
| 22 |
// Add potx.inc which we test for its functionality. |
// Add potx.inc which we test for its functionality. |
| 23 |
include_once(drupal_get_path('module', 'potx') .'/potx.inc'); |
include_once(drupal_get_path('module', 'potx') .'/potx.inc'); |
| 24 |
|
// Store empty error message for reuse in multiple cases. |
| 25 |
|
$this->empty_error = t('Empty string attempted to be localized. Please do not leave test code for localization in your source.'); |
| 26 |
} |
} |
| 27 |
|
|
| 28 |
/** |
/** |
| 59 |
$this->assertMsgID('Dynamic callback test string'); |
$this->assertMsgID('Dynamic callback test string'); |
| 60 |
$this->assertNoMsgID('1 test string'); |
$this->assertNoMsgID('1 test string'); |
| 61 |
$this->assertNoMsgID('This is a test string.'); |
$this->assertNoMsgID('This is a test string.'); |
| 62 |
|
|
| 63 |
|
$this->assert(count($this->potx_status) == 3, t('3 error messages found')); |
| 64 |
|
$this->assert($this->potx_status[0][0] == $this->empty_error, t('First empty error found.')); |
| 65 |
|
$this->assert($this->potx_status[1][0] == $this->empty_error, t('Second empty error found.')); |
| 66 |
|
$this->assert($this->potx_status[2][0] == $this->empty_error, t('Third empty error found.')); |
| 67 |
} |
} |
| 68 |
|
|
| 69 |
/** |
/** |
| 99 |
$this->assertMsgID('Dynamic callback test string'); |
$this->assertMsgID('Dynamic callback test string'); |
| 100 |
$this->assertNoMsgID('1 test string'); |
$this->assertNoMsgID('1 test string'); |
| 101 |
$this->assertNoMsgID('This is a test string.'); |
$this->assertNoMsgID('This is a test string.'); |
| 102 |
|
|
| 103 |
|
$this->assert(count($this->potx_status) == 3, t('3 error messages found')); |
| 104 |
|
$this->assert($this->potx_status[0][0] == $this->empty_error, t('First empty error found.')); |
| 105 |
|
$this->assert($this->potx_status[1][0] == $this->empty_error, t('Second empty error found.')); |
| 106 |
|
$this->assert($this->potx_status[2][0] == $this->empty_error, t('Third empty error found.')); |
| 107 |
} |
} |
| 108 |
|
|
| 109 |
/** |
/** |
| 144 |
$this->assertMsgID('Dynamic callback test string'); |
$this->assertMsgID('Dynamic callback test string'); |
| 145 |
$this->assertNoMsgID('1 test string'); |
$this->assertNoMsgID('1 test string'); |
| 146 |
$this->assertNoMsgID('This is a test string.'); |
$this->assertNoMsgID('This is a test string.'); |
| 147 |
|
|
| 148 |
|
$this->assert(count($this->potx_status) == 2, t('2 error messages found')); |
| 149 |
|
$this->assert($this->potx_status[0][0] == $this->empty_error, t('First empty error found.')); |
| 150 |
|
$this->assert($this->potx_status[1][0] == $this->empty_error, t('Second empty error found.')); |
| 151 |
} |
} |
| 152 |
|
|
| 153 |
/** |
/** |
| 178 |
$this->assertPluralID('@count test strings in JS'); |
$this->assertPluralID('@count test strings in JS'); |
| 179 |
$this->assertMsgID('Another test string in JS'); |
$this->assertMsgID('Another test string in JS'); |
| 180 |
$this->assertMsgID('Embedded test string in JS'); |
$this->assertMsgID('Embedded test string in JS'); |
| 181 |
|
|
| 182 |
|
$this->assert(count($this->potx_status) == 1, t('1 error message found')); |
| 183 |
|
$this->assert($this->potx_status[0][0] == $this->empty_error, t('Empty error found.')); |
| 184 |
} |
} |
| 185 |
|
|
| 186 |
/** |
/** |
| 190 |
global $_potx_store, $_potx_strings, $_potx_install; |
global $_potx_store, $_potx_strings, $_potx_install; |
| 191 |
$_potx_store = $_potx_strings = $_potx_install = array(); |
$_potx_store = $_potx_strings = $_potx_install = array(); |
| 192 |
|
|
| 193 |
|
potx_status('set', POTX_STATUS_STRUCTURED); |
| 194 |
_potx_process_file($filename, 0, '_potx_save_string', '_potx_save_version', $api_version); |
_potx_process_file($filename, 0, '_potx_save_string', '_potx_save_version', $api_version); |
| 195 |
_potx_build_files($string_mode, POTX_BUILD_SINGLE, 'general', '_potx_save_string', '_potx_save_version', '_potx_get_header', NULL, NULL, $api_version); |
_potx_build_files($string_mode, POTX_BUILD_SINGLE, 'general', '_potx_save_string', '_potx_save_version', '_potx_get_header', NULL, NULL, $api_version); |
| 196 |
|
|
| 198 |
ob_start(); |
ob_start(); |
| 199 |
_potx_write_files('potx-test.po'); |
_potx_write_files('potx-test.po'); |
| 200 |
$this->potx_output = ob_get_clean(); |
$this->potx_output = ob_get_clean(); |
| 201 |
$this->pass(var_export($this->potx_output, TRUE)); |
// $this->pass(var_export($this->potx_output, TRUE)); |
| 202 |
} |
$this->potx_status = potx_status('get', TRUE); |
| 203 |
|
// $this->pass(var_export($this->potx_status, TRUE)); |
| 204 |
|
} |
| 205 |
|
|
| 206 |
/** |
/** |
| 207 |
* Helper function to assert an msgid construct in the .po file. |
* Helper function to assert an msgid construct in the .po file. |
| 253 |
$this->assert(strpos($this->potx_output, 'msgid_plural "'. _potx_format_quoted_string('"'. $string . '"') .'"') !== FALSE, $message, $group); |
$this->assert(strpos($this->potx_output, 'msgid_plural "'. _potx_format_quoted_string('"'. $string . '"') .'"') !== FALSE, $message, $group); |
| 254 |
} |
} |
| 255 |
|
|
| 256 |
|
/** |
| 257 |
|
* Debug functionality until simpletest built-in debugging is backported. |
| 258 |
|
*/ |
| 259 |
|
private function outputScreenContents($description = 'output', $basename = 'output') { |
| 260 |
|
// This is a hack to get a directory that won't be cleaned up by simpletest |
| 261 |
|
$file_dir = file_directory_path() .'/../simpletest_output_pages'; |
| 262 |
|
if (!is_dir($file_dir)) { |
| 263 |
|
mkdir($file_dir, 0777, TRUE); |
| 264 |
|
} |
| 265 |
|
$output_path = "$file_dir/$basename.". $this->randomName(10) .'.html'; |
| 266 |
|
$rv = file_put_contents($output_path, $this->drupalGetContent()); |
| 267 |
|
$this->pass("$description: ". l('Contents of result page', $output_path)); |
| 268 |
|
} |
| 269 |
|
|
| 270 |
} |
} |