/**
     * @group ZF-7490
     */
    public function testSettingHostnameMessagesThroughEmailValidator()
    {
        $translations = array(
            'hostnameIpAddressNotAllowed' => 'hostnameIpAddressNotAllowed translation',
            'hostnameUnknownTld' => 'hostnameUnknownTld translation',
            'hostnameDashCharacter' => 'hostnameDashCharacter translation',
            'hostnameInvalidHostnameSchema' => 'hostnameInvalidHostnameSchema translation',
            'hostnameUndecipherableTld' => 'hostnameUndecipherableTld translation',
            'hostnameInvalidHostname' => 'hostnameInvalidHostname translation',
            'hostnameInvalidLocalName' => 'hostnameInvalidLocalName translation',
            'hostnameLocalNameNotAllowed' => 'hostnameLocalNameNotAllowed translation',
        );

        $this->validator->setMessages($translations);
        $this->validator->isValid('_XX.!!3xx@0.239,512.777');
        $messages = $this->validator->getMessages();
        $found = false;
        foreach ($messages as $code => $message) {
            if (array_key_exists($code, $translations)) {
                $this->assertEquals($translations[$code], $message);
                $found = true;
                break;
            }
        }

        $this->assertTrue($found);
    }
Esempio n. 2
0
File: Email.php Progetto: t4web/base
 public function __construct($name = null)
 {
     $hostNameValidator = new Validator\Hostname();
     $hostNameValidator->setMessages(array(Validator\Hostname::INVALID => "Неверный тип поля", Validator\Hostname::LOCAL_NAME_NOT_ALLOWED => "", Validator\Hostname::UNKNOWN_TLD => "Неопознанное имя хоста", Validator\Hostname::INVALID_HOSTNAME => "Некорректно задано имя хоста", Validator\Hostname::CANNOT_DECODE_PUNYCODE => "", Validator\Hostname::INVALID_DASH => "", Validator\Hostname::INVALID_HOSTNAME_SCHEMA => "", Validator\Hostname::INVALID_LOCAL_NAME => "", Validator\Hostname::INVALID_URI => "", Validator\Hostname::IP_ADDRESS_NOT_ALLOWED => "", Validator\Hostname::UNDECIPHERABLE_TLD => ""));
     $validator = new Validator\EmailAddress(array('hostnameValidator' => $hostNameValidator));
     $validator->setMessages(array(Validator\EmailAddress::INVALID => "Неверный тип поля", Validator\EmailAddress::INVALID_FORMAT => "Неверный формат поля. Используйте стандартный формат local-part@hostname", Validator\EmailAddress::INVALID_HOSTNAME => "'%hostname%' некорректное имя хоста для email адреса", Validator\EmailAddress::INVALID_LOCAL_PART => "'%localPart%' некорректное имя для email адреса", Validator\EmailAddress::LENGTH_EXCEEDED => "Значение превышает допустимые размеры поля", Validator\EmailAddress::INVALID_MX_RECORD => "", Validator\EmailAddress::INVALID_SEGMENT => "", Validator\EmailAddress::DOT_ATOM => "", Validator\EmailAddress::QUOTED_STRING => ""));
     $this->getValidatorChain()->attach($validator, true);
     parent::__construct($name);
 }
Esempio n. 3
0
 public function testIdenticalAndNonIdenticalMessagesReturned()
 {
     $validator = new EmailAddress();
     $this->assertFalse($validator->isValid('*****@*****.**'));
     $this->assertCount(3, $validator->getMessages());
     $this->assertArrayHasKey(EmailAddress::INVALID_HOSTNAME, $validator->getMessages());
     $this->assertArrayHasKey(Hostname::UNKNOWN_TLD, $validator->getMessages());
     $this->assertArrayHasKey(Hostname::LOCAL_NAME_NOT_ALLOWED, $validator->getMessages());
     $validator->setMessages(array(EmailAddress::INVALID_HOSTNAME => 'This is the same error message', Hostname::UNKNOWN_TLD => 'This is the same error message'));
     $this->assertFalse($validator->isValid('*****@*****.**'));
     $this->assertCount(2, $validator->getMessages());
     $this->assertArrayHasKey(EmailAddress::INVALID_HOSTNAME, $validator->getMessages());
     $this->assertArrayHasKey(Hostname::LOCAL_NAME_NOT_ALLOWED, $validator->getMessages());
 }