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:
authorZoltan Flamis <zoltan@innocraft.com>2021-02-23 05:41:15 +0300
committerGitHub <noreply@github.com>2021-02-23 05:41:15 +0300
commitd288c96baf2b4c30b022364f6fdefe00b41e3821 (patch)
treee2625897d0c7da55abfdbe1733d2400d0e6fed14 /plugins/SegmentEditor/tests
parent45fbd45ba47ed2d8ed0ea96e46d5c62d8d4f5264 (diff)
13976 segments not deleted (#17231)
* transfer segments when user deleted * test transferAllUserSegments * test deleted user lost segments * fix test errors * remove static modifier Co-authored-by: dizzy <diosmosis@users.noreply.github.com>
Diffstat (limited to 'plugins/SegmentEditor/tests')
-rw-r--r--plugins/SegmentEditor/tests/Integration/SegmentEditorTest.php61
1 files changed, 61 insertions, 0 deletions
diff --git a/plugins/SegmentEditor/tests/Integration/SegmentEditorTest.php b/plugins/SegmentEditor/tests/Integration/SegmentEditorTest.php
index d6b594280d..a536243a2d 100644
--- a/plugins/SegmentEditor/tests/Integration/SegmentEditorTest.php
+++ b/plugins/SegmentEditor/tests/Integration/SegmentEditorTest.php
@@ -17,6 +17,9 @@ use Piwik\Plugins\SitesManager\API as APISitesManager;
use Piwik\Tests\Framework\Mock\FakeAccess;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
use Exception;
+use Piwik\Plugins\UsersManager\UserUpdater;
+use Piwik\Plugins\SegmentEditor\SegmentEditor;
+use Piwik\Plugins\UsersManager\API as UsersManagerAPI;
/**
* Class Plugins_SegmentEditorTest
@@ -180,6 +183,49 @@ class SegmentEditorTest extends IntegrationTestCase
API::getInstance()->get($idSegment1);
}
+ public function test_transferAllUserSegmentsToSuperUser()
+ {
+ Rules::setBrowserTriggerArchiving(false);
+
+ $this->addUser('user1');
+ $this->addUser('super', true);
+
+ FakeAccess::$identity = 'user1';
+
+ $idSegment = API::getInstance()->add('name 1', 'searches==0', $idSite = 1, $autoArchive = 1, $enabledAllUsers = 0);
+ $segment = API::getInstance()->get($idSegment);
+
+ $this->assertEquals('user1', $segment['login']);
+
+ $segmentEditor = new SegmentEditor();
+ $segmentEditor->transferAllUserSegmentsToSuperUser('user1');
+
+ $segment = API::getInstance()->get($idSegment);
+
+ $this->assertEquals('super', $segment['login']);
+ }
+
+ public function test_deletedUserLostTheSegments()
+ {
+ Rules::setBrowserTriggerArchiving(false);
+ $model = new Model();
+
+ $this->addUser('user1');
+ $this->addUser('super', true);
+
+ FakeAccess::$identity = 'user1';
+ API::getInstance()->add('name 1', 'searches==0', $idSite = 1, $autoArchive = 1, $enabledAllUsers = 0);
+
+ $segments = $model->getAllSegments('user1');
+ $this->assertNotEmpty($segments);
+
+ FakeAccess::$identity = 'super';
+ $this->deleteUser('user1');
+
+ $segments = $model->getAllSegments('user1');
+ $this->assertEmpty($segments);
+ }
+
private function removeSecondsFromSegmentInfo(&$segmentInfo)
{
$timestampProperties = array('ts_last_edit', 'ts_created');
@@ -196,4 +242,19 @@ class SegmentEditorTest extends IntegrationTestCase
'Piwik\Access' => new FakeAccess()
);
}
+
+ private function addUser($login, $isSuper = false)
+ {
+ UsersManagerAPI::getInstance()->addUser($login, 'password', "{$login}@test.com");
+
+ if ($isSuper) {
+ $userUpdater = new UserUpdater();
+ $userUpdater->setSuperUserAccessWithoutCurrentPassword($login, true);
+ }
+ }
+
+ private function deleteUser($login)
+ {
+ UsersManagerAPI::getInstance()->deleteUser($login);
+ }
}