diff options
author | Ben Burgess <88810029+bx80@users.noreply.github.com> | 2021-12-01 05:27:48 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-01 05:27:48 +0300 |
commit | 74a6bb09477a175f06bffbef14cf533ba8744b69 (patch) | |
tree | d582cea51ba22234ab35a3f86d9d98bf2e061378 /plugins/Transitions/tests | |
parent | 9efa63a654145fcb315d16c5e6d21ab3b96c6f01 (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')
-rw-r--r-- | plugins/Transitions/tests/Integration/TransitionsMaxAllowedPeriodTest.php | 133 | ||||
-rw-r--r-- | plugins/Transitions/tests/UI/Transitions_spec.js | 16 |
2 files changed, 148 insertions, 1 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); + } + +} diff --git a/plugins/Transitions/tests/UI/Transitions_spec.js b/plugins/Transitions/tests/UI/Transitions_spec.js index ed125f3078..4e0d716d09 100644 --- a/plugins/Transitions/tests/UI/Transitions_spec.js +++ b/plugins/Transitions/tests/UI/Transitions_spec.js @@ -84,4 +84,18 @@ describe("Transitions", function () { expect(await page.screenshotSelector('body')).to.matchImage('transitions_report_switch_type_title'); }); -});
\ No newline at end of file + it('should show period not allowed for disabled periods', async function () { + + testEnvironment.overrideConfig('Transitions_1', 'max_period_allowed', 'day'); + testEnvironment.save(); + + await page.goto("?" + urlBase + "#?" + generalParams + "&category=General_Actions&subcategory=Transitions_Transitions"); + await page.waitForNetworkIdle(); + expect(await page.screenshotSelector('.pageWrap')).to.matchImage('transitions_report_period_not_allowed'); + + testEnvironment.overrideConfig('Transitions_1', 'max_period_allowed', 'all'); + testEnvironment.save(); + }); + + +}); |