Security update for Core, with self-updated composer
[yaffs-website] / vendor / symfony / validator / Tests / Constraints / EmailValidatorTest.php
index 5933bd5ed6a65d5448f85658ba1e151bfcfb6d6e..94857c17841734663c92758cec013adc21281f96 100644 (file)
@@ -14,18 +14,13 @@ namespace Symfony\Component\Validator\Tests\Constraints;
 use Symfony\Bridge\PhpUnit\DnsMock;
 use Symfony\Component\Validator\Constraints\Email;
 use Symfony\Component\Validator\Constraints\EmailValidator;
-use Symfony\Component\Validator\Validation;
+use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
 
 /**
  * @group dns-sensitive
  */
-class EmailValidatorTest extends AbstractConstraintValidatorTest
+class EmailValidatorTest extends ConstraintValidatorTestCase
 {
-    protected function getApiVersion()
-    {
-        return Validation::API_VERSION_2_5;
-    }
-
     protected function createValidator()
     {
         return new EmailValidator(false);
@@ -108,6 +103,81 @@ class EmailValidatorTest extends AbstractConstraintValidatorTest
         $this->assertNoViolation();
     }
 
+    /**
+     * @dataProvider getInvalidEmailsForStrictChecks
+     */
+    public function testStrictWithInvalidEmails($email)
+    {
+        $constraint = new Email(array(
+            'message' => 'myMessage',
+            'strict' => true,
+        ));
+
+        $this->validator->validate($email, $constraint);
+
+        $this
+            ->buildViolation('myMessage')
+            ->setParameter('{{ value }}', '"'.$email.'"')
+            ->setCode(Email::INVALID_FORMAT_ERROR)
+            ->assertRaised();
+    }
+
+    /**
+     * @see https://github.com/egulias/EmailValidator/blob/1.2.8/tests/egulias/Tests/EmailValidator/EmailValidatorTest.php
+     */
+    public function getInvalidEmailsForStrictChecks()
+    {
+        return array(
+            array('test@example.com test'),
+            array('user  name@example.com'),
+            array('user   name@example.com'),
+            array('example.@example.co.uk'),
+            array('example@example@example.co.uk'),
+            array('(test_exampel@example.fr)'),
+            array('example(example)example@example.co.uk'),
+            array('.example@localhost'),
+            array('ex\ample@localhost'),
+            array('example@local\host'),
+            array('example@localhost.'),
+            array('user name@example.com'),
+            array('username@ example . com'),
+            array('example@(fake).com'),
+            array('example@(fake.com'),
+            array('username@example,com'),
+            array('usern,ame@example.com'),
+            array('user[na]me@example.com'),
+            array('"""@iana.org'),
+            array('"\"@iana.org'),
+            array('"test"test@iana.org'),
+            array('"test""test"@iana.org'),
+            array('"test"."test"@iana.org'),
+            array('"test".test@iana.org'),
+            array('"test"'.chr(0).'@iana.org'),
+            array('"test\"@iana.org'),
+            array(chr(226).'@iana.org'),
+            array('test@'.chr(226).'.org'),
+            array('\r\ntest@iana.org'),
+            array('\r\n test@iana.org'),
+            array('\r\n \r\ntest@iana.org'),
+            array('\r\n \r\ntest@iana.org'),
+            array('\r\n \r\n test@iana.org'),
+            array('test@iana.org \r\n'),
+            array('test@iana.org \r\n '),
+            array('test@iana.org \r\n \r\n'),
+            array('test@iana.org \r\n\r\n'),
+            array('test@iana.org  \r\n\r\n '),
+            array('test@iana/icann.org'),
+            array('test@foo;bar.com'),
+            array('test;123@foobar.com'),
+            array('test@example..com'),
+            array('email.email@email."'),
+            array('test@email>'),
+            array('test@email<'),
+            array('test@email{'),
+            array(str_repeat('x', 254).'@example.com'), //email with warnings
+        );
+    }
+
     /**
      * @dataProvider getDnsChecks
      * @requires function Symfony\Bridge\PhpUnit\DnsMock::withMockedHosts