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:
-rw-r--r--core/Archive.php2
-rw-r--r--tests/PHPUnit/Fixtures/TwoSitesTwoVisitorsDifferentDays.php2
-rwxr-xr-xtests/PHPUnit/System/TwoVisitorsTwoWebsitesDifferentDaysConversionsTest.php72
3 files changed, 74 insertions, 2 deletions
diff --git a/core/Archive.php b/core/Archive.php
index 208d6dfdce..dcc14b7ad0 100644
--- a/core/Archive.php
+++ b/core/Archive.php
@@ -162,7 +162,7 @@ class Archive
private $params;
/**
- * \Piwik\Cache\Cache
+ * @var \Piwik\Cache\Cache
*/
private static $cache;
diff --git a/tests/PHPUnit/Fixtures/TwoSitesTwoVisitorsDifferentDays.php b/tests/PHPUnit/Fixtures/TwoSitesTwoVisitorsDifferentDays.php
index 0281ac532e..154dc70c2b 100644
--- a/tests/PHPUnit/Fixtures/TwoSitesTwoVisitorsDifferentDays.php
+++ b/tests/PHPUnit/Fixtures/TwoSitesTwoVisitorsDifferentDays.php
@@ -77,7 +77,7 @@ class TwoSitesTwoVisitorsDifferentDays extends Fixture
$startDate = null, $excludedUserAgents = null, $keepURLFragments = 1); // KEEP_URL_FRAGMENT_YES Yes for idSite 2
}
- private function trackVisits()
+ public function trackVisits()
{
$dateTime = $this->dateTime;
$idSite = $this->idSite1;
diff --git a/tests/PHPUnit/System/TwoVisitorsTwoWebsitesDifferentDaysConversionsTest.php b/tests/PHPUnit/System/TwoVisitorsTwoWebsitesDifferentDaysConversionsTest.php
index 88727c30a2..8542e53774 100755
--- a/tests/PHPUnit/System/TwoVisitorsTwoWebsitesDifferentDaysConversionsTest.php
+++ b/tests/PHPUnit/System/TwoVisitorsTwoWebsitesDifferentDaysConversionsTest.php
@@ -8,6 +8,9 @@
namespace Piwik\Tests\System;
use Piwik\Archive;
+use Piwik\Cache;
+use Piwik\DataAccess\ArchiveInvalidator;
+use Piwik\Option;
use Piwik\Plugins\Goals\Archiver;
use Piwik\Segment;
use Piwik\Tests\Framework\TestCase\SystemTestCase;
@@ -25,6 +28,9 @@ require_once PIWIK_INCLUDE_PATH . '/plugins/Goals/Goals.php';
*/
class TwoVisitorsTwoWebsitesDifferentDaysConversionsTest extends SystemTestCase
{
+ /**
+ * @var TwoSitesTwoVisitorsDifferentDays
+ */
public static $fixture = null; // initialized below class definition
/**
@@ -135,6 +141,72 @@ class TwoVisitorsTwoWebsitesDifferentDaysConversionsTest extends SystemTestCase
);
}
+ // TODO: this test should be in an integration test for Piwik\Archive. setup code for getting metrics from different
+ // plugins is non-trivial, so not done now.
+ public function test_Archive_getNumeric_shouldInvalidateRememberedReportsOncePerRequestIfNeeded()
+ {
+ // Tests that getting a visits summary metric (nb_visits) & a Goal's metric (Goal_revenue)
+ // at the same time works.
+ $dateTimeRange = '2010-01-03,2010-01-06';
+ $columns = array('nb_visits', 'Goal_nb_conversions', 'nb_actions');
+ $idSite1 = self::$fixture->idSite1;
+
+ $archive = Archive::build($idSite1, 'range', $dateTimeRange);
+ $result = $archive->getNumeric($columns);
+ $this->assertEquals(
+ array(
+ 'nb_visits' => 4,
+ 'Goal_nb_conversions' => 6,
+ 'nb_actions' => 13
+ ),
+ $result
+ );
+
+ $cache = Cache::getTransientCache();
+ $this->assertTrue($cache->contains('Archive.RememberedReportsInvalidated'));
+
+ $invalidator = new ArchiveInvalidator();
+
+ self::$fixture->trackVisits();
+
+ // trackVisits should remember archived reports as invalid
+ $this->assertNotEmpty($invalidator->getRememberedArchivedReportsThatShouldBeInvalidated());
+
+ // although there were new tracked visists it doesn'T change as the report invalidation is cached and was
+ // already invalidated in previous Archive::get();
+ $archive = Archive::build($idSite1, 'range', $dateTimeRange);
+ $result = $archive->getNumeric($columns);
+ $this->assertEquals(
+ array(
+ 'nb_visits' => 4,
+ 'Goal_nb_conversions' => 6,
+ 'nb_actions' => 13 // actions should remain the same as nothing was reports are still marked as already processed
+ ),
+ $result
+ );
+
+ // make sure the caching in archive::get() worked and they are still to be invalidated
+ $this->assertNotEmpty($invalidator->getRememberedArchivedReportsThatShouldBeInvalidated());
+
+ // now we force to actually invalidate archived reports again and then archive will be rebuilt
+ $cache->delete('Archive.RememberedReportsInvalidated');
+
+ $archive = Archive::build($idSite1, 'range', $dateTimeRange);
+ $result = $archive->getNumeric($columns);
+
+ // archive::get() should have invalidated them now as we cleared the lock / cache before
+ $this->assertEmpty($invalidator->getRememberedArchivedReportsThatShouldBeInvalidated());
+
+ $this->assertEquals(
+ array(
+ 'nb_visits' => 4,
+ 'Goal_nb_conversions' => 6,
+ 'nb_actions' => 26 // now actions should be increased as the reports were invalidated
+ ),
+ $result
+ );
+ }
+
public static function getOutputPrefix()
{
return 'TwoVisitors_twoWebsites_differentDays_Conversions';