diff options
author | Zoltan Flamis <zoltan@innocraft.com> | 2021-05-11 23:54:24 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-11 23:54:24 +0300 |
commit | 2eb0b40370897d206bfcfc663c78b9f97cb4b50d (patch) | |
tree | d45d74eb742f11e2fc5c832265c3ef5d0922da0a /plugins/API | |
parent | 7ded63245744b599782465fa26b576d8315367ed (diff) |
Disable visitorId segment when feature disabled (#17508)
Diffstat (limited to 'plugins/API')
-rw-r--r-- | plugins/API/tests/System/GetSegmentsMetadataAPITest.php | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/plugins/API/tests/System/GetSegmentsMetadataAPITest.php b/plugins/API/tests/System/GetSegmentsMetadataAPITest.php new file mode 100644 index 0000000000..f39e2ae93f --- /dev/null +++ b/plugins/API/tests/System/GetSegmentsMetadataAPITest.php @@ -0,0 +1,72 @@ +<?php +/** + * Matomo - free/libre analytics platform + * + * @link https://matomo.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +namespace Piwik\Plugins\API\tests\System; + +use Piwik\Cache; +use Piwik\API\Request; +use Piwik\Plugins\Live\SystemSettings; +use Piwik\Plugins\CoreHome\Columns\VisitorId; +use Piwik\Tests\Framework\TestCase\SystemTestCase; + +class GetSegmentsMetadataAPITest extends SystemTestCase +{ + public function test_it_contains_visitid_by_default() + { + $request = new Request( + 'method=API.getSegmentsMetadata' + . '&filter_limit=-1' + . '&_hideImplementationData=0' + . '&format=json' + . '&module=API' + ); + + $response = json_decode($request->process(), true); + + $contains = false; + + foreach($response as $segment) { + if ($segment['segment'] === (new VisitorId())->getSegmentName()) { + $contains = true; + break; + } + } + + $this->assertTrue($contains); + } + + public function test_it_does_not_contain_visitid_if_profile_disabled() + { + Cache::flushAll(); + + $systemSettings = new SystemSettings(); + $systemSettings->disableVisitorProfile->setValue(1); + $systemSettings->save(); + + $request = new Request( + 'method=API.getSegmentsMetadata' + . '&filter_limit=-1' + . '&_hideImplementationData=0' + . '&format=json' + . '&module=API' + ); + + $response = json_decode($request->process(), true); + + $contains = false; + + foreach($response as $segment) { + if ($segment['segment'] === (new VisitorId())->getSegmentName()) { + $contains = true; + break; + } + } + + $this->assertFalse($contains); + } +} |