Skip to content

Commit

Permalink
[GENERIC] Resources:
Browse files Browse the repository at this point in the history
- fixed the testbed to throw out ALL problems instead of only the first one

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@22358 44c647ce-9c0f-0410-b52a-842ac1e357ba
  • Loading branch information
thomas committed Jun 3, 2010
1 parent 1cad96f commit 97812e4
Showing 1 changed file with 75 additions and 19 deletions.
94 changes: 75 additions & 19 deletions tests/resources/languages/Zend_ValidateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,15 @@ public function setUp()
if (!is_array($translation)) {
$this->fail("Invalid or empty translation table found for language '{$fname}'");
}

$this->_translations[$fname] = $translation;
}
}
}

/**
* Tests if the given language is really a language
*/
public function testIsLocale()
{
foreach ($this->_languages as $lang) {
Expand All @@ -86,74 +90,126 @@ public function testIsLocale()
}
}

/**
* Tests if all english original keys have the same translations
*/
public function testEnglishKeySameAsValue()
{
foreach ($this->_translations['en'] as $k => $v) {
$this->assertEquals($k, $v);
$errors = array();
$cnt = 0;
foreach ($this->_translations['en'] as $key => $value) {
if ($key !== $value) {
++$cnt;
$errors['en ' . $cnt] = "The key $key is not identical in the english original";
}
}

if (!empty($errors)) {
$this->fail(var_export($errors, true));
}
}

/**
* Tests if all translation keys are also available in the english original
*/
public function testTranslationAvailableInEnglish()
{
$errors = array();
$cnt = 0;
foreach ($this->_translations as $lang => $translation) {
if ($lang == 'en') {
continue;
}

foreach ($translation as $k => $v) {
$this->assertTrue(
isset($this->_translations['en'][$k]),
$lang . ': The key "' . $k . '" isn\'t available within english translation file'
);
foreach ($translation as $key => $value) {
if (!isset($this->_translations['en'][$key])) {
++$cnt;
$errors[$lang . ' ' . $cnt] = "The key \"" . $key . "\" isn't available within english translation file";
}
}
}

if (!empty($errors)) {
$this->fail(var_export($errors, true));
}
}

/**
* Tests if the key is translated
*/
public function testTranslationDiffersFromEnglish()
{
$errors = array();
$cnt = 0;
foreach ($this->_translations as $lang => $translation) {
if ($lang == 'en') {
continue;
}

foreach ($translation as $k => $v) {
$this->assertTrue( ($k != $v),
$lang . ': The translated message "' . $v . '" is the same the english version'
);
foreach ($translation as $key => $value) {
if ($key == $value) {
++$cnt;
$errors[$lang . ' ' . $cnt] = "The translated message \"" . $value . "\" is the same the english version";
}
}
}

if (!empty($errors)) {
$this->fail(var_export($errors, true));
}
}

/**
* Tests if all placeholders from the original are also available within the translation
*/
public function testPlaceholder()
{
$errors = array();
$cnt = 0;
foreach ($this->_translations as $lang => $translation) {
if ($lang == 'en') { // not needed to test - see testEnglishKeySameAsValue
continue;
}

foreach ($translation as $k => $v) {
if (preg_match_all('/(\%.+\%)/U', $k, $matches, PREG_SET_ORDER)) {
foreach ($translation as $key => $value) {
if (preg_match_all('/(\%.+\%)/U', $key, $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) {
$this->assertContains($match[1], $v,
$lang . ': Missing placeholder "' . $match[1] . '" within "' . $v . '"');
if (!strpos($value, $match[1])) {
++$cnt;
$errors[$lang . ' ' . $cnt] = "Missing placeholder \"" . $match[1] . "\" within \"" . $value . "\"";
}
}
}
}
}

if (!empty($errors)) {
$this->fail(var_export($errors, true));
}
}

/**
* Tests if all english originals are translated
*/
public function testAllTranslated()
{
foreach ($this->_translations['en'] as $enK => $enV) {
$errors = array();
$cnt = 0;
foreach ($this->_translations['en'] as $key => $value) {
foreach ($this->_translations as $lang => $translation) {
if ($lang == 'en') {
continue;
}

$this->assertTrue(isset($translation[$enK]),
$lang . ': Message "' . $enK . '" not translated');
if (!isset($translation[$key])) {
++$cnt;
$errors[$lang . ' ' . $cnt] = "Message \"" . $key . "\" not translated";
}
}
}
}

if (!empty($errors)) {
$this->fail(var_export($errors, true));
}
}
}

0 comments on commit 97812e4

Please sign in to comment.