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:
authordizzy <diosmosis@users.noreply.github.com>2021-04-15 10:53:44 +0300
committerGitHub <noreply@github.com>2021-04-15 10:53:44 +0300
commit6e3f165ab16f49969b7393ca752aad51e180bf0d (patch)
treed3f47385025ce8a9bab41e4bf469e24a0dd8e6ef /plugins/SegmentEditor/tests
parent7e091d1a32af18ed506fe113e22bb2a3d8053385 (diff)
add some assertions for segment rearchive so there is test coverage (#17460)
Diffstat (limited to 'plugins/SegmentEditor/tests')
-rw-r--r--plugins/SegmentEditor/tests/Integration/SegmentEditorTest.php32
1 files changed, 31 insertions, 1 deletions
diff --git a/plugins/SegmentEditor/tests/Integration/SegmentEditorTest.php b/plugins/SegmentEditor/tests/Integration/SegmentEditorTest.php
index a536243a2d..ec594117a9 100644
--- a/plugins/SegmentEditor/tests/Integration/SegmentEditorTest.php
+++ b/plugins/SegmentEditor/tests/Integration/SegmentEditorTest.php
@@ -9,6 +9,7 @@
namespace Piwik\Plugins\SegmentEditor\tests\Integration;
use Piwik\ArchiveProcessor\Rules;
+use Piwik\CronArchive\ReArchiveList;
use Piwik\Date;
use Piwik\Piwik;
use Piwik\Plugins\SegmentEditor\API;
@@ -32,6 +33,8 @@ class SegmentEditorTest extends IntegrationTestCase
{
parent::setUp();
+ Date::$now = strtotime('2020-03-01 00:00:00');
+
\Piwik\Plugin\Manager::getInstance()->loadPlugin('SegmentEditor');
\Piwik\Plugin\Manager::getInstance()->installLoadedPlugins();
@@ -59,10 +62,13 @@ class SegmentEditorTest extends IntegrationTestCase
public function test_AddAndGet_SimpleSegment()
{
+ Rules::setBrowserTriggerArchiving(false);
+
$name = 'name';
$definition = 'searches>1,visitIp!=127.0.0.1';
$idSegment = API::getInstance()->add($name, $definition);
$this->assertEquals($idSegment, 1);
+ $this->assertReArchivesQueued([]); // none since not auto archive
$segment = API::getInstance()->get($idSegment);
unset($segment['ts_created']);
$expected = array(
@@ -88,6 +94,9 @@ class SegmentEditorTest extends IntegrationTestCase
$definition = 'searches>1,visitIp!=127.0.0.1';
$idSegment = API::getInstance()->add($name, $definition, $idSite = 1, $autoArchive = 1, $enabledAllUsers = 1);
$this->assertEquals($idSegment, 1);
+ $this->assertReArchivesQueued([
+ ['idSites' => [1], 'pluginName' => null, 'report' => null, 'segment' => $definition, 'startDate' => Date::factory('2020-03-01 00:00:00')->getTimestamp()],
+ ]);
// Testing get()
$segment = API::getInstance()->get($idSegment);
@@ -130,13 +139,15 @@ class SegmentEditorTest extends IntegrationTestCase
$idSegment1 = API::getInstance()->add($nameSegment1, 'searches==0', $idSite = 1, $autoArchive = 1, $enabledAllUsers = 1);
$idSegment2 = API::getInstance()->add($name, $definition, $idSite = 1, $autoArchive = 1, $enabledAllUsers = 1);
+ $this->clearReArchiveList();
+
$updatedSegment = array(
'idsegment' => $idSegment2,
'name' => 'NEW name',
'definition' => 'searches==0',
'enable_only_idsite' => '0',
'enable_all_users' => '0',
- 'auto_archive' => '0',
+ 'auto_archive' => '1',
'ts_last_edit' => Date::now()->getDatetime(),
'ts_created' => Date::now()->getDatetime(),
'login' => Piwik::getCurrentUserLogin(),
@@ -150,6 +161,10 @@ class SegmentEditorTest extends IntegrationTestCase
$updatedSegment['enable_all_users']
);
+ $this->assertReArchivesQueued([
+ ['idSites' => [1], 'pluginName' => null, 'report' => null, 'segment' => $updatedSegment['definition'], 'startDate' => null],
+ ]);
+
$newSegment = API::getInstance()->get($idSegment2);
// avoid test failures for when ts_created/ts_last_edit are different by between 1/2 secs
@@ -257,4 +272,19 @@ class SegmentEditorTest extends IntegrationTestCase
{
UsersManagerAPI::getInstance()->deleteUser($login);
}
+
+ private function clearReArchiveList()
+ {
+ $list = new ReArchiveList();
+ $list->setAll([]);
+ }
+
+ private function assertReArchivesQueued($expected)
+ {
+ $list = new ReArchiveList();
+ $items = $list->getAll();
+ $items = array_map(function ($s) { return json_decode($s, true); }, $items);
+
+ $this->assertEquals($expected, $items);
+ }
}