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

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordiosmosis <benaka@piwik.pro>2015-09-12 00:00:54 +0300
committerdiosmosis <benaka@piwik.pro>2015-09-12 00:00:54 +0300
commit4f931a6a1657500699c06d0c2f0f890106cc0b03 (patch)
treed013bd9419cf326a18a996dde5830a4b31153a78 /tests/PHPUnit/System/OneVisitorOneWebsiteSeveralDaysDateRangeArchivingTest.php
parentb60f408b96c034858dd10b8039f3293857e1f8a8 (diff)
Fixing test namespaces and files of some system tests.
Diffstat (limited to 'tests/PHPUnit/System/OneVisitorOneWebsiteSeveralDaysDateRangeArchivingTest.php')
-rwxr-xr-xtests/PHPUnit/System/OneVisitorOneWebsiteSeveralDaysDateRangeArchivingTest.php218
1 files changed, 218 insertions, 0 deletions
diff --git a/tests/PHPUnit/System/OneVisitorOneWebsiteSeveralDaysDateRangeArchivingTest.php b/tests/PHPUnit/System/OneVisitorOneWebsiteSeveralDaysDateRangeArchivingTest.php
new file mode 100755
index 0000000000..373cfdf170
--- /dev/null
+++ b/tests/PHPUnit/System/OneVisitorOneWebsiteSeveralDaysDateRangeArchivingTest.php
@@ -0,0 +1,218 @@
+<?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\Archive\Chunk;
+use Piwik\Common;
+use Piwik\Db;
+use Piwik\Piwik;
+use Piwik\Tests\Framework\TestCase\SystemTestCase;
+use Piwik\Tests\Fixtures\VisitsOverSeveralDays;
+
+/**
+ * Tests some API using range periods & makes sure the correct amount of blob/numeric
+ * archives are created.
+ *
+ * @group OneVisitorOneWebsiteSeveralDaysDateRangeArchivingTest
+ * @group Core
+ */
+class OneVisitorOneWebsiteSeveralDaysDateRangeArchivingTest extends SystemTestCase
+{
+ public static $fixture = null; // initialized below test definition
+
+ public static function getOutputPrefix()
+ {
+ return 'oneVisitor_oneWebsite_severalDays_DateRange';
+ }
+
+ /**
+ * @dataProvider getApiForTesting
+ */
+ public function testApi($api, $params)
+ {
+ $this->runApiTests($api, $params);
+ }
+
+ public function getApiForTesting()
+ {
+ $idSite = self::$fixture->idSite;
+
+ $apiToCall = array('Actions.getPageUrls',
+ 'VisitsSummary.get',
+ 'Resolution.getResolution',
+ 'VisitFrequency.get',
+ 'VisitTime.getVisitInformationPerServerTime');
+
+ // 2 segments: ALL and another way of expressing ALL but triggering the Segment code path
+ // 2 segments: ALL and another way of expressing ALL but triggering the Segment code path
+ $segments = array(
+ false,
+ 'countryCode!=aa',
+ 'pageUrl!=ThisIsNotKnownPageUrl',
+ );
+
+ // Running twice just as health check that second call also works
+ $result = array();
+ for ($i = 0; $i <= 1; $i++) {
+ foreach ($segments as $segment) {
+ $result[] = array($apiToCall, array('idSite' => $idSite, 'date' => '2010-12-15,2011-01-15',
+ 'periods' => array('range'),
+ 'segment' => $segment,
+ 'otherRequestParameters' => array(
+ 'flat' => '0',
+ 'expanded' => '0'
+ ),
+ ));
+ }
+ }
+
+ // Testing Date range in January only
+ // Because of flat=1, this test will archive all sub-tables
+ $result[] = array('Actions.getPageUrls', array('idSite' => $idSite, 'date' => '2011-01-01,2011-02-01',
+ 'periods' => array('range'),
+ 'otherRequestParameters' => array(
+ 'flat' => '1',
+ 'expanded' => '0'
+ ),
+ 'testSuffix' => '_periodIsRange_flattened_')
+ );
+ // testing the same with expanded=1 should not create new archive records
+ $result[] = array('Actions.getPageUrls', array('idSite' => $idSite, 'date' => '2011-01-01,2011-02-01',
+ 'periods' => array('range'),
+ 'otherRequestParameters' => array(
+ 'flat' => '0',
+ 'expanded' => '1'
+ ),
+ 'testSuffix' => '_periodIsRange_expanded_')
+ );
+ return $result;
+ }
+
+ /**
+ * Check that requesting period "Range" means only processing
+ * the requested Plugin blob (Actions in this case), not all Plugins blobs
+ *
+ * @depends testApi
+ */
+ public function test_checkArchiveRecords_whenPeriodIsRange()
+ {
+ // we expect 5 blobs for Actions plugins, because flat=1 or expanded=1 was not set
+ // so we only archived the parent table
+ $expectedActionsBlobs = 5;
+
+ // When flat=1, Actions plugin will process 5 + 1 extra chunk blobs (URL = 'http://example.org/sub1/sub2/sub3/news')
+ $expectedActionsBlobsWhenFlattened = $expectedActionsBlobs + 1;
+
+ $tests = array(
+ 'archive_blob_2010_12' => ( ($expectedActionsBlobs+1) /*Actions*/
+ + 2 /* Resolution */
+ + 2 /* VisitTime */) * 3,
+
+ /**
+ * In Each "Period=range" Archive, we expect following non zero numeric entries:
+ * 5 metrics + 1 flag // VisitsSummary
+ * + 2 metrics + 1 flag // Actions
+ * + 1 flag // Resolution
+ * + 1 flag // VisitTime
+ * = 11
+ *
+ * because we call VisitFrequency.get, this creates an archive for the visitorType==returning segment.
+ * -> There are two archives for each segment (one for "countryCode!=aa"
+ * and VisitFrequency creates one for "countryCode!=aa;visitorType==returning")
+ *
+ * So each period=range will have = 11 records + (5 metrics + 1 flag // VisitsSummary)
+ * = 17
+ *
+ * Total expected records = count unique archives * records per archive
+ * = 3 * 17
+ * = 51
+ */
+ 'archive_numeric_2010_12' => 17 * 3,
+
+ /**
+ * In the January date range,
+ * we archive only Actions plugins.
+ * It is flattened so all 3 sub-tables should be archived.
+ */
+ 'archive_blob_2011_01' => $expectedActionsBlobsWhenFlattened,
+
+ /**
+ * 5 metrics + 1 flag // VisitsSummary
+ * + 2 metrics + 1 flag // Actions
+ */
+ 'archive_numeric_2011_01' => (6 + 3),
+
+ // nothing in Feb
+ 'archive_blob_2011_02' => 0,
+ 'archive_numeric_2011_02' => 0,
+ );
+ foreach ($tests as $table => $expectedRows) {
+ $sql = "SELECT count(*) FROM " . Common::prefixTable($table) . " WHERE period = " . Piwik::$idPeriods['range'];
+ $countBlobs = Db::get()->fetchOne($sql);
+
+ if($expectedRows != $countBlobs) {
+ $this->printDebugWhenTestFails($table);
+ }
+ $this->assertEquals($expectedRows, $countBlobs, "$table expected $expectedRows, got $countBlobs");
+ }
+ }
+
+ /**
+ * Check that requesting period "Range" means only processing
+ * the requested Plugin blob (Actions in this case), not all Plugins blobs
+ *
+ * @depends testApi
+ */
+ public function test_checkArchiveRecords_shouldMergeSubtablesIntoOneRow()
+ {
+ $tests = array(
+ 'archive_blob_2010_12' => 3,
+
+ /**
+ * In the January date range,
+ * we archive only Actions plugins.
+ * It is flattened so all 3 sub-tables should be archived.
+ */
+ 'archive_blob_2011_01' => 3,
+ );
+ $chunk = new Chunk();
+ $chunkName = $chunk->getRecordNameForTableId('Actions_actions_url', 0);
+
+ foreach ($tests as $table => $expectedNumSubtables) {
+ $sql = "SELECT value FROM " . Common::prefixTable($table) . " WHERE period = " . Piwik::$idPeriods['range'] . " and `name` ='$chunkName'";
+ $blob = Db::get()->fetchOne($sql);
+ $blob = gzuncompress($blob);
+ $blob = unserialize($blob);
+ $countSubtables = count($blob);
+
+ $this->assertEquals($expectedNumSubtables, $countSubtables, "Actions_actions_url_chunk_0_99 in $table expected to contain $expectedNumSubtables subtables, got $countSubtables");
+ }
+ }
+
+ /**
+ * @param $table
+ */
+ protected function printDebugWhenTestFails($table)
+ {
+ $data = Db::get()->fetchAll("SELECT * FROM " . Common::prefixTable($table) . " WHERE period = " . Piwik::$idPeriods['range'] . " ORDER BY idarchive ASC");
+ var_export($data);
+
+ $idArchives = array();
+ foreach ($data as $row) {
+ $idArchives[] = $row['idarchive'];
+ }
+ $idArchives = array_unique($idArchives);
+ foreach ($idArchives as $idArchive) {
+ $numericTable = str_replace("blob", "numeric", Common::prefixTable($table));
+ var_export(Db::get()->fetchAll("SELECT idarchive, name FROM " . $numericTable . " WHERE idarchive = ? AND name LIKE 'done%' LIMIT 1 ", $idArchive));
+ }
+ }
+
+}
+
+OneVisitorOneWebsiteSeveralDaysDateRangeArchivingTest::$fixture = new VisitsOverSeveralDays();