Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Currently we only support a very loose validation. There is now a standard HTML5 element with matching regex. This will add the ability to set a `mode` on the email validator. The mode will change the validation that is applied to the field as a whole. These modes are: * loose: The pattern from previous Symfony versions (default) * strict: Strictly matching the RFC * html5: The regex used for the HTML5 Element Deprecates the `strict=true` parameter in favour of `mode='strict'`
- Loading branch information
1 parent
98dae3e
commit a7af07e
Showing
5 changed files
with
312 additions
and
10 deletions.
There are no files selected for viewing
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
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
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
46 changes: 46 additions & 0 deletions
46
src/Symfony/Component/Validator/Tests/Constraints/EmailTest.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Validator\Tests\Constraints; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Validator\Constraints\Email; | ||
use Symfony\Component\Validator\Constraints\File; | ||
|
||
class EmailTest extends TestCase | ||
{ | ||
/** | ||
* @expectedDeprecation The 'strict' property is deprecated since version 3.4 and will be removed in 4.0. Use 'mode'=>"strict" instead. | ||
* @group legacy | ||
*/ | ||
public function testLegacyConstructorStrict() | ||
{ | ||
$subject = new Email(array('strict' => true)); | ||
|
||
$this->assertTrue($subject->strict); | ||
} | ||
|
||
public function testConstructorStrict() | ||
{ | ||
$subject = new Email(array('mode' => Email::VALIDATION_MODE_STRICT)); | ||
|
||
$this->assertEquals(Email::VALIDATION_MODE_STRICT, $subject->mode); | ||
} | ||
|
||
/** | ||
* @expectedException \InvalidArgumentException | ||
* @expectedExceptionMessage The 'mode' parameter value is not valid. | ||
*/ | ||
public function testUnknownModesTriggerException() | ||
{ | ||
new Email(array('mode' => 'Unknown Mode')); | ||
} | ||
} |
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