Exemple #1
0
    public function testErrorMessagesFromProcessAjaxAreLocalizedWhenTranslateAdapterPresent()
    {
        $translations = include __DIR__ . '/TestAsset/locale/array.php';
        $translate = new Translator('ArrayAdapter', $translations, 'en');
        $translate->setLocale('en');

        $this->form->addElements(array(
            'foo' => array(
                'type' => 'text',
                'options' => array(
                    'required'   => true,
                    'validators' => array('NotEmpty')
                )
            ),
            'bar' => array(
                'type' => 'text',
                'options' => array(
                    'required'   => true,
                    'validators' => array('Digits')
                )
            ),
        ))
        ->setTranslator($translate);

        $data = array(
            'foo' => '',
        );
        $return = $this->form->processAjax($data);
        $messages = Json::decode($return, Json::TYPE_ARRAY);
        $this->assertTrue(is_array($messages));

        $this->assertTrue(isset($messages['foo']));
        $this->assertFalse(isset($messages['bar']));

        foreach ($messages['foo'] as $key => $message) {
            if (array_key_exists($key, $translations)) {
                $this->assertEquals($translations[$key], $message);
            } else {
                $this->fail('Translation for ' . $key . ' does not exist?');
            }
        }
    }
Exemple #2
0
 public function testErrorMessagesFromProcessAjaxAreLocalizedWhenTranslateAdapterPresent()
 {
     $this->_checkZf2794();
     $translations = (include dirname(__FILE__) . '/_files/locale/array.php');
     $translate = new Zend_Translate('array', $translations, 'en');
     $translate->setLocale('en');
     $this->form->addElements(array('foo' => array('type' => 'text', 'options' => array('required' => true, 'validators' => array('NotEmpty'))), 'bar' => array('type' => 'text', 'options' => array('required' => true, 'validators' => array('Digits')))))->setTranslator($translate);
     $data = array('foo' => '');
     $return = $this->form->processAjax($data);
     $messages = Zend_Json::decode($return);
     $this->assertTrue(is_array($messages));
     $this->assertTrue(isset($messages['foo']));
     $this->assertFalse(isset($messages['bar']));
     foreach ($messages['foo'] as $key => $message) {
         if (array_key_exists($key, $translations)) {
             $this->assertEquals($translations[$key], $message);
         } else {
             $this->fail('Translation for ' . $key . ' does not exist?');
         }
     }
 }