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:
authorPeter Zhang <peter@innocraft.com>2022-01-21 17:45:12 +0300
committerGitHub <noreply@github.com>2022-01-21 17:45:12 +0300
commitb277655b9163ca0181a67087be6c0dcaea63dc20 (patch)
treee48b36a2a76163ba7197440dae457cce6f2a1bc1 /tests/PHPUnit/Integration
parent1e26baf4dc0eec3eba84d1f0422a95f5835252e9 (diff)
disable cron task when segment is deleted (#18383)
* Update Segment.php add function * update segment on cron when is deleted update segment on cron when is deleted * Update QueueConsumer.php change to check segement * Update QueueConsumer.php remove used function * Update QueueConsumer.php update Segment availbel * Update QueueConsumer.php update queue * Update QueueConsumer.php trigger update * update update * Update QueueConsumer.php remove plugin check * Revert "Update QueueConsumer.php" This reverts commit e059f4b7f3eef4e0807987e3f0bb09fc12cd0bf8. * Update QueueConsumer.php remove the right part * Update core/CronArchive/QueueConsumer.php Co-authored-by: Stefan Giehl <stefan@matomo.org> * try simple solution try simple solution * Adds invalid segment test case * fix segment errors fix segment errors * Update CronArchiveInvalidSegmentTest.php update tests * Update CronArchiveInvalidSegmentTest.php update tests * update tests update tests * update tests and words update tests and words * update log info and tests update log info and tests Co-authored-by: Stefan Giehl <stefan@matomo.org>
Diffstat (limited to 'tests/PHPUnit/Integration')
-rw-r--r--tests/PHPUnit/Integration/CronArchiveInvalidSegmentTest.php108
1 files changed, 108 insertions, 0 deletions
diff --git a/tests/PHPUnit/Integration/CronArchiveInvalidSegmentTest.php b/tests/PHPUnit/Integration/CronArchiveInvalidSegmentTest.php
new file mode 100644
index 0000000000..2752244c04
--- /dev/null
+++ b/tests/PHPUnit/Integration/CronArchiveInvalidSegmentTest.php
@@ -0,0 +1,108 @@
+<?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\Tests\Integration;
+
+use Piwik\ArchiveProcessor\Rules;
+use Piwik\CronArchive;
+use Piwik\Date;
+use Piwik\Plugin\Manager;
+use Piwik\Tests\Framework\Fixture;
+use Piwik\Tests\Framework\Mock\FakeLogger;
+use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
+use Piwik\Plugins\SegmentEditor\API as SegmentAPI;
+use Piwik\Version;
+
+/**
+ * @group Archiver
+ * @group CronArchive
+ */
+class CronArchiveInvalidSegmentTest extends IntegrationTestCase
+{
+ /** @var FakeLogger */
+ private $logger;
+
+ public function setUp(): void
+ {
+ \Piwik\Tests\Framework\Mock\FakeCliMulti::$specifiedResults = array(
+ '/method=API.get/' => json_encode(array(array('nb_visits' => 1)))
+ );
+
+ Fixture::createWebsite('2014-12-12 00:01:02');
+
+ Manager::getInstance()->activatePlugin('UserLanguage');
+
+ Rules::setBrowserTriggerArchiving(false);
+ SegmentAPI::getInstance()->add('languageSegment', 'languageCode==fr', 1, true, true);
+
+ $tracker = Fixture::getTracker(1, '2019-12-12 02:03:00');
+ $tracker->setUrl('http://someurl.com');
+ Fixture::checkResponse($tracker->doTrackPageView('abcdefg'));
+
+ $tracker->setForceVisitDateTime('2019-12-11 03:04:05');
+ $tracker->setUrl('http://someurl.com/2');
+ Fixture::checkResponse($tracker->doTrackPageView('abcdefg2'));
+
+ $tracker->setForceVisitDateTime('2019-12-10 03:04:05');
+ $tracker->setUrl('http://someurl.com/3');
+ Fixture::checkResponse($tracker->doTrackPageView('abcdefg3'));
+
+ $tracker->setForceVisitDateTime('2019-12-02 03:04:05');
+ $tracker->setUrl('http://someurl.com/4');
+ Fixture::checkResponse($tracker->doTrackPageView('abcdefg4'));
+
+ $this->logger = new FakeLogger();
+
+
+ }
+
+ public function test_output_invalidSegment()
+ {
+ $archiver = new CronArchive($this->logger);
+
+ $archiver->init();
+ $archiver->run();
+
+ $this->assertStringNotContainsStringIgnoringCase('Got invalid response from API request', $this->logger->output);
+ $this->assertStringContainsString("Skipped Archiving website id 1", $this->logger->output);
+ $this->assertStringContainsString('no error', $this->logger->output);
+ }
+
+ public function test_output_invalidSegment_whenPluginIsNotActive()
+ {
+ Manager::getInstance()->deactivatePlugin('UserLanguage');
+
+ $archiver = new CronArchive($this->logger);
+
+ $archiver->init();
+ $archiver->run();
+
+ $this->assertStringNotContainsStringIgnoringCase('Got invalid response from API request', $this->logger->output);
+ $this->assertStringContainsString("Segment 'languageCode==fr' is not a supported segment", $this->logger->output);
+ $this->assertStringContainsString('no error', $this->logger->output);
+ }
+
+ public function provideContainerConfig()
+ {
+ Date::$now = strtotime('2020-02-03 04:05:06');
+
+ return array(
+ 'observers.global' => \DI\add([
+ ['API.CoreAdminHome.archiveReports', \DI\value(function (&$result) {
+ Manager::getInstance()->deactivatePlugin('UserLanguage');
+ })]
+ ]),
+ );
+ }
+
+ protected static function configureFixture($fixture)
+ {
+ parent::configureFixture($fixture);
+ $fixture->createSuperUser = true;
+ }
+}