summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJoas Schilling <213943+nickvergessen@users.noreply.github.com>2023-01-03 08:54:23 +0100
committerGitHub <noreply@github.com>2023-01-03 08:54:23 +0100
commit30f896b3a9dc9d8553a20c96e894c15255bc999e (patch)
tree66ce85ce9393f390288b965b13b0d53fd63715e5 /tests
parente863b9f157bc1e4b6c14607e5d45d9aff623aa8f (diff)
parent9262b609f14698453d5e06348ddf67ae44173e4e (diff)
Merge pull request #8479 from nextcloud/feature/8412/transfer-ownership
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/features/bootstrap/FeatureContext.php14
-rw-r--r--tests/integration/features/command/user-transfer-ownership.feature165
-rw-r--r--tests/psalm-baseline.xml7
3 files changed, 184 insertions, 2 deletions
diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php
index c0f910f4c..41743b6e1 100644
--- a/tests/integration/features/bootstrap/FeatureContext.php
+++ b/tests/integration/features/bootstrap/FeatureContext.php
@@ -40,6 +40,8 @@ class FeatureContext implements Context, SnippetAcceptingContext {
/** @var string[] */
protected static $identifierToToken;
/** @var string[] */
+ protected static $identifierToId;
+ /** @var string[] */
protected static $tokenToIdentifier;
/** @var array[] */
protected static $identifierToAvatar;
@@ -146,6 +148,7 @@ class FeatureContext implements Context, SnippetAcceptingContext {
*/
public function setUp() {
self::$identifierToToken = [];
+ self::$identifierToId = [];
self::$tokenToIdentifier = [];
self::$sessionIdToUser = [];
self::$userToSessionId = [];
@@ -325,7 +328,15 @@ class FeatureContext implements Context, SnippetAcceptingContext {
$expected = $formData->getHash();
if ($shouldOrder) {
$sorter = static function (array $roomA, array $roomB): int {
- return $roomA['id'] < $roomB['id'] ? -1 : 1;
+ $idA = $roomA['id'];
+ $idB = $roomB['id'];
+ if (isset(self::$identifierToId[$idA])) {
+ $idA = self::$identifierToId[$idA];
+ }
+ if (isset(self::$identifierToId[$idB])) {
+ $idB = self::$identifierToId[$idB];
+ }
+ return $idA < $idB ? -1 : 1;
};
usort($expected, $sorter);
@@ -786,6 +797,7 @@ class FeatureContext implements Context, SnippetAcceptingContext {
if ($statusCode === 201) {
self::$identifierToToken[$identifier] = $response['token'];
+ self::$identifierToId[$identifier] = $response['id'];
self::$tokenToIdentifier[$response['token']] = $identifier;
}
}
diff --git a/tests/integration/features/command/user-transfer-ownership.feature b/tests/integration/features/command/user-transfer-ownership.feature
new file mode 100644
index 000000000..0572f2c20
--- /dev/null
+++ b/tests/integration/features/command/user-transfer-ownership.feature
@@ -0,0 +1,165 @@
+Feature: command/user-remove
+
+ Background:
+ Given user "participant1" exists
+ Given user "participant2" exists
+ Given user "participant3" exists
+
+ Scenario: Only transfer when moderator permissions
+ Given user "participant1" creates room "one-to-one" (v4)
+ | roomType | 1 |
+ | invite | participant2 |
+ Given user "participant1" creates room "user" (v4)
+ | roomType | 3 |
+ | roomName | user |
+ And user "participant1" adds user "participant2" to room "user" with 200 (v4)
+ Given user "participant1" creates room "moderator" (v4)
+ | roomType | 2 |
+ | roomName | moderator |
+ And user "participant1" adds user "participant2" to room "moderator" with 200 (v4)
+ And user "participant1" promotes "participant2" in room "moderator" with 200 (v4)
+ Given user "participant2" creates room "owner" (v4)
+ | roomType | 2 |
+ | roomName | owner |
+ Given user "participant1" creates room "self-joined" (v4)
+ | roomType | 3 |
+ | roomName | self-joined |
+ And user "participant2" joins room "self-joined" with 200 (v4)
+ And invoking occ with "talk:user:transfer-ownership participant2 participant3"
+ And the command output contains the text "Added or promoted user participant3 in 2 rooms."
+ Then the command was successful
+ And user "participant2" is participant of the following rooms (v4)
+ | id | name | type | participantType |
+ | one-to-one | participant1 | 1 | 1 |
+ | user | user | 3 | 3 |
+ | moderator | moderator | 2 | 2 |
+ | owner | owner | 2 | 1 |
+ | self-joined | self-joined | 3 | 5 |
+ And user "participant3" is participant of the following rooms (v4)
+ | id | name | type | participantType |
+ | moderator | moderator | 2 | 2 |
+ | owner | owner | 2 | 1 |
+
+ Scenario: Also transfer without moderator permissions
+ Given user "participant1" creates room "one-to-one" (v4)
+ | roomType | 1 |
+ | invite | participant2 |
+ Given user "participant1" creates room "user" (v4)
+ | roomType | 3 |
+ | roomName | user |
+ And user "participant1" adds user "participant2" to room "user" with 200 (v4)
+ Given user "participant1" creates room "moderator" (v4)
+ | roomType | 2 |
+ | roomName | moderator |
+ And user "participant1" adds user "participant2" to room "moderator" with 200 (v4)
+ And user "participant1" promotes "participant2" in room "moderator" with 200 (v4)
+ Given user "participant2" creates room "owner" (v4)
+ | roomType | 2 |
+ | roomName | owner |
+ Given user "participant1" creates room "self-joined" (v4)
+ | roomType | 3 |
+ | roomName | self-joined |
+ And user "participant2" joins room "self-joined" with 200 (v4)
+ And invoking occ with "talk:user:transfer-ownership --include-non-moderator participant2 participant3"
+ And the command output contains the text "Added or promoted user participant3 in 3 rooms."
+ Then the command was successful
+ And user "participant2" is participant of the following rooms (v4)
+ | id | name | type | participantType |
+ | one-to-one | participant1 | 1 | 1 |
+ | user | user | 3 | 3 |
+ | moderator | moderator | 2 | 2 |
+ | owner | owner | 2 | 1 |
+ | self-joined | self-joined | 3 | 5 |
+ And user "participant3" is participant of the following rooms (v4)
+ | id | name | type | participantType |
+ | user | user | 3 | 3 |
+ | moderator | moderator | 2 | 2 |
+ | owner | owner | 2 | 1 |
+
+ Scenario: Remove source user on successful transfer
+ Given user "participant1" creates room "one-to-one" (v4)
+ | roomType | 1 |
+ | invite | participant2 |
+ Given user "participant1" creates room "user" (v4)
+ | roomType | 3 |
+ | roomName | user |
+ And user "participant1" adds user "participant2" to room "user" with 200 (v4)
+ Given user "participant1" creates room "moderator" (v4)
+ | roomType | 2 |
+ | roomName | moderator |
+ And user "participant1" adds user "participant2" to room "moderator" with 200 (v4)
+ And user "participant1" promotes "participant2" in room "moderator" with 200 (v4)
+ Given user "participant2" creates room "owner" (v4)
+ | roomType | 2 |
+ | roomName | owner |
+ Given user "participant1" creates room "self-joined" (v4)
+ | roomType | 3 |
+ | roomName | self-joined |
+ And user "participant2" joins room "self-joined" with 200 (v4)
+ And invoking occ with "talk:user:transfer-ownership --remove-source-user participant2 participant3"
+ And the command output contains the text "Added or promoted user participant3 in 2 rooms."
+ Then the command was successful
+ And user "participant2" is participant of the following rooms (v4)
+ | id | name | type | participantType |
+ | one-to-one | participant1 | 1 | 1 |
+ | user | user | 3 | 3 |
+ | self-joined | self-joined | 3 | 5 |
+ And user "participant3" is participant of the following rooms (v4)
+ | id | name | type | participantType |
+ | moderator | moderator | 2 | 2 |
+ | owner | owner | 2 | 1 |
+
+ Scenario: Promote user if source had privileges
+ Given user "participant1" creates room "moderator" (v4)
+ | roomType | 2 |
+ | roomName | moderator |
+ And user "participant1" adds user "participant2" to room "moderator" with 200 (v4)
+ And user "participant1" promotes "participant2" in room "moderator" with 200 (v4)
+ Given user "participant2" creates room "owner" (v4)
+ | roomType | 2 |
+ | roomName | owner |
+ Given user "participant2" creates room "moderator to owner" (v4)
+ | roomType | 2 |
+ | roomName | moderator to owner |
+ And user "participant2" adds user "participant3" to room "moderator to owner" with 200 (v4)
+ And user "participant2" promotes "participant3" in room "moderator to owner" with 200 (v4)
+ Given user "participant1" creates room "from self-joined to moderator" (v4)
+ | roomType | 3 |
+ | roomName | from self-joined to moderator |
+ And user "participant1" adds user "participant2" to room "from self-joined to moderator" with 200 (v4)
+ And user "participant1" promotes "participant2" in room "from self-joined to moderator" with 200 (v4)
+ Given user "participant1" creates room "from self-joined to user" (v4)
+ | roomType | 3 |
+ | roomName | from self-joined to user |
+ And user "participant1" adds user "participant2" to room "from self-joined to user" with 200 (v4)
+ And user "participant3" is participant of the following rooms (v4)
+ | id | name | type | participantType |
+ | moderator to owner | moderator to owner | 2 | 2 |
+ And user "participant3" joins room "from self-joined to user" with 200 (v4)
+ And user "participant3" is participant of the following unordered rooms (v4)
+ | id | name | type | participantType |
+ | moderator to owner | moderator to owner | 2 | 2 |
+ | from self-joined to user | from self-joined to user | 3 | 5 |
+ And user "participant3" joins room "from self-joined to moderator" with 200 (v4)
+ And user "participant3" is participant of the following unordered rooms (v4)
+ | id | name | type | participantType |
+ | moderator to owner | moderator to owner | 2 | 2 |
+ | from self-joined to user | from self-joined to user | 3 | 5 |
+ | from self-joined to moderator | from self-joined to moderator | 3 | 5 |
+ And invoking occ with "talk:user:transfer-ownership --include-non-moderator participant2 participant3"
+ And the command output contains the text "Added or promoted user participant3 in 5 rooms."
+ Then the command was successful
+ And user "participant2" is participant of the following rooms (v4)
+ | id | name | type | participantType |
+ | moderator | moderator | 2 | 2 |
+ | owner | owner | 2 | 1 |
+ | moderator to owner | moderator to owner | 2 | 1 |
+ | from self-joined to moderator | from self-joined to moderator | 3 | 2 |
+ | from self-joined to user | from self-joined to user | 3 | 3 |
+ And user "participant3" is participant of the following unordered rooms (v4)
+ | id | name | type | participantType |
+ | moderator | moderator | 2 | 2 |
+ | owner | owner | 2 | 1 |
+ | moderator to owner | moderator to owner | 2 | 1 |
+ | from self-joined to moderator | from self-joined to moderator | 3 | 2 |
+ | from self-joined to user | from self-joined to user | 3 | 3 |
diff --git a/tests/psalm-baseline.xml b/tests/psalm-baseline.xml
index abdde0391..2412a5e96 100644
--- a/tests/psalm-baseline.xml
+++ b/tests/psalm-baseline.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<files psalm-version="5.1.0@4defa177c89397c5e14737a80fe4896584130674">
+<files psalm-version="5.2.0@fb685a16df3050d4c18d8a4100fe83abe6458cba">
<file src="lib/AppInfo/Application.php">
<UndefinedClass occurrences="2">
<code>BeforeTemplateRenderedEvent</code>
@@ -154,6 +154,11 @@
<code>Base</code>
</UndefinedClass>
</file>
+ <file src="lib/Command/User/TransferOwnership.php">
+ <UndefinedClass occurrences="1">
+ <code>Base</code>
+ </UndefinedClass>
+ </file>
<file src="lib/Config.php">
<NullArgument occurrences="1">
<code>null</code>