Skip to content
Extraits de code Groupes Projets
UrlNormalizationTest.php 4,33 ko
Newer Older
  • Learn to ignore specific revisions
  • /**
     * Piwik - free/libre analytics platform
     *
     * @link http://piwik.org
     * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
     */
    
    mattab's avatar
    mattab a validé
    use Piwik\Tracker\Action;
    
    use Piwik\Tests\Framework\TestCase\SystemTestCase;
    
    Thomas Steur's avatar
    Thomas Steur a validé
    use Piwik\Tests\Fixtures\OneVisitWithAbnormalPageviewUrls;
    
    /**
     * Tests the URL normalization.
    
    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==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;
        }
    
        /**
    
         */
        public function testCheckPostConditions()
        {
    
            $sql = "SELECT count(*) FROM " . Common::prefixTable('log_action');
    
            $expected = 9; // 4 urls + 5 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";
    
            $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' => 'example.org/foo/bar4.html', 'url_prefix' => 2)
            );
            $this->assertEquals($expected, $urls, "normalization went wrong");
        }
    
    
        {
            return 'UrlNormalization';
        }
    }
    
    
    UrlNormalizationTest::$fixture = new OneVisitWithAbnormalPageviewUrls();