Newer
Older
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
Thomas Steur
a validé
namespace Piwik\Tests\System;
use Piwik\API\Request;
use Piwik\Config;
use Piwik\Tests\Fixtures\VisitsTwoWebsitesWithAdditionalVisits;
Thomas Steur
a validé
use Piwik\Tests\Framework\TestCase\SystemTestCase;
/**
* Track visits before website creation date and test that Piwik handles them correctly.
*
* This tests that the API method invalidateArchivedReports works correctly, that it deletes data:
* - on one or multiple websites
* - for a given set of dates (and optional period)
*
Thomas Steur
a validé
* @group Core
* @group ArchiveInvalidationTest
*/
class ArchiveInvalidationTest extends SystemTestCase
{
public static $fixture = null; // initialized below class definition
Michał Kurzeja
a validé
protected $suffix = '_NewDataShouldNotAppear';
/**
* @dataProvider getApiForTesting
*/
public function testApi($api, $params)
{
$this->runApiTests($api, $params);
}
/**
* This should NOT return data for old dates before website creation
*/
public function getApiForTesting()
{
// We test a typical Numeric and a Recursive blob reports
$apiToCall = array('VisitsSummary.get', 'Actions.getPageUrls');
// Build tests for the 2 websites
return array(
Michał Kurzeja
a validé
array($apiToCall, array('idSite' => self::$fixture->idSite1,
'testSuffix' => 'Website' . self::$fixture->idSite1 . $this->suffix,
'date' => self::$fixture->dateTimeFirstDateWebsite1,
'periods' => 'month',
'setDateLastN' => 4, // 4months ahead
'otherRequestParameters' => array('expanded' => 1))
),
Michał Kurzeja
a validé
array($apiToCall, array('idSite' => self::$fixture->idSite2,
'testSuffix' => 'Website' . self::$fixture->idSite2 . $this->suffix,
'date' => self::$fixture->dateTimeFirstDateWebsite2,
Michał Kurzeja
a validé
'segment' => 'pageUrl=@category/',
'setDateLastN' => 4, // 4months ahead
'otherRequestParameters' => array('expanded' => 1))
),
array($apiToCall, array('idSite' => self::$fixture->idSite2,
'testSuffix' => 'Website' . self::$fixture->idSite2 . "_NewDataShouldNotAppear_BecauseWeekWasNotInvalidated",
'date' => self::$fixture->dateTimeFirstDateWebsite2,
'periods' => 'week',
'segment' => 'pageUrl=@category/',
'setDateLastN' => 4, // 4months ahead
'otherRequestParameters' => array('expanded' => 1))
),
Michał Kurzeja
a validé
* @dataProvider getApiForTesting
*/
public function testSameApi($api, $params)
{
Michał Kurzeja
a validé
$this->setBrowserArchivingTriggering(0);
self::$fixture->trackMoreVisits($params['idSite']);
Michał Kurzeja
a validé
$this->invalidateTestArchives();
$this->runApiTests($api, $params);
}
/**
* @depends testApi
* @depends testSameApi
* @dataProvider getAnotherApiForTesting
*/
public function testAnotherApi($api, $params)
{
Michał Kurzeja
a validé
$this->setBrowserArchivingTriggering(1);
$this->runApiTests($api, $params);
}
/**
* This is called after getApiToTest()
* We invalidate old reports and check that data is now returned for old dates
*/
public function getAnotherApiForTesting()
{
Michał Kurzeja
a validé
$this->suffix = '_NewDataShouldAppear';
return $this->getApiForTesting();
}
public static function getOutputPrefix()
{
return 'Archive_Invalidation';
}
Michał Kurzeja
a validé
protected function setBrowserArchivingTriggering($value)
{
Config::getInstance()->General['enable_browser_archiving_triggering'] = $value;
}
protected function invalidateTestArchives()
{
$dateToInvalidate1 = new \DateTime(self::$fixture->dateTimeFirstDateWebsite1);
$dateToInvalidate2 = new \DateTime(self::$fixture->dateTimeFirstDateWebsite2);
$r = new Request("module=API&method=CoreAdminHome.invalidateArchivedReports&idSites=" . self::$fixture->idSite1 . "&dates=" . $dateToInvalidate1->format('Y-m-d'));
$this->assertApiResponseHasNoError($r->process());
// Days & Months reports only are invalidated and we test our weekly report will still show old data.
$r = new Request("module=API&method=CoreAdminHome.invalidateArchivedReports&period=day&idSites=" . self::$fixture->idSite2 . "&dates=" . $dateToInvalidate2->format('Y-m-d'));
$this->assertApiResponseHasNoError($r->process());
$r = new Request("module=API&method=CoreAdminHome.invalidateArchivedReports&period=month&idSites=" . self::$fixture->idSite2 . "&dates=" . $dateToInvalidate2->format('Y-m-d'));
Michał Kurzeja
a validé
$this->assertApiResponseHasNoError($r->process());
Michał Kurzeja
a validé
}
Michał Kurzeja
a validé
ArchiveInvalidationTest::$fixture = new VisitsTwoWebsitesWithAdditionalVisits();