Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Burgess <88810029+bx80@users.noreply.github.com>2021-12-01 05:27:48 +0300
committerGitHub <noreply@github.com>2021-12-01 05:27:48 +0300
commit74a6bb09477a175f06bffbef14cf533ba8744b69 (patch)
treed582cea51ba22234ab35a3f86d9d98bf2e061378 /plugins/Transitions/tests/Integration
parent9efa63a654145fcb315d16c5e6d21ab3b96c6f01 (diff)
Configuration option to disable transition periods (#18366)
* Added config option to disable transition periods * Config section checks * Hide transitions row action if period is not allowed * Added system test * Add default values for requests vars * Do allowed period checks for transition row actions in javascript * Code tidy up, fix for range get day count bug, improved tests * Added UI test for disabled period
Diffstat (limited to 'plugins/Transitions/tests/Integration')
-rw-r--r--plugins/Transitions/tests/Integration/TransitionsMaxAllowedPeriodTest.php133
1 files changed, 133 insertions, 0 deletions
diff --git a/plugins/Transitions/tests/Integration/TransitionsMaxAllowedPeriodTest.php b/plugins/Transitions/tests/Integration/TransitionsMaxAllowedPeriodTest.php
new file mode 100644
index 0000000000..b074e7d3ab
--- /dev/null
+++ b/plugins/Transitions/tests/Integration/TransitionsMaxAllowedPeriodTest.php
@@ -0,0 +1,133 @@
+<?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\Transitions\tests\Integration;
+
+use Piwik\Plugins\Transitions\Transitions;
+use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
+use Piwik\Config;
+use Piwik\Tests\Framework\Fixture;
+use Piwik\Plugins\Transitions\API;
+
+/**
+ * Tests the transitions plugin max_period_allowed setting
+ *
+ * @group TransitionsMaxAllowedPeriodTest
+ * @group Plugins
+ */
+class TransitionsMaxAllowedPeriodTest extends IntegrationTestCase
+{
+
+ public $api;
+
+ protected static function configureFixture($fixture)
+ {
+ parent::configureFixture($fixture);
+ $fixture->createSuperUser = true;
+ }
+
+ public function setUp(): void
+ {
+ parent::setUp();
+ Fixture::createWebsite('2010-02-03 00:00:00');
+ $this->api = API::getInstance();
+
+ $t = Fixture::getTracker(1, '2012-08-09 01:02:03', $defaultInit = true, $useLocalTracker = false);
+
+ $t->setUrl('http://example.org/page/one.html');
+ $t->doTrackPageView('incredible title ');
+ }
+
+ public function test_ShouldThrowException_IfPeriodNotAllowed()
+ {
+ $invalidPeriods = [
+ 'day' => ['week', 'month', 'year'],
+ 'week' => ['month', 'year'],
+ 'month' => ['year'],
+ ];
+ foreach ($invalidPeriods as $period => $invalids) {
+ Config::setSetting('Transitions_1', 'max_period_allowed', $period);
+ foreach ($invalids as $ip) {
+ try {
+ $this->api->getTransitionsForAction('http://example.org/page/one.html', 'url',
+ 1, $ip, '2012-08-09');
+ $this->fail("Failed asserting that exception 'PeriodNotAllowed' was thrown");
+ } catch (\Exception $e) {
+ $this->assertEquals('PeriodNotAllowed', $e->getMessage());
+ }
+ }
+ }
+ }
+
+ public function test_ShouldReturnData_IfPeriodAllowed()
+ {
+ $validPeriods = [
+ 'day' => ['day'],
+ 'week' => ['day', 'week'],
+ 'month' => ['day', 'week', 'month'],
+ 'year' => ['day', 'week', 'month', 'year'],
+ 'all' => ['day', 'week', 'month', 'year'],
+ ];
+ foreach ($validPeriods as $period => $valids) {
+ Config::setSetting('Transitions_1', 'max_period_allowed', $period);
+ foreach ($valids as $vp) {
+ $r = $this->api->getTransitionsForAction('http://example.org/page/one.html', 'url',
+ 1, $vp, '2012-08-09');
+ self::assertEquals(1, $r['pageMetrics']['pageviews']);
+ }
+ }
+ }
+
+ public function test_ShouldThrowException_IfRangeDayCountIsLargerThanDayPeriod()
+ {
+ Config::setSetting('Transitions_1', 'max_period_allowed', 'day');
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessage('PeriodNotAllowed');
+ $this->api->getTransitionsForAction('http://example.org/page/one.html', 'url', 1,
+ 'range','2012-08-09,2012-08-10');
+ }
+
+ public function test_ShouldThrowException_IfRangeDayCountIsLargerThanWeekPeriod()
+ {
+ Config::setSetting('Transitions_1', 'max_period_allowed', 'day');
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessage('PeriodNotAllowed');
+ $this->api->getTransitionsForAction('http://example.org/page/one.html', 'url', 1,
+ 'range','2012-08-09,2012-08-17');
+ }
+
+ public function test_ShouldThrowException_IfRangeDayCountIsLargerThanMonthPeriod()
+ {
+ Config::setSetting('Transitions_1', 'max_period_allowed', 'day');
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessage('PeriodNotAllowed');
+ $this->api->getTransitionsForAction('http://example.org/page/one.html', 'url', 1,
+ 'range','2012-08-09,2012-09-10');
+ }
+
+ public function test_ShouldThrowException_IfRangeDayCountIsLargerThanYearPeriod()
+ {
+ Config::setSetting('Transitions_1', 'max_period_allowed', 'day');
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessage('PeriodNotAllowed');
+ $this->api->getTransitionsForAction('http://example.org/page/one.html', 'url', 1,
+ 'range','2012-08-09,2013-08-10');
+ }
+
+ public function test_ShouldUseSiteConfigInsteadOfGeneral_IfSiteConfigExists()
+ {
+ Config::setSetting('Transitions_1', 'max_period_allowed', null);
+ Config::setSetting('Transitions', 'max_period_allowed', 'month');
+ $maxAllowedPeriod = Transitions::getPeriodAllowedConfig(1);
+ $this->assertEquals('month', $maxAllowedPeriod);
+
+ Config::setSetting('Transitions_1', 'max_period_allowed', 'week');
+ $maxAllowedPeriod = Transitions::getPeriodAllowedConfig(1);
+ $this->assertEquals('week', $maxAllowedPeriod);
+ }
+
+}