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

LabelFilterTest.php « Integration « PHPUnit « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0141761bed0788571ab10d5baad09d3042b8923b (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
/**
 * Piwik - Open source web analytics
 *
 * @link    http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */

/**
 * Tests the class Piwik_API_DataTableManipulator_LabelFilter.
 * This is not possible as unit test, since it loads data from the archive.
 */
class Test_Piwik_Integration_LabelFilter extends IntegrationTestCase
{
    public static $fixture = null; // initialized below class definition

    /**
     * @dataProvider getApiForTesting
     * @group        Integration
     * @group        LabelFilter
     */
    public function testApi($api, $params)
    {
        $this->runApiTests($api, $params);
    }

    public function getApiForTesting()
    {
        $idSite = self::$fixture->idSite;
        $dateTime = self::$fixture->dateTime;

        $labelsToTest = array(
            // first level
            'shouldBeNoData'          => 'nonExistent',
            'dir'                     => '  dir   ',
            '0'                       => '/0',

            // TODO the label in the API output is ...&amp;#039;... why does it only work this way?
            'thisiscool'              => '/ééé&quot;&#039;... &lt;this is cool&gt;!',

            // second level
            'dirnonExistent'          => 'dir>nonExistent',
            'dirfilephpfoobarfoo2bar' => 'dir>' . urlencode('/file.php?foo=bar&foo2=bar'),

            // 4 levels
            'dir2sub0filephp'         => 'dir2>sub>0>' . urlencode('/file.php'),
        );

        $return = array();
        foreach ($labelsToTest as $suffix => $label) {
            $return[] = array('Actions.getPageUrls', array(
                'testSuffix'             => '_' . $suffix,
                'idSite'                 => $idSite,
                'date'                   => $dateTime,
                'otherRequestParameters' => array(
                    'label'    => urlencode($label),
                    'expanded' => 0
                )
            ));
        }

        $label = 'dir';
        $return[] = array('Actions.getPageUrls', array(
            'testSuffix'             => '_' . $label . '_range',
            'idSite'                 => $idSite,
            'date'                   => $dateTime,
            'otherRequestParameters' => array(
                'date'     => '2010-03-06,2010-03-08',
                'label'    => urlencode($label),
                'expanded' => 0
            )
        ));

        $return[] = array('Actions.getPageTitles', array(
            'testSuffix'             => '_titles',
            'idSite'                 => $idSite,
            'date'                   => $dateTime,
            'otherRequestParameters' => array(
                // note: title has no blank prefixed here. in the report it has.
                'label'    => urlencode('incredible title! <>,;'),
                'expanded' => 0
            )
        ));

        $return[] = array('Actions.getPageTitles', array(
            'testSuffix'             => '_titlesRecursive',
            'idSite'                 => $idSite,
            'date'                   => $dateTime,
            'otherRequestParameters' => array(
                'label'    => urlencode(
                    '   ' . // test trimming
                        urlencode('incredible parent title! <>,;') .
                        '>' .
                        urlencode('subtitle <>,;')),
                'expanded' => 0
            )
        ));

        $keyword = '&lt;&gt;&amp;\&quot;the pdo extension is required for this adapter but the extension is not loaded';
        $searchEngineTest = array(
            'testSuffix'             => '_keywords_html',
            'idSite'                 => $idSite,
            'date'                   => $dateTime,
            'otherRequestParameters' => array(
                'label'    => urlencode('Google>' . urlencode($keyword)),
                'expanded' => 0
            )
        );
        $return[] = array('Referers.getSearchEngines', $searchEngineTest);

        $searchEngineTest['otherRequestParameters']['label'] = urlencode('Google>' . urlencode(html_entity_decode($keyword)));
        $return[] = array('Referers.getSearchEngines', $searchEngineTest);

        return $return;
    }

    public function getOutputPrefix()
    {
        return 'LabelFilter';
    }
}

Test_Piwik_Integration_LabelFilter::$fixture = new Test_Piwik_Fixture_OneVisitSeveralPageViews();