TYPO3  7.6
RegexTest.php
Go to the documentation of this file.
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 
13 
15 
16 class RegexTest extends \PHPUnit_Framework_TestCase
17 {
21  public function testHasFlags($regex, $start, $end)
22  {
23  $expr = new Expression($regex);
24 
25  $this->assertEquals($start, $expr->getRegex()->hasStartFlag());
26  $this->assertEquals($end, $expr->getRegex()->hasEndFlag());
27  }
28 
32  public function testHasJokers($regex, $start, $end)
33  {
34  $expr = new Expression($regex);
35 
36  $this->assertEquals($start, $expr->getRegex()->hasStartJoker());
37  $this->assertEquals($end, $expr->getRegex()->hasEndJoker());
38  }
39 
43  public function testSetFlags($regex, $start, $end, $expected)
44  {
45  $expr = new Expression($regex);
46  $expr->getRegex()->setStartFlag($start)->setEndFlag($end);
47 
48  $this->assertEquals($expected, $expr->render());
49  }
50 
54  public function testSetJokers($regex, $start, $end, $expected)
55  {
56  $expr = new Expression($regex);
57  $expr->getRegex()->setStartJoker($start)->setEndJoker($end);
58 
59  $this->assertEquals($expected, $expr->render());
60  }
61 
62  public function testOptions()
63  {
64  $expr = new Expression('~abc~is');
65  $expr->getRegex()->removeOption('i')->addOption('m');
66 
67  $this->assertEquals('~abc~sm', $expr->render());
68  }
69 
70  public function testMixFlagsAndJokers()
71  {
72  $expr = new Expression('~^.*abc.*$~is');
73 
74  $expr->getRegex()->setStartFlag(false)->setEndFlag(false)->setStartJoker(false)->setEndJoker(false);
75  $this->assertEquals('~abc~is', $expr->render());
76 
77  $expr->getRegex()->setStartFlag(true)->setEndFlag(true)->setStartJoker(true)->setEndJoker(true);
78  $this->assertEquals('~^.*abc.*$~is', $expr->render());
79  }
80 
84  public function testReplaceJokers($regex, $expected)
85  {
86  $expr = new Expression($regex);
87  $expr = $expr->getRegex()->replaceJokers('@');
88 
89  $this->assertEquals($expected, $expr->renderPattern());
90  }
91 
92  public function getHasFlagsData()
93  {
94  return array(
95  array('~^abc~', true, false),
96  array('~abc$~', false, true),
97  array('~abc~', false, false),
98  array('~^abc$~', true, true),
99  array('~^abc\\$~', true, false),
100  );
101  }
102 
103  public function getHasJokersData()
104  {
105  return array(
106  array('~.*abc~', true, false),
107  array('~abc.*~', false, true),
108  array('~abc~', false, false),
109  array('~.*abc.*~', true, true),
110  array('~.*abc\\.*~', true, false),
111  );
112  }
113 
114  public function getSetFlagsData()
115  {
116  return array(
117  array('~abc~', true, false, '~^abc~'),
118  array('~abc~', false, true, '~abc$~'),
119  array('~abc~', false, false, '~abc~'),
120  array('~abc~', true, true, '~^abc$~'),
121  );
122  }
123 
124  public function getSetJokersData()
125  {
126  return array(
127  array('~abc~', true, false, '~.*abc~'),
128  array('~abc~', false, true, '~abc.*~'),
129  array('~abc~', false, false, '~abc~'),
130  array('~abc~', true, true, '~.*abc.*~'),
131  );
132  }
133 
134  public function getReplaceJokersTestData()
135  {
136  return array(
137  array('~.abc~', '@abc'),
138  array('~\\.abc~', '\\.abc'),
139  array('~\\\\.abc~', '\\\\@abc'),
140  array('~\\\\\\.abc~', '\\\\\\.abc'),
141  );
142  }
143 }