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

LabelFilterTest.php « System « PHPUnit « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 809409754bdf9bdfab1dfd5d8e31bd9edab9e410 (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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php
/**
 * Piwik - free/libre analytics platform
 *
 * @link    http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */
namespace Piwik\Tests\System;

use Piwik\Tests\Framework\TestCase\SystemTestCase;
use Piwik\Tests\Fixtures\OneVisitSeveralPageViews;

/**
 * Tests the class LabelFilter.
 * This is not possible as unit test, since it loads data from the archive.
 *
 * @group LabelFilterTest
 * @group Core
 */
class LabelFilterTest extends SystemTestCase
{
    public static $fixture = null; // initialized below class definition

    /**
     * @dataProvider getApiForTesting
     */
    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('Referrers.getSearchEngines', $searchEngineTest);

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

        // test the ! operator
        $return[] = array('Actions.getPageTitles', array(
            'testSuffix'                => '_terminalOperator_selectTerminal',
            'idSite'                    => $idSite,
            'date'                      => $dateTime,
            'otherRequestParameters'    => array(
                'label'     => urlencode(urlencode('check <>') . '> @  ' . urlencode('@one@')),
                'expanded'  => 0
            )
        ));

        $return[] = array('Actions.getPageTitles', array(
            'testSuffix'                => '_terminalOperator_selectBranch',
            'idSite'                    => $idSite,
            'date'                      => $dateTime,
            'otherRequestParameters'    => array(
                'label'     => urlencode(urlencode('check <>') . '>  ' . urlencode('@one@')),
                'expanded'  => 0
            )
        ));

        $return[] = array('Actions.getPageUrls', array(
            'testSuffix'                => '_terminalOperator_selectTerminal',
            'idSite'                    => $idSite,
            'date'                      => $dateTime,
            'otherRequestParameters'    => array(
                'label'     => urlencode('dir> @ /subdir'),
                'expanded'  => 0
            )
        ));

        // test that filter_limit & filter_truncate are ignored when label is used
        $return[] = array('Actions.getPageTitles', array(
            'testSuffix'             => '_titles',
            'idSite'                 => $idSite,
            'date'                   => $dateTime,
            'otherRequestParameters' => array(
                'label'           => urlencode('incredible title! <>,;'),
                'expanded'        => 0,
                'filter_limit'    => 1,
                'filter_truncate' => 1
            )
        ));

        return $return;
    }

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

LabelFilterTest::$fixture = new OneVisitSeveralPageViews();