diff options
author | Matthieu Aubry <mattab@users.noreply.github.com> | 2016-11-15 18:51:38 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-15 18:51:38 +0300 |
commit | 28409d4c92f46ce3b250501c769bb08ebb26884c (patch) | |
tree | 645f6b3a94bf98d8af518c9605d2414b2e848d60 /tests/PHPUnit/Integration/SegmentTest.php | |
parent | 44283a6f19e4f1b2ca96e4ebacab1f2dc8eb42ed (diff) | |
parent | ff33b964f557e230f6cbcbf6ccac92cf8fe608fa (diff) |
Merge pull request #10871 from piwik/3.x-dev
Piwik 3.0.0-b3 release
Diffstat (limited to 'tests/PHPUnit/Integration/SegmentTest.php')
-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; + } } |