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

UrlNormalizationTest.php « System « PHPUnit « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 849ea95c9d3bfc4f6b4a94a0bf49140fdea15889 (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
<?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\Common;
use Piwik\Db;
use Piwik\Tracker\Action;
use Piwik\Tests\Framework\TestCase\SystemTestCase;
use Piwik\Tests\Fixtures\OneVisitWithAbnormalPageviewUrls;

/**
 * Tests the URL normalization.
 *
 * @group Core
 * @group UrlNormalizationTest
 */
class UrlNormalizationTest extends SystemTestCase
{
    public static $fixture = null; // initialized below class definition

    /**
     * @dataProvider getApiForTesting
     */
    public function testApi($api, $params)
    {
        if(self::isMysqli()) {
            $this->markTestSkipped('Sometimes fail on MYSQLI (at random)');
        }
        $this->runApiTests($api, $params);
    }

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

        $return = array();
        $return[] = array('Actions.getPageUrls', array(
            'testSuffix' => '_urls',
            'idSite'     => $idSite,
            'date'       => $dateTime,
        ));
        $return[] = array('Actions.getPageTitles', array(
            'testSuffix' => '_titles',
            'idSite'     => $idSite,
            'date'       => $dateTime,
        ));

        $return[] = array('Actions.getPageUrls', array(
            'testSuffix' => '_pagesSegmented',
            'idSite'     => $idSite,
            'date'       => $dateTime,
            'segment'    => 'pageUrl==https://WWw.example.org/foo/bar2.html',
        ));
        // Testing entryPageUrl  with AND segment
        $return[] = array('Actions.getPageUrls', array(
            'testSuffix' => '_pagesSegmented',
            'idSite'     => $idSite,
            'date'       => $dateTime,
            'segment'    => 'entryPageUrl==http://example.org/foo/bar.html;pageUrl==https://WWw.example.org/foo/bar2.html',
        ));
        // Testing exitPageUrl with AND segment
        $return[] = array('Actions.getPageUrls', array(
            'testSuffix' => '_pagesSegmented',
            'idSite'     => $idSite,
            'date'       => $dateTime,
            'segment'    => 'exitPageUrl==example.org/foo/bar4.html;pageUrl==https://WWw.example.org/foo/bar2.html',
        ));
        $return[] = array('Actions.getPageUrls', array(
            'testSuffix' => '_pagesSegmented',
            'idSite'     => $idSite,
            'date'       => $dateTime,
            'segment'    => 'pageUrl==' . urlencode('example.org/foo/bar2.html'),
        ));
        $return[] = array('Actions.getPageUrls', array(
            'testSuffix' => '_pagesSegmentedRef',
            'idSite'     => $idSite,
            'date'       => $dateTime,
            'segment'    => 'referrerUrl==http://www.google.com/search?q=piwik',
        ));
        $return[] = array('Referrers.getKeywordsForPageUrl', array(
            'testSuffix'             => '_keywords',
            'idSite'                 => $idSite,
            'date'                   => $dateTime,
            'otherRequestParameters' => array(
                'url' => 'http://WWW.example.org/foo/bar.html'
            )
        ));
        return $return;
    }

    /**
     * @depends     testApi
     */
    public function testCheckPostConditions()
    {
        $sql = "SELECT count(*) FROM " . Common::prefixTable('log_action');
        $count = Db::get()->fetchOne($sql);
        $expected = 13; // 6 urls + 7 titles
        $this->assertEquals($expected, $count, "only $expected actions expected");

        $sql = "SELECT name, url_prefix FROM " . Common::prefixTable('log_action')
            . " WHERE type = " . Action::TYPE_PAGE_URL
            . " ORDER BY idaction ASC";
        $urls = Db::get()->fetchAll($sql);
        $expected = array(
            array('name' => 'example.org/foo/bar.html', 'url_prefix' => 0),
            array('name' => 'example.org/foo/bar2.html', 'url_prefix' => 3),
            array('name' => 'example.org/foo/bar3.html', 'url_prefix' => 1),
            array('name' => 'my.url/ꟽ碌㒧䊶亄ﶆⅅขκもኸόσशμεޖृ', 'url_prefix' => 1),
            array('name' => 'make.wordpress.org/?emoji=�l&param=test', 'url_prefix' => 2),
            array('name' => 'example.org/foo/bar4.html', 'url_prefix' => 2),
        );
        $this->assertEquals($expected, $urls, "normalization went wrong");
    }

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

UrlNormalizationTest::$fixture = new OneVisitWithAbnormalPageviewUrls();