diff options
author | Thomas Steur <tsteur@users.noreply.github.com> | 2016-11-14 14:40:30 +0300 |
---|---|---|
committer | Matthieu Aubry <mattab@users.noreply.github.com> | 2016-11-14 14:40:29 +0300 |
commit | 9ad7d38049f02c8d65bff5da4db25335ef296ff9 (patch) | |
tree | 4eff1ae818cfbd3e49dba97374dca076286360fe /tests | |
parent | 7c1590b47f4e51340df5dd36d459f7d3221a8768 (diff) |
new method that lets us know if we segment will be archived (#10845)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/PHPUnit/Integration/SegmentTest.php | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/tests/PHPUnit/Integration/SegmentTest.php b/tests/PHPUnit/Integration/SegmentTest.php index aedd95e61f..9558cc0929 100644 --- a/tests/PHPUnit/Integration/SegmentTest.php +++ b/tests/PHPUnit/Integration/SegmentTest.php @@ -9,16 +9,19 @@ namespace Piwik\Tests\Integration; use Exception; +use Piwik\ArchiveProcessor\Rules; use Piwik\Cache; use Piwik\Common; use Piwik\Config; use Piwik\Container\StaticContainer; use Piwik\Db; use Piwik\Segment; +use Piwik\Tests\Framework\Fixture; use Piwik\Tests\Framework\Mock\FakeAccess; use Piwik\Tests\Framework\TestCase\IntegrationTestCase; use Piwik\Tracker\Action; use Piwik\Tracker\TableLogAction; +use Piwik\Plugins\SegmentEditor\API as SegmentEditorApi; /** * @group Core @@ -28,12 +31,16 @@ class SegmentTest extends IntegrationTestCase { public $tableLogActionCacheHits = 0; + private $exampleSegment = 'visitCount>=1'; + public function setUp() { parent::setUp(); // setup the access layer (required in Segment contrustor testing if anonymous is allowed to use segments) FakeAccess::$superUser = true; + + Fixture::createWebsite('2015-01-01 00:00:00'); } static public function removeExtraWhiteSpaces($valueToFilter) @@ -1491,4 +1498,78 @@ class SegmentTest extends IntegrationTestCase 'Piwik\Tracker\TableLogAction\Cache' => \DI\object()->constructorParameter('cache', $cacheProxy), ); } + + public function test_willBeArchived_ByDefault_AllSegmentsWillBeArchived() + { + $this->assertWillBeArchived($this->exampleSegment); + } + + public function test_willBeArchived_SegmentsWillNotBeArchivedWhenBrowserArchivingIsDisabledAndNoSuchSegmentExists() + { + $this->disableSegmentBrowserArchiving(); + $this->assertNotWillBeArchived($this->exampleSegment); + } + + public function test_willBeArchived_SegmentsWillBeArchivedWhenBrowserArchivingIsDisabledButBrowserSegmentsArchivingEnabled() + { + $this->disableBrowserArchiving(); + $this->assertWillBeArchived($this->exampleSegment); + } + + public function test_willSegmentBeArchived_SegmentsWillNotBeArchivedWhenBrowserArchivingDisabledAndSegmentExistsNotAutoArchive() + { + $this->disableSegmentBrowserArchiving(); + + SegmentEditorApi::getInstance()->add('My Name', $this->exampleSegment, $idSite = false, $autoArchive = false); + + $this->assertNotWillBeArchived($this->exampleSegment); + } + + public function test_willSegmentBeArchived_SegmentsWillBeArchivedWhenBrowserArchivingDisabledButSegmentExistsWithAuthoArchive() + { + $this->disableSegmentBrowserArchiving(); + + SegmentEditorApi::getInstance()->add('My Name', $this->exampleSegment, $idSite = false, $autoArchive = true); + + $this->assertWillBeArchived($this->exampleSegment); + } + + public function test_willBeArchived_AnEmptySegmentShouldBeAlwaysArchived() + { + $this->assertWillBeArchived(false); + + $this->disableSegmentBrowserArchiving(); + $this->assertWillBeArchived(false); + } + + private function assertWillBeArchived($segmentString) + { + $this->assertTrue($this->willSegmentByArchived($segmentString)); + } + + private function assertNotWillBeArchived($segmentString) + { + $this->assertFalse($this->willSegmentByArchived($segmentString)); + } + + private function willSegmentByArchived($segmentString) + { + $segment = new Segment($segmentString, $idSites = array(1)); + + return $segment->willBeArchived(); + } + + private function disableBrowserArchiving() + { + Rules::setBrowserTriggerArchiving(false); + } + + private function disableSegmentBrowserArchiving() + { + $this->disableBrowserArchiving(); + $config = Config::getInstance(); + $general = $config->General; + $general['browser_archiving_disabled_enforce'] = '1'; + $config->General = $general; + } } |