diff options
-rw-r--r-- | build/integration/features/avatar.feature | 219 | ||||
-rw-r--r-- | build/integration/features/bootstrap/Avatar.php | 105 |
2 files changed, 324 insertions, 0 deletions
diff --git a/build/integration/features/avatar.feature b/build/integration/features/avatar.feature index f7926615c01..3d2d5b9c1af 100644 --- a/build/integration/features/avatar.feature +++ b/build/integration/features/avatar.feature @@ -2,6 +2,225 @@ Feature: avatar Background: Given user "user0" exists + Given user "user1" exists + + Scenario: get default generic user avatar + When user "user0" gets avatar for type "user" and id "user0" + Then The following headers should be set + | Content-Type | image/png | + | X-NC-IsCustomAvatar | 0 | + And last avatar is a square of size 128 + And last avatar is not a single color + + Scenario: get default generic user avatar as an anonymous user + When user "anonymous" gets avatar for type "user" and id "user0" + Then The following headers should be set + | Content-Type | image/png | + | X-NC-IsCustomAvatar | 0 | + And last avatar is a square of size 128 + And last avatar is not a single color + + Scenario: get default generic guest avatar + When user "user0" gets avatar for type "guest" and id "guest0" + Then The following headers should be set + | Content-Type | image/png | + | X-NC-IsCustomAvatar | 0 | + And last avatar is a square of size 128 + And last avatar is not a single color + + Scenario: get default generic guest avatar as an anonymous user + When user "anonymous" gets avatar for type "guest" and id "guest0" + Then The following headers should be set + | Content-Type | image/png | + | X-NC-IsCustomAvatar | 0 | + And last avatar is a square of size 128 + And last avatar is not a single color + + Scenario: get generic unknown avatar + When user "user0" gets avatar for type "unknown" and id "user0" with size "128" with 404 + + + + Scenario: set generic user avatar + When user "user0" sets avatar for type "user" and id "user0" from file "data/green-square-256.png" + Then user "user0" gets avatar for type "user" and id "user0" with size "256" + And The following headers should be set + | Content-Type | image/png | + | X-NC-IsCustomAvatar | 1 | + And last avatar is a square of size 256 + And last avatar is a single "#00FF00" color + And user "anonymous" gets avatar for type "user" and id "user0" with size "256" + And The following headers should be set + | Content-Type | image/png | + | X-NC-IsCustomAvatar | 1 | + And last avatar is a square of size 256 + And last avatar is a single "#00FF00" color + + Scenario: set generic user avatar as another user + When user "user1" sets avatar for type "user" and id "user0" from file "data/green-square-256.png" with "404" + Then user "user0" gets avatar for type "user" and id "user0" + And The following headers should be set + | Content-Type | image/png | + | X-NC-IsCustomAvatar | 0 | + And last avatar is a square of size 128 + And last avatar is not a single color + + Scenario: set generic user avatar as an anonymous user + When user "anonymous" sets avatar for type "user" and id "user0" from file "data/green-square-256.png" with "404" + Then user "user0" gets avatar for type "user" and id "user0" + And The following headers should be set + | Content-Type | image/png | + | X-NC-IsCustomAvatar | 0 | + And last avatar is a square of size 128 + And last avatar is not a single color + + Scenario: set non squared image as generic user avatar + When user "user0" sets avatar for type "user" and id "user0" from file "data/coloured-pattern.png" with "400" + Then user "user0" gets avatar for type "user" and id "user0" + And The following headers should be set + | Content-Type | image/png | + | X-NC-IsCustomAvatar | 0 | + And last avatar is a square of size 128 + And last avatar is not a single color + + Scenario: set not an image as generic user avatar + When user "user0" sets avatar for type "user" and id "user0" from file "data/textfile.txt" with "400" + Then user "user0" gets avatar for type "user" and id "user0" + And The following headers should be set + | Content-Type | image/png | + | X-NC-IsCustomAvatar | 0 | + And last avatar is a square of size 128 + And last avatar is not a single color + + Scenario: set generic guest avatar + # Silently ignored + When user "user0" sets avatar for type "guest" and id "guest0" from file "data/green-square-256.png" + Then user "user0" gets avatar for type "guest" and id "guest0" + And The following headers should be set + | Content-Type | image/png | + | X-NC-IsCustomAvatar | 0 | + And last avatar is a square of size 128 + And last avatar is not a single color + + + + Scenario: delete generic user avatar + Given user "user0" sets avatar for type "user" and id "user0" from file "data/green-square-256.png" + And user "user0" gets avatar for type "user" and id "user0" with size "256" + And The following headers should be set + | Content-Type | image/png | + | X-NC-IsCustomAvatar | 1 | + And last avatar is a square of size 256 + And last avatar is a single "#00FF00" color + And user "anonymous" gets avatar for type "user" and id "user0" with size "256" + And The following headers should be set + | Content-Type | image/png | + | X-NC-IsCustomAvatar | 1 | + And last avatar is a square of size 256 + And last avatar is a single "#00FF00" color + When user "user0" deletes avatar for type "user" and id "user0" + Then user "user0" gets avatar for type "user" and id "user0" + And The following headers should be set + | Content-Type | image/png | + | X-NC-IsCustomAvatar | 0 | + And last avatar is a square of size 128 + And last avatar is not a single color + And user "anonymous" gets avatar for type "user" and id "user0" + And The following headers should be set + | Content-Type | image/png | + | X-NC-IsCustomAvatar | 0 | + And last avatar is a square of size 128 + And last avatar is not a single color + + Scenario: delete generic user avatar as another user + Given user "user0" sets avatar for type "user" and id "user0" from file "data/green-square-256.png" + And user "user0" gets avatar for type "user" and id "user0" with size "256" + And The following headers should be set + | Content-Type | image/png | + | X-NC-IsCustomAvatar | 1 | + And last avatar is a square of size 256 + And last avatar is a single "#00FF00" color + When user "user1" deletes avatar for type "user" and id "user0" with "404" + Then user "user0" gets avatar for type "user" and id "user0" with size "256" + And The following headers should be set + | Content-Type | image/png | + | X-NC-IsCustomAvatar | 1 | + And last avatar is a square of size 128 + And last avatar is a single "#00FF00" color + + Scenario: delete generic user avatar as an anonymous user + Given user "user0" sets avatar for type "user" and id "user0" from file "data/green-square-256.png" + And user "user0" gets avatar for type "user" and id "user0" with size "256" + And The following headers should be set + | Content-Type | image/png | + | X-NC-IsCustomAvatar | 1 | + And last avatar is a square of size 256 + And last avatar is a single "#00FF00" color + When user "anonymous" deletes avatar for type "user" and id "user0" with "404" + Then user "user0" gets avatar for type "user" and id "user0" with size "256" + And The following headers should be set + | Content-Type | image/png | + | X-NC-IsCustomAvatar | 1 | + And last avatar is a square of size 128 + And last avatar is a single "#00FF00" color + + Scenario: delete generic guest avatar + # Silently ignored + When user "user0" deletes avatar for type "guest" and id "guest0" + Then user "user0" gets avatar for type "guest" and id "guest0" + And The following headers should be set + | Content-Type | image/png | + | X-NC-IsCustomAvatar | 0 | + And last avatar is a square of size 128 + And last avatar is not a single color + + + + Scenario: get generic user avatar with a larger size than the original one + Given user "user0" sets avatar for type "user" and id "user0" from file "data/green-square-256.png" + When user "user0" gets avatar for type "user" and id "user0" with size "512" + Then The following headers should be set + | Content-Type | image/png | + | X-NC-IsCustomAvatar | 1 | + And last avatar is a square of size 512 + And last avatar is a single "#00FF00" color + + Scenario: get generic user avatar with a smaller size than the original one + Given user "user0" sets avatar for type "user" and id "user0" from file "data/green-square-256.png" + When user "user0" gets avatar for type "user" and id "user0" with size "128" + Then The following headers should be set + | Content-Type | image/png | + | X-NC-IsCustomAvatar | 1 | + And last avatar is a square of size 128 + And last avatar is a single "#00FF00" color + + + + Scenario: get user avatar after setting generic user avatar + Given user "user0" sets avatar for type "user" and id "user0" from file "data/green-square-256.png" + When user "user0" gets avatar for user "user0" with size "256" + And The following headers should be set + | Content-Type | image/png | + | X-NC-IsCustomAvatar | 1 | + And last avatar is a square of size 256 + And last avatar is a single "#00FF00" color + + Scenario: get generic user avatar after setting user avatar + Given Logging in using web as "user0" + And logged in user posts temporary avatar from file "data/coloured-pattern.png" + And logged in user crops temporary avatar + | x | 384 | + | y | 256 | + | w | 128 | + | h | 128 | + When user "user0" gets avatar for type "user" and id "user0" + Then The following headers should be set + | Content-Type | image/png | + | X-NC-IsCustomAvatar | 1 | + And last avatar is a square of size 128 + And last avatar is a single "#FF0000" color + + Scenario: get default user avatar When user "user0" gets avatar for user "user0" diff --git a/build/integration/features/bootstrap/Avatar.php b/build/integration/features/bootstrap/Avatar.php index 388715340c6..eda591a1e54 100644 --- a/build/integration/features/bootstrap/Avatar.php +++ b/build/integration/features/bootstrap/Avatar.php @@ -45,6 +45,111 @@ trait Avatar { } $body->close(); } + /** + * @When user :user gets avatar for type :type and id :id + * + * @param string $user + * @param string $type + * @param string $id + */ + public function userGetsAvatarForTypeAndId(string $user, string $type, string $id) { + $this->userGetsAvatarForTypeAndIdWithSize($user, $type, $id, '128'); + } + + /** + * @When user :user gets avatar for type :type and id :id with size :size + * + * @param string $user + * @param string $type + * @param string $id + * @param string $size + */ + public function userGetsAvatarForTypeAndIdWithSize(string $user, string $type, string $id, string $size) { + $this->userGetsAvatarForTypeAndIdWithSizeWith($user, $type, $id, $size, '200'); + } + + /** + * @When user :user gets avatar for type :type and id :id with size :size with :statusCode + * + * @param string $user + * @param string $type + * @param string $id + * @param string $size + * @param string $statusCode + */ + public function userGetsAvatarForTypeAndIdWithSizeWith(string $user, string $type, string $id, string $size, string $statusCode) { + $this->asAn($user); + $this->sendingToWith('GET', '/core/avatar/' . $type . '/' . $id . '/' . $size, null); + $this->theHTTPStatusCodeShouldBe($statusCode); + + if ($statusCode !== '200') { + return; + } + + $this->getLastAvatar(); + } + + /** + * @When user :user sets avatar for type :type and id :id from file :source + * + * @param string $user + * @param string $type + * @param string $id + * @param string $source + */ + public function userSetsAvatarForTypeAndIdFromFile(string $user, string $type, string $id, string $source) { + $this->userSetsAvatarForTypeAndIdFromFileWith($user, $type, $id, $source, '200'); + } + + /** + * @When user :user sets avatar for type :type and id :id from file :source with :statusCode + * + * @param string $user + * @param string $type + * @param string $id + * @param string $source + * @param string $statusCode + */ + public function userSetsAvatarForTypeAndIdFromFileWith(string $user, string $type, string $id, string $source, string $statusCode) { + $file = \GuzzleHttp\Psr7\stream_for(fopen($source, 'r')); + + $this->asAn($user); + $this->sendingToWith('POST', '/core/avatar/' . $type . '/' . $id, + [ + 'multipart' => [ + [ + 'name' => 'files[]', + 'contents' => $file + ] + ] + ]); + $this->theHTTPStatusCodeShouldBe($statusCode); + } + + /** + * @When user :user deletes avatar for type :type and id :id + * + * @param string $user + * @param string $type + * @param string $id + */ + public function userDeletesAvatarForTypeAndId(string $user, string $type, string $id) { + $this->userDeletesAvatarForTypeAndIdWith($user, $type, $id, '200'); + } + + /** + * @When user :user deletes avatar for type :type and id :id with :statusCode + * + * @param string $user + * @param string $type + * @param string $id + * @param string $statusCode + */ + public function userDeletesAvatarForTypeAndIdWith(string $user, string $type, string $id, string $statusCode) { + $this->asAn($user); + $this->sendingToWith('DELETE', '/core/avatar/' . $type . '/' . $id, null); + $this->theHTTPStatusCodeShouldBe($statusCode); + } /** * @When user :user gets avatar for user :userAvatar |