mockApplication(); } public function testValidateValue() { $validator = new EmailValidator(); $this->assertTrue($validator->validate('sam@rmcreative.ru')); $this->assertTrue($validator->validate('5011@gmail.com')); $this->assertFalse($validator->validate('rmcreative.ru')); $this->assertFalse($validator->validate('Carsten Brandt ')); $this->assertFalse($validator->validate('"Carsten Brandt" ')); $this->assertFalse($validator->validate('')); $this->assertFalse($validator->validate('info@örtliches.de')); $this->assertFalse($validator->validate('sam@рмкреатиф.ru')); $validator->allowName = true; $this->assertTrue($validator->validate('sam@rmcreative.ru')); $this->assertTrue($validator->validate('5011@gmail.com')); $this->assertFalse($validator->validate('rmcreative.ru')); $this->assertTrue($validator->validate('Carsten Brandt ')); $this->assertTrue($validator->validate('"Carsten Brandt" ')); $this->assertTrue($validator->validate('')); $this->assertFalse($validator->validate('info@örtliches.de')); $this->assertFalse($validator->validate('sam@рмкреатиф.ru')); $this->assertFalse($validator->validate('Informtation info@oertliches.de')); $this->assertTrue($validator->validate('test@example.com')); $this->assertTrue($validator->validate('John Smith ')); $this->assertFalse($validator->validate('John Smith ')); } public function testValidateValueIdn() { if (!function_exists('idn_to_ascii')) { $this->markTestSkipped('Intl extension required'); return; } $validator = new EmailValidator(); $validator->enableIDN = true; $this->assertTrue($validator->validate('5011@example.com')); $this->assertTrue($validator->validate('example@äüößìà.de')); $this->assertTrue($validator->validate('example@xn--zcack7ayc9a.de')); $this->assertTrue($validator->validate('info@örtliches.de')); $this->assertTrue($validator->validate('sam@рмкреатиф.ru')); $this->assertTrue($validator->validate('sam@rmcreative.ru')); $this->assertTrue($validator->validate('5011@gmail.com')); $this->assertFalse($validator->validate('rmcreative.ru')); $this->assertFalse($validator->validate('Carsten Brandt ')); $this->assertFalse($validator->validate('"Carsten Brandt" ')); $this->assertFalse($validator->validate('')); $validator->allowName = true; $this->assertTrue($validator->validate('info@örtliches.de')); $this->assertTrue($validator->validate('Informtation ')); $this->assertFalse($validator->validate('Informtation info@örtliches.de')); $this->assertTrue($validator->validate('sam@рмкреатиф.ru')); $this->assertTrue($validator->validate('sam@rmcreative.ru')); $this->assertTrue($validator->validate('5011@gmail.com')); $this->assertFalse($validator->validate('rmcreative.ru')); $this->assertTrue($validator->validate('Carsten Brandt ')); $this->assertTrue($validator->validate('"Carsten Brandt" ')); $this->assertTrue($validator->validate('')); $this->assertTrue($validator->validate('test@example.com')); $this->assertTrue($validator->validate('John Smith ')); $this->assertFalse($validator->validate('John Smith ')); } public function testValidateValueMx() { $validator = new EmailValidator(); $validator->checkDNS = true; $this->assertTrue($validator->validate('5011@gmail.com')); $validator->checkDNS = false; $this->assertTrue($validator->validate('test@nonexistingsubdomain.example.com')); $validator->checkDNS = true; $this->assertFalse($validator->validate('test@nonexistingsubdomain.example.com')); } public function testValidateAttribute() { $val = new EmailValidator(); $model = new FakedValidationModel(); $model->attr_email = '5011@gmail.com'; $val->validateAttribute($model, 'attr_email'); $this->assertFalse($model->hasErrors('attr_email')); } }