Created
July 3, 2012 21:39
-
-
Save weierophinney/3043479 to your computer and use it in GitHub Desktop.
Test code for i18n-aware validators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace ZendTest\Validator\TestAsset; | |
use Zend\I18n\Translator; | |
class ArrayTranslator implements Translator\Loader\LoaderInterface | |
{ | |
public $translations; | |
public function load($filename, $locale) | |
{ | |
return new Translator\TextDomain($this->translations); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @group i18n | |
*/ | |
public function testErrorMessagesAreTranslatedWhenTranslatorPresent() | |
{ | |
Locale::setDefault('en_US'); | |
$loader = new TestAsset\ArrayTranslator(); | |
$loader->translations = array( | |
'fooMessage' => 'This is the translated message for %value%', | |
); | |
$translator = new Translator(); | |
$translator->getPluginManager()->setService('default', $loader); | |
$translator->addTranslationFile('default', null); | |
$this->validator->setTranslator($translator); | |
$this->assertFalse($this->validator->isValid('bar')); | |
$messages = $this->validator->getMessages(); | |
$this->assertTrue(array_key_exists('fooMessage', $messages)); | |
$this->assertContains('bar', $messages['fooMessage'], var_export($messages, 1)); | |
$this->assertContains('This is the translated message for ', $messages['fooMessage']); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment