1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
use Piwik\DataTable;
use Piwik\DataTable\Row;
class DataTable_Filter_PatternRecursiveTest extends PHPUnit_Framework_TestCase
{
/**
* Returns a data table for testing
* @return DataTable
*/
protected function getTable()
{
$subtableAskPath1 = new DataTable();
$subtableAskPath1->addRowsFromArray(array(
array(Row::COLUMNS => array('label' => 'path1-index-page.html')),
array(Row::COLUMNS => array('label' => 'another-page')),
));
$subtableAsk = new DataTable();
$subtableAsk->addRowsFromArray(array(
array(Row::COLUMNS => array('label' => 'path1'),
Row::DATATABLE_ASSOCIATED => $subtableAskPath1),
array(Row::COLUMNS => array('label' => 'index.html')),
));
$table = new DataTable;
$rows = array(
array(Row::COLUMNS => array('label' => 'http://www.ask.com'),
Row::DATATABLE_ASSOCIATED => $subtableAsk),
array(Row::COLUMNS => array('label' => 'yahoo')),
);
$table->addRowsFromArray($rows);
return $table;
}
/**
* Dataprovider for testFilterPattern
*/
public function getTestData()
{
return array(
// level 0
array(array('hoo', array(1))),
// level 1
array(array('path1', array(0))),
// level 2
array(array('path1-index-page', array(0))),
// not found
array(array('not found', array())),
);
}
/**
* Test to filter a column with a pattern
*
* @group Core
* @dataProvider getTestData
*/
public function testFilterPattern($test)
{
$table = $this->getTable();
$rowIds = array_keys($table->getRows());
$pattern = $test[0];
$expectedRows = $test[1];
$rowToDelete = array_diff($rowIds, $expectedRows);
$expectedtable = clone $table;
$expectedtable->deleteRows($rowToDelete);
$filteredTable = clone $table;
$filteredTable->filter('PatternRecursive', array('label', $pattern));
$this->assertEquals($expectedtable->getRows(), $filteredTable->getRows());
}
}
|