1
0
قرینه از https://github.com/matomo-org/matomo.git synced 2025-08-22 06:57:53 +00:00
Files
matomo/plugins/SegmentEditor/tests/System/UnprocessedSegmentsTest.php
Stefan Giehl d6d72d1fa7 [Coding Style] Enable rule PSR1.Methods.CamelCapsMethodName.NotCamelCaps (#22144)
* [Coding Style] Enable rule PSR1.Methods.CamelCapsMethodName.NotCamelCaps

* [Coding Style] Use camel case for method names in API plugin tests (#22145)

* [Coding Style] Use camel case for method names in Core* plugin tests (#22147)

* [Coding Style] Use camel case for method names in core Unit tests (#22149)

* [Coding Style] Use camel case for method names in Actions and BulkTracking plugin tests (#22146)

* [Coding Style] Use camel case for method names in CustomDimensions and CustomJSTracker plugin tests (#22148)

* [Coding Style] Use camel case for method names in core Integration tests (#22151)

* [Coding Style] Use camel case for method names in more core plugin tests (#22153)

* [Coding Style] Use camel case for method names in more core plugin tests (#22157)

* [Coding Style] Use camel case for method names in more core plugin tests

* Update plugins/Monolog/tests/Unit/Processor/ExceptionToTextProcessorTest.php

Co-authored-by: Michal Kleiner <michal@innocraft.com>

---------

Co-authored-by: Michal Kleiner <michal@innocraft.com>

* [Coding Style] Use camel case for method names in more core plugin tests (#22159)

* [Coding Style] Use camel case for method names in remaining tests (#22160)

* [Coding Style] Use camel case for method names in remaining tests

* rename expected test files

---------

Co-authored-by: Michal Kleiner <michal@innocraft.com>
2024-04-25 20:57:55 +02:00

289 خطوط
10 KiB
PHP

<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\SegmentEditor\tests\System;
use Piwik\ArchiveProcessor\Rules;
use Piwik\Common;
use Piwik\Config;
use Piwik\Date;
use Piwik\Db;
use Piwik\Plugins\SegmentEditor\API;
use Piwik\Plugins\VisitsSummary;
use Piwik\Tests\Fixtures\OneVisitorTwoVisits;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
use Piwik\CronArchive\SegmentArchiving;
/**
* @group SegmentEditor
* @group System
* @group UnprocessedSegmentsTest
*/
class UnprocessedSegmentsTest extends IntegrationTestCase
{
/**
* @var OneVisitorTwoVisits
*/
public static $fixture;
public const TEST_SEGMENT = 'browserCode==ff';
public function testApiOutputWhenCustomSegmentUsedWithBrowserArchivingDisabled()
{
Rules::setBrowserTriggerArchiving(false);
$segments = Rules::getSegmentsToProcess([self::$fixture->idSite]);
self::assertTrue(!in_array(self::TEST_SEGMENT, $segments));
$this->runAnyApiTest('VisitsSummary.get', 'customSegmentUnprocessed', [
'idSite' => self::$fixture->idSite,
'date' => Date::factory(self::$fixture->dateTime)->toString(),
'period' => 'week',
'segment' => self::TEST_SEGMENT,
]);
}
public function testApiOutputWhenRealTimeProcessedSegmentUsedWithBrowserArchivingDisabled()
{
$idSegment = API::getInstance()->add('testsegment', self::TEST_SEGMENT, self::$fixture->idSite, $autoArchive = false);
$storedSegment = API::getInstance()->get($idSegment);
$this->assertNotEmpty($storedSegment);
Rules::setBrowserTriggerArchiving(false);
$segments = Rules::getSegmentsToProcess([self::$fixture->idSite]);
self::assertTrue(in_array(self::TEST_SEGMENT, $segments)); // auto archive is forced when browser archiving is fully disabled
$this->runAnyApiTest('VisitsSummary.get', 'realTimeSegmentUnprocessed', [
'idSite' => self::$fixture->idSite,
'date' => Date::factory(self::$fixture->dateTime)->toString(),
'period' => 'week',
'segment' => self::TEST_SEGMENT,
]);
}
public function testApiOutputWhenUnprocessedAutoArchiveSegmentUsedWithBrowserArchivingDisabled()
{
Rules::setBrowserTriggerArchiving(false);
$idSegment = API::getInstance()->add('testsegment', self::TEST_SEGMENT, self::$fixture->idSite, $autoArchive = true);
$storedSegment = API::getInstance()->get($idSegment);
$this->assertNotEmpty($storedSegment);
$segments = Rules::getSegmentsToProcess([self::$fixture->idSite]);
self::assertTrue(in_array(self::TEST_SEGMENT, $segments));
$this->runAnyApiTest('VisitsSummary.get', 'autoArchiveSegmentUnprocessed', [
'idSite' => self::$fixture->idSite,
'date' => Date::factory(self::$fixture->dateTime)->toString(),
'period' => 'week',
'segment' => self::TEST_SEGMENT,
]);
}
public function testApiOutputWhenUnprocessedAutoArchiveSegmentUsedWithBrowserArchivingDisabledAndEncodedSegment()
{
Rules::setBrowserTriggerArchiving(false);
$idSegment = API::getInstance()->add('testsegment', self::TEST_SEGMENT, self::$fixture->idSite, $autoArchive = true);
$storedSegment = API::getInstance()->get($idSegment);
$this->assertNotEmpty($storedSegment);
$segments = Rules::getSegmentsToProcess([self::$fixture->idSite]);
self::assertTrue(in_array(self::TEST_SEGMENT, $segments));
$this->runAnyApiTest('VisitsSummary.get', 'autoArchiveSegmentUnprocessedEncoded', [
'idSite' => self::$fixture->idSite,
'date' => Date::factory(self::$fixture->dateTime)->toString(),
'period' => 'week',
'segment' => urlencode(self::TEST_SEGMENT),
]);
}
public function testApiOutputWhenPreprocessedSegmentUsedWithBrowserArchivingDisabled()
{
Rules::setBrowserTriggerArchiving(false);
$idSegment = API::getInstance()->add('testsegment', self::TEST_SEGMENT, self::$fixture->idSite, $autoArchive = true);
$storedSegment = API::getInstance()->get($idSegment);
$this->assertNotEmpty($storedSegment);
Rules::setBrowserTriggerArchiving(true);
VisitsSummary\API::getInstance()->get(
self::$fixture->idSite,
'week',
Date::factory(self::$fixture->dateTime)->toString(),
self::TEST_SEGMENT
); // archive (make sure there's data for actual test)
Rules::setBrowserTriggerArchiving(false);
$segments = Rules::getSegmentsToProcess([self::$fixture->idSite]);
self::assertTrue(in_array(self::TEST_SEGMENT, $segments));
$this->runAnyApiTest('VisitsSummary.get', 'autoArchiveSegmentPreprocessed', [
'idSite' => self::$fixture->idSite,
'date' => Date::factory(self::$fixture->dateTime)->toString(),
'period' => 'week',
'segment' => self::TEST_SEGMENT,
]);
}
public function testApiOutputWhenPreprocessedCustomSegmentUsedWithBrowserArchivingDisabled()
{
VisitsSummary\API::getInstance()->get(
self::$fixture->idSite,
'week',
Date::factory(self::$fixture->dateTime)->toString(),
self::TEST_SEGMENT
); // archive
Rules::setBrowserTriggerArchiving(false);
$segments = Rules::getSegmentsToProcess([self::$fixture->idSite]);
self::assertTrue(!in_array(self::TEST_SEGMENT, $segments));
$this->runAnyApiTest('VisitsSummary.get', 'customSegmentPreprocessed', [
'idSite' => self::$fixture->idSite,
'date' => Date::factory(self::$fixture->dateTime)->toString(),
'period' => 'week',
'segment' => self::TEST_SEGMENT,
]);
}
public function testApiOutputWhenPreprocessedSegmentUsedWithNoDataAndBrowserArchivingDisabled()
{
$this->clearLogData();
Rules::setBrowserTriggerArchiving(false);
$idSegment = API::getInstance()->add('testsegment', self::TEST_SEGMENT, self::$fixture->idSite, $autoArchive = true);
$storedSegment = API::getInstance()->get($idSegment);
$this->assertNotEmpty($storedSegment);
VisitsSummary\API::getInstance()->get(
self::$fixture->idSite,
'week',
Date::factory(self::$fixture->dateTime)->toString(),
self::TEST_SEGMENT
); // archive
$segments = Rules::getSegmentsToProcess([self::$fixture->idSite]);
self::assertTrue(in_array(self::TEST_SEGMENT, $segments));
$this->runAnyApiTest('VisitsSummary.get', 'autoArchiveSegmentNoDataPreprocessed', [
'idSite' => self::$fixture->idSite,
'date' => Date::factory(self::$fixture->dateTime)->toString(),
'period' => 'week',
'segment' => self::TEST_SEGMENT,
]);
}
public function testApiOutputWhenNoLogDataAndUnprocessedSegmentUsedAndBrowserArchivingDisabled()
{
$this->clearLogData();
Rules::setBrowserTriggerArchiving(false);
$idSegment = API::getInstance()->add('testsegment', self::TEST_SEGMENT, self::$fixture->idSite, $autoArchive = true);
$storedSegment = API::getInstance()->get($idSegment);
$this->assertNotEmpty($storedSegment);
$segments = Rules::getSegmentsToProcess([self::$fixture->idSite]);
self::assertTrue(in_array(self::TEST_SEGMENT, $segments));
$this->runAnyApiTest('VisitsSummary.get', 'noLogDataSegmentUnprocessed', [
'idSite' => self::$fixture->idSite,
'date' => Date::factory(self::$fixture->dateTime)->toString(),
'period' => 'week',
'segment' => self::TEST_SEGMENT,
]);
}
public function testApiOutputWhenMultipleSitesRequestedOneWithDataOneNotAndBrowserArchivingDisabled()
{
Rules::setBrowserTriggerArchiving(false);
$idSegment = API::getInstance()->add('testsegment', self::TEST_SEGMENT, $idSite = false, $autoArchive = true);
$storedSegment = API::getInstance()->get($idSegment);
$this->assertNotEmpty($storedSegment);
$segments = Rules::getSegmentsToProcess([self::$fixture->idSite]);
self::assertTrue(in_array(self::TEST_SEGMENT, $segments));
$this->runAnyApiTest('VisitsSummary.get', 'noLogDataSegmentUnprocessedMultiSite', [
'idSite' => 'all',
'date' => Date::factory(self::$fixture->dateTime)->toString(),
'period' => 'week',
'segment' => self::TEST_SEGMENT,
]);
}
public function testAddRealTimeEnabledInApiWhenRealTimeDisabledInConfig()
{
$this->expectExceptionMessage('Real time segments are disabled. You need to enable auto archiving.');
$this->expectException(\Exception::class);
$config = Config::getInstance();
$general = $config->General;
$general['enable_create_realtime_segments'] = 0;
$config->General = $general;
API::getInstance()->add('testsegment', self::TEST_SEGMENT, $idSite = false, $autoArchive = false);
}
public function testAddRealTimeEnabledInApiWhenRealTimeEnabledInConfigShouldWork()
{
$config = Config::getInstance();
$general = $config->General;
$general['enable_create_realtime_segments'] = 1;
$config->General = $general;
$id = API::getInstance()->add('testsegment', self::TEST_SEGMENT, $idSite = false, $autoArchive = false);
$this->assertNotEmpty($id);
}
public static function getOutputPrefix()
{
return '';
}
public static function getPathToTestDirectory()
{
return dirname(__FILE__);
}
public function provideContainerConfig()
{
return [
Config::class => \Piwik\DI::decorate(function (Config $previous) {
$previous->General['browser_archiving_disabled_enforce'] = 1;
return $previous;
}),
SegmentArchiving::class => \Piwik\DI::autowire()
->constructorParameter('beginningOfTimeLastNInYears', 15)
];
}
private function clearLogData()
{
Db::query('TRUNCATE ' . Common::prefixTable('log_visit'));
Db::query('TRUNCATE ' . Common::prefixTable('log_link_visit_action'));
Db::query('TRUNCATE ' . Common::prefixTable('log_conversion'));
}
}
UnprocessedSegmentsTest::$fixture = new OneVisitorTwoVisits();