|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Graze\Sprout\Test\Unit\Parser; |
|
4
|
|
|
|
|
5
|
|
|
use Graze\Sprout\Parser\TableFilterer; |
|
6
|
|
|
use Graze\Sprout\Test\TestCase; |
|
7
|
|
|
|
|
8
|
|
|
class TableFilterableTest extends TestCase |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @dataProvider filterData |
|
12
|
|
|
* |
|
13
|
|
|
* @param string[] $tables |
|
14
|
|
|
* @param string[] $excludes |
|
15
|
|
|
* @param string[] $expected |
|
16
|
|
|
*/ |
|
17
|
|
|
public function testFilter(array $tables, array $excludes, array $expected) |
|
18
|
|
|
{ |
|
19
|
|
|
$tableFilterer = new TableFilterer(); |
|
20
|
|
|
|
|
21
|
|
|
$output = $tableFilterer->filter($tables, $excludes); |
|
22
|
|
|
|
|
23
|
|
|
$this->assertEquals($expected, $output); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @return array |
|
28
|
|
|
*/ |
|
29
|
|
|
public function filterData() |
|
30
|
|
|
{ |
|
31
|
|
|
return [ |
|
32
|
|
|
[ // test standard string matching |
|
33
|
|
|
['table1', 'table2', 'table3'], |
|
34
|
|
|
['table1'], |
|
35
|
|
|
['table2', 'table3'], |
|
36
|
|
|
], |
|
37
|
|
|
[ // test simple regex |
|
38
|
|
|
['table1', 'table2', 'table3'], |
|
39
|
|
|
['table[23]'], |
|
40
|
|
|
['table1'], |
|
41
|
|
|
], |
|
42
|
|
|
[ // test multiple excludes |
|
43
|
|
|
['table1', 'table2', 'table3'], |
|
44
|
|
|
['table2', 'table3'], |
|
45
|
|
|
['table1'], |
|
46
|
|
|
], |
|
47
|
|
|
[ // test multiple regex |
|
48
|
|
|
['table1', 'table2', 'table11', 'table12'], |
|
49
|
|
|
['table\d', 'table[1]{2}'], |
|
50
|
|
|
['table12'], |
|
51
|
|
|
], |
|
52
|
|
|
[ // test complex regex |
|
53
|
|
|
['table1', 'Table2', 'table11', 'table1s'], |
|
54
|
|
|
['/^table\d{1}(?!\d)/i'], |
|
55
|
|
|
['table11'], |
|
56
|
|
|
], |
|
57
|
|
|
]; |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|