Welcome to mirror list, hosted at ThFree Co, Russian Federation.

PatternRecursiveTest.php « Filter « DataTable « Core « PHPUnit « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5efc2dac7abec3c8033def4750a248a50575a0e3 (plain)
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 - Open source web analytics
 *
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */
class DataTable_Filter_PatternRecursiveTest extends PHPUnit_Framework_TestCase
{
    /**
     * Returns a data table for testing
     * @return Piwik_DataTable
     */
    protected function getTable()
    {
        $subtableAskPath1 = new Piwik_DataTable();
        $subtableAskPath1->addRowsFromArray(array(
                                                 array(Piwik_DataTable_Row::COLUMNS => array('label' => 'path1-index-page.html')),
                                                 array(Piwik_DataTable_Row::COLUMNS => array('label' => 'another-page')),
                                            ));

        $subtableAsk = new Piwik_DataTable();
        $subtableAsk->addRowsFromArray(array(
                                            array(Piwik_DataTable_Row::COLUMNS              => array('label' => 'path1'),
                                                  Piwik_DataTable_Row::DATATABLE_ASSOCIATED => $subtableAskPath1),
                                            array(Piwik_DataTable_Row::COLUMNS => array('label' => 'index.html')),
                                       ));

        $table = new Piwik_DataTable;
        $rows = array(
            array(Piwik_DataTable_Row::COLUMNS              => array('label' => 'http://www.ask.com'),
                  Piwik_DataTable_Row::DATATABLE_ASSOCIATED => $subtableAsk),
            array(Piwik_DataTable_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
     * @group DataTable
     * @group DataTable_Filter
     * @group DataTable_Filter_PatternRecursive
     * @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());
    }
}