Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / symfony / validator / Tests / Constraints / RegexTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\Validator\Tests\Constraints;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Validator\Constraints\Regex;
16
17 /**
18  * @author Bernhard Schussek <bschussek@gmail.com>
19  */
20 class RegexTest extends TestCase
21 {
22     public function testConstraintGetDefaultOption()
23     {
24         $constraint = new Regex('/^[0-9]+$/');
25
26         $this->assertSame('/^[0-9]+$/', $constraint->pattern);
27     }
28
29     public function provideHtmlPatterns()
30     {
31         return array(
32             // HTML5 wraps the pattern in ^(?:pattern)$
33             array('/^[0-9]+$/', '[0-9]+'),
34             array('/[0-9]+$/', '.*[0-9]+'),
35             array('/^[0-9]+/', '[0-9]+.*'),
36             array('/[0-9]+/', '.*[0-9]+.*'),
37             // We need a smart way to allow matching of patterns that contain
38             // ^ and $ at various sub-clauses of an or-clause
39             // .*(pattern).* seems to work correctly
40             array('/[0-9]$|[a-z]+/', '.*([0-9]$|[a-z]+).*'),
41             array('/[0-9]$|^[a-z]+/', '.*([0-9]$|^[a-z]+).*'),
42             array('/^[0-9]|[a-z]+$/', '.*(^[0-9]|[a-z]+$).*'),
43             // Unescape escaped delimiters
44             array('/^[0-9]+\/$/', '[0-9]+/'),
45             array('#^[0-9]+\#$#', '[0-9]+#'),
46             // Cannot be converted
47             array('/^[0-9]+$/i', null),
48
49             // Inverse matches are simple, just wrap in
50             // ((?!pattern).)*
51             array('/^[0-9]+$/', '((?!^[0-9]+$).)*', false),
52             array('/[0-9]+$/', '((?![0-9]+$).)*', false),
53             array('/^[0-9]+/', '((?!^[0-9]+).)*', false),
54             array('/[0-9]+/', '((?![0-9]+).)*', false),
55             array('/[0-9]$|[a-z]+/', '((?![0-9]$|[a-z]+).)*', false),
56             array('/[0-9]$|^[a-z]+/', '((?![0-9]$|^[a-z]+).)*', false),
57             array('/^[0-9]|[a-z]+$/', '((?!^[0-9]|[a-z]+$).)*', false),
58             array('/^[0-9]+\/$/', '((?!^[0-9]+/$).)*', false),
59             array('#^[0-9]+\#$#', '((?!^[0-9]+#$).)*', false),
60             array('/^[0-9]+$/i', null, false),
61         );
62     }
63
64     /**
65      * @dataProvider provideHtmlPatterns
66      */
67     public function testGetHtmlPattern($pattern, $htmlPattern, $match = true)
68     {
69         $constraint = new Regex(array(
70             'pattern' => $pattern,
71             'match' => $match,
72         ));
73
74         $this->assertSame($pattern, $constraint->pattern);
75         $this->assertSame($htmlPattern, $constraint->getHtmlPattern());
76     }
77
78     public function testGetCustomHtmlPattern()
79     {
80         $constraint = new Regex(array(
81             'pattern' => '((?![0-9]$|[a-z]+).)*',
82             'htmlPattern' => 'foobar',
83         ));
84
85         $this->assertSame('((?![0-9]$|[a-z]+).)*', $constraint->pattern);
86         $this->assertSame('foobar', $constraint->getHtmlPattern());
87     }
88 }