diff options
author | Stefan Giehl <stefan@matomo.org> | 2020-10-28 23:46:35 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-28 23:46:35 +0300 |
commit | 0e910f0badf1aaa6e1b34b83f4f1f9a11bd5b373 (patch) | |
tree | 64c6e341629ba8cd9f77c913fa777ee9f3537dfc /plugins/Live/tests/System | |
parent | eb1543097d188c322b8470fea240fb62e39d01dd (diff) |
Improve possibility to disable visits log / visitor profile (#16598)
Diffstat (limited to 'plugins/Live/tests/System')
5 files changed, 178 insertions, 76 deletions
diff --git a/plugins/Live/tests/System/ApiTest.php b/plugins/Live/tests/System/ApiTest.php index d9c5cbb134..7588cad575 100644 --- a/plugins/Live/tests/System/ApiTest.php +++ b/plugins/Live/tests/System/ApiTest.php @@ -2,13 +2,15 @@ /** * Matomo - free/libre analytics platform * - * @link https://matomo.org + * @link https://matomo.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ namespace Piwik\Plugins\Live\tests\System; use Piwik\Config; +use Piwik\Plugins\API\API; +use Piwik\Plugins\Live\SystemSettings; use Piwik\Plugins\Live\tests\Fixtures\ManyVisitsOfSameVisitor; use Piwik\Tests\Framework\TestCase\SystemTestCase; @@ -35,82 +37,89 @@ class ApiTest extends SystemTestCase public function getApiForTesting() { - $api = array( + $api = [ 'Live.getVisitorProfile', - ); + ]; - $apiToTest = array(); - $apiToTest[] = array($api, - array( + $apiToTest = []; + $apiToTest[] = [ + $api, + [ 'idSite' => 1, 'date' => self::$fixture->dateTime, - 'periods' => array('day'), - 'testSuffix' => '' - ) - ); - $apiToTest[] = array($api, - array( - 'idSite' => 1, - 'date' => self::$fixture->dateTime, - 'periods' => array('day'), - 'otherRequestParameters' => array('limitVisits' => 20), - 'testSuffix' => 'higherLimit' - ) - ); - - $apiToTest[] = array(array('Live.getLastVisitsDetails'), - array( - 'idSite' => 'all', - 'date' => self::$fixture->dateTime, - 'periods' => array('day'), - 'otherRequestParameters' => array('limitVisits' => 20), - 'testSuffix' => 'allSites' - ) - ); - - $apiToTest[] = array(array('Live.getLastVisitsDetails'), - array( - 'idSite' => '1,2', - 'date' => self::$fixture->dateTime, - 'periods' => array('day'), - 'otherRequestParameters' => array('limitVisits' => 40), - 'testSuffix' => 'multiSites' - ) - ); - - $apiToTest[] = array(array('Live.getLastVisitsDetails'), - array( - 'idSite' => '1', - 'date' => self::$fixture->dateTime, - 'periods' => array('day'), - 'otherRequestParameters' => array( - 'segment' => 'pageTitle=@title', + 'periods' => ['day'], + 'testSuffix' => '', + ], + ]; + $apiToTest[] = [ + $api, + [ + 'idSite' => 1, + 'date' => self::$fixture->dateTime, + 'periods' => ['day'], + 'otherRequestParameters' => ['limitVisits' => 20], + 'testSuffix' => 'higherLimit', + ], + ]; + + $apiToTest[] = [ + ['Live.getLastVisitsDetails'], + [ + 'idSite' => 'all', + 'date' => self::$fixture->dateTime, + 'periods' => ['day'], + 'otherRequestParameters' => ['limitVisits' => 20], + 'testSuffix' => 'allSites', + ], + ]; + + $apiToTest[] = [ + ['Live.getLastVisitsDetails'], + [ + 'idSite' => '1,2', + 'date' => self::$fixture->dateTime, + 'periods' => ['day'], + 'otherRequestParameters' => ['limitVisits' => 40], + 'testSuffix' => 'multiSites', + ], + ]; + + $apiToTest[] = [ + ['Live.getLastVisitsDetails'], + [ + 'idSite' => '1', + 'date' => self::$fixture->dateTime, + 'periods' => ['day'], + 'otherRequestParameters' => [ + 'segment' => 'pageTitle=@title', 'filter_limit' => 2, - ), - 'testSuffix' => 'actionSegment' - ) - ); - $apiToTest[] = array(array('Live.getLastVisitsDetails'), - array( - 'idSite' => 1, - 'date' => self::$fixture->dateTime, - 'periods' => array('day'), - 'otherRequestParameters' => array('hideColumns' => 'pageTitle,referrerName,pluginIcon'), - 'testSuffix' => 'hideColumns' - ) - ); - $apiToTest[] = array(array('Live.getLastVisitsDetails'), - array( - 'idSite' => 1, - 'date' => self::$fixture->dateTime, - 'periods' => array('day'), - 'otherRequestParameters' => array( - 'hideColumns' => 'pageTitle,referrerName,pluginIcon', - 'hideColumnsRecursively' => 0 - ), - 'testSuffix' => 'hideColumnsNonRecursive' - ) - ); + ], + 'testSuffix' => 'actionSegment', + ], + ]; + $apiToTest[] = [ + ['Live.getLastVisitsDetails'], + [ + 'idSite' => 1, + 'date' => self::$fixture->dateTime, + 'periods' => ['day'], + 'otherRequestParameters' => ['hideColumns' => 'pageTitle,referrerName,pluginIcon'], + 'testSuffix' => 'hideColumns', + ], + ]; + $apiToTest[] = [ + ['Live.getLastVisitsDetails'], + [ + 'idSite' => 1, + 'date' => self::$fixture->dateTime, + 'periods' => ['day'], + 'otherRequestParameters' => [ + 'hideColumns' => 'pageTitle,referrerName,pluginIcon', + 'hideColumnsRecursively' => 0, + ], + 'testSuffix' => 'hideColumnsNonRecursive', + ], + ]; return $apiToTest; } @@ -119,12 +128,70 @@ class ApiTest extends SystemTestCase { Config::getInstance()->General['live_visitor_profile_max_visits_to_aggregate'] = 20; - $this->runApiTests('Live.getVisitorProfile', array( + $this->runApiTests('Live.getVisitorProfile', [ 'idSite' => 1, 'date' => self::$fixture->dateTime, - 'periods' => array('day'), - 'testSuffix' => 'maxVisitLimit' - )); + 'periods' => ['day'], + 'testSuffix' => 'maxVisitLimit', + ]); + } + + /** + * @dataProvider getApiForTestingDisabledFeatures + */ + public function testSuggestSegmentAPIWithDisabledFeatures($api, $params) + { + $settings = new SystemSettings(); + $settings->disableVisitorLog->setValue(true); + $settings->disableVisitorProfile->setValue(true); + $settings->save(); + + $date = mktime(0, 0, 0, 1, 1, 2010); + $lookBack = ceil((time() - $date) / 86400); + API::$_autoSuggestLookBack = $lookBack; + + $params['testSuffix'] = 'disabledFeatures'; + + $this->runApiTests($api, $params); + } + + public function getApiForTestingDisabledFeatures() + { + $apiToTest = []; + $apiToTest[] = [ + ['API.getSuggestedValuesForSegment'], + [ + 'idSite' => 1, + 'date' => self::$fixture->dateTime, + 'periods' => ['day'], + 'otherRequestParameters' => [ + 'segmentName' => 'pageTitle', + ], + ] + ]; + $apiToTest[] = [ + ['Live.getLastVisitsDetails', 'Live.getVisitorProfile'], + [ + 'idSite' => 1, + 'date' => self::$fixture->dateTime, + 'periods' => ['day'], + ] + ]; + $apiToTest[] = [ + ['API.getBulkRequest'], + [ + 'format' => 'xml', + 'otherRequestParameters' => [ + 'urls' => [ + urlencode("idSite=1&date=".self::$fixture->dateTime."&period=day&method=Live.getLastVisitsDetails"), + urlencode("idSite=1&date=".self::$fixture->dateTime."&period=day&method=API.getSuggestedValuesForSegment&segmentName=pageTitle"), + urlencode("idSite=1&date=".self::$fixture->dateTime."&period=day&method=Live.getVisitorProfile"), + ] + ], + ] + ]; + + return $apiToTest; } public static function getOutputPrefix() diff --git a/plugins/Live/tests/System/expected/test_disabledFeatures__API.getBulkRequest.xml b/plugins/Live/tests/System/expected/test_disabledFeatures__API.getBulkRequest.xml new file mode 100644 index 0000000000..b173afd57f --- /dev/null +++ b/plugins/Live/tests/System/expected/test_disabledFeatures__API.getBulkRequest.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="utf-8" ?> +<result> + <row> + <result>error</result> + <message>Visits log is deactivated globally. A user with super user access can enable this feature in the general settings. --> To temporarily debug this error further, set const PIWIK_PRINT_ERROR_BACKTRACE=true; in index.php</message> + </row> + <row> + <result>error</result> + <message>Visits log is deactivated globally. A user with super user access can enable this feature in the general settings. --> To temporarily debug this error further, set const PIWIK_PRINT_ERROR_BACKTRACE=true; in index.php --> To temporarily debug this error further, set const PIWIK_PRINT_ERROR_BACKTRACE=true; in index.php</message> + </row> + <row> + <result>error</result> + <message>Visits log is deactivated globally. A user with super user access can enable this feature in the general settings. --> To temporarily debug this error further, set const PIWIK_PRINT_ERROR_BACKTRACE=true; in index.php</message> + </row> +</result>
\ No newline at end of file diff --git a/plugins/Live/tests/System/expected/test_disabledFeatures__API.getSuggestedValuesForSegment.xml b/plugins/Live/tests/System/expected/test_disabledFeatures__API.getSuggestedValuesForSegment.xml new file mode 100644 index 0000000000..b214a81f8f --- /dev/null +++ b/plugins/Live/tests/System/expected/test_disabledFeatures__API.getSuggestedValuesForSegment.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="utf-8" ?> +<result> + <row>incredible title 1</row> + <row>incredible title 0</row> + <row>incredible title 2</row> + <row>incredible title -1</row> + <row>incredible title -2</row> +</result>
\ No newline at end of file diff --git a/plugins/Live/tests/System/expected/test_disabledFeatures__Live.getLastVisitsDetails_day.xml b/plugins/Live/tests/System/expected/test_disabledFeatures__Live.getLastVisitsDetails_day.xml new file mode 100644 index 0000000000..1842dc4ae7 --- /dev/null +++ b/plugins/Live/tests/System/expected/test_disabledFeatures__Live.getLastVisitsDetails_day.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8" ?> +<result> + <error message="Visits log is deactivated globally. A user with super user access can enable this feature in the general settings. + + --> To temporarily debug this error further, set const PIWIK_PRINT_ERROR_BACKTRACE=true; in index.php" /> +</result>
\ No newline at end of file diff --git a/plugins/Live/tests/System/expected/test_disabledFeatures__Live.getVisitorProfile.xml b/plugins/Live/tests/System/expected/test_disabledFeatures__Live.getVisitorProfile.xml new file mode 100644 index 0000000000..1842dc4ae7 --- /dev/null +++ b/plugins/Live/tests/System/expected/test_disabledFeatures__Live.getVisitorProfile.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8" ?> +<result> + <error message="Visits log is deactivated globally. A user with super user access can enable this feature in the general settings. + + --> To temporarily debug this error further, set const PIWIK_PRINT_ERROR_BACKTRACE=true; in index.php" /> +</result>
\ No newline at end of file |