ApiTest: set user profile photo

This commit is contained in:
Viktor Scharf
2025-05-28 15:56:36 +02:00
parent b37a45f26f
commit d073551767
6 changed files with 321 additions and 0 deletions

View File

@@ -2468,4 +2468,109 @@ class GraphHelper {
self::getRequestHeaders()
);
}
/**
* @param string $baseUrl
* @param string $xRequestId
* @param string $user
* @param string $password
* @param string $source
*
* @return ResponseInterface
* @throws GuzzleException
*/
public static function addUserPhoto(
string $baseUrl,
string $xRequestId,
string $user,
string $password,
string $source
): ResponseInterface {
$url = self::getFullUrl($baseUrl, "me/photo/\$value");
return HttpRequestHelper::put(
$url,
$xRequestId,
$user,
$password,
['Content-Type' => 'image/jpeg'],
$source
);
}
/**
* @param string $baseUrl
* @param string $xRequestId
* @param string $user
* @param string $password
*
* @return ResponseInterface
* @throws GuzzleException
*/
public static function getUserPhoto(
string $baseUrl,
string $xRequestId,
string $user,
string $password
): ResponseInterface {
$url = self::getFullUrl($baseUrl, "me/photo/\$value");
return HttpRequestHelper::get(
$url,
$xRequestId,
$user,
$password
);
}
/**
* @param string $baseUrl
* @param string $xRequestId
* @param string $user
* @param string $password
* @param string $source
*
* @return ResponseInterface
* @throws GuzzleException
*/
public static function changeUserPhoto(
string $baseUrl,
string $xRequestId,
string $user,
string $password,
string $source
): ResponseInterface {
$url = self::getFullUrl($baseUrl, "me/photo/\$value");
return HttpRequestHelper::sendRequest(
$url,
$xRequestId,
"PATCH",
$user,
$password,
['Content-Type' => 'image/jpeg'],
$source
);
}
/**
* @param string $baseUrl
* @param string $xRequestId
* @param string $user
* @param string $password
*
* @return ResponseInterface
* @throws GuzzleException
*/
public static function deleteUserPhoto(
string $baseUrl,
string $xRequestId,
string $user,
string $password
): ResponseInterface {
$url = self::getFullUrl($baseUrl, "me/photo/\$value");
return HttpRequestHelper::delete(
$url,
$xRequestId,
$user,
$password
);
}
}

View File

@@ -3178,4 +3178,145 @@ class GraphContext implements Context {
$this->featureContext->setResponse($response);
}
/**
* @When /^user "([^"]*)" sets profile photo to "([^"]*)" using the Graph API$/
*
* @param string $user
* @param string $photo
*
* @return void
* @throws GuzzleException
*/
public function userSetsUserProfilePhotoUsingTheGraphApi(
string $user,
string $photo
): void {
$source = \file_get_contents(
$this->featureContext->acceptanceTestsDirLocation() . $photo
);
$response = GraphHelper::addUserPhoto(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$user,
$this->featureContext->getPasswordForUser($user),
$source
);
$this->featureContext->setResponse($response);
}
/**
* @Given /^user "([^"]*)" has set the profile photo to "([^"]*)"$/
*
* @param string $user
* @param string $photo
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
public function theUserHasSetPhoto(string $user, string $photo): void {
$response = $this->userSetsUserProfilePhotoUsingTheGraphApi($user, $photo);
$this->featureContext->theHTTPStatusCodeShouldBe(200, '', $response);
}
/**
* @When /^user "([^"]*)" (gets|tries to get) a profile photo using the Graph API$/
*
* @param string $user
*
* @return void
* @throws GuzzleException
*/
public function userShouldHasAProfilePhotoUsingTheGraphApi(string $user): void {
$response = GraphHelper::getUserPhoto(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$user,
$this->featureContext->getPasswordForUser($user)
);
$this->featureContext->setResponse($response);
}
/**
* @Then /^the profile photo should contain file "([^"]*)"$/
*
* @param string $file
*
* @return void
* @throws GuzzleException
*/
public function profilePhotoShouldContainFile(string $file): void {
$source = \file_get_contents(
$this->featureContext->acceptanceTestsDirLocation() . $file
);
Assert::assertEquals(
$source,
$this->featureContext->getResponse()->getBody()->getContents(),
"The profile photo binary does not match expected content of $file"
);
}
/**
* @Then /^for user "([^"]*)" the profile photo should contain file "([^"]*)"$/
*
* @param string $user
* @param string $file
*
* @return void
* @throws GuzzleException
*/
public function profilePhotoForUserShouldContainFile(string $user, string $file): void {
$this->featureContext->theHTTPStatusCodeShouldBe(
200,
"Expected response status code should be 200",
$this->userShouldHasAProfilePhotoUsingTheGraphApi($user)
);
$this->profilePhotoShouldContainFile($file);
}
/**
* @When /^user "([^"]*)" changes the profile photo to "([^"]*)" using the Graph API$/
*
* @param string $user
* @param string $photo
*
* @return void
* @throws GuzzleException
*/
public function userChangesUserProfilePhotoUsingTheGraphApi(
string $user,
string $photo
): void {
$source = \file_get_contents(
$this->featureContext->acceptanceTestsDirLocation() . $photo
);
$response = GraphHelper::changeUserPhoto(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$user,
$this->featureContext->getPasswordForUser($user),
$source
);
$this->featureContext->setResponse($response);
}
/**
* @When /^user "([^"]*)" deletes the profile photo using the Graph API$/
*
* @param string $user
*
* @return void
* @throws GuzzleException
*/
public function userDeletesAProfilePhotoUsingTheGraphApi(string $user): void {
$response = GraphHelper::deleteUserPhoto(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$user,
$this->featureContext->getPasswordForUser($user)
);
$this->featureContext->setResponse($response);
}
}

View File

@@ -481,3 +481,13 @@ Feature: antivirus
| Virus found in text.txt. Upload not possible. Virus: Eicar-Signature |
And for user "Brian" the content of the file "/text.txt" of the space "new-space" should be "hello world"
And for user "Alice" the content of the file "/text.txt" of the space "new-space" should be "hello world"
Scenario Outline: try adding a photo of the user containing the virus
When user "Alice" sets profile photo to "filesForUpload/filesWithVirus/eicar-image.jpeg" using the Graph API
Then the HTTP status code should be "200"
And user "Alice" should get a notification with subject "Virus found" and message:
| message |
| Virus found in eicar-image.jpeg. Upload not possible. Virus: Eicar-Signature |
When user "Alice" tries to get a profile photo using the Graph API
Then the HTTP status code should be "404"

View File

@@ -0,0 +1,64 @@
Feature: user profile photo
As a user, I want to provide my avatar to make my actions more visible
Background:
Given user "Alice" has been created with default attributes
Scenario Outline: add profile photo
When user "Alice" sets profile photo to "<file>" using the Graph API
Then the HTTP status code should be "<http-status-code>"
And for user "Alice" the profile photo should contain file "<file>"
Examples:
| file | http-status-code |
| filesForUpload/testavatar.jpg | 200 |
| filesForUpload/testavatar.png | 200 |
| filesForUpload/example.gif | 200 |
| filesForUpload/lorem.txt | 400 |
| filesForUpload/simple.pdf | 400 |
| filesForUpload/broken-image-file.png | 400 |
Scenario: user tries to get profile photo when none is set
When user "Alice" tries to get a profile photo using the Graph API
Then the HTTP status code should be "404"
Scenario Outline: get profile photo
Given user "Alice" has set the profile photo to "<file>"
When user "Alice" gets a profile photo using the Graph API
Then the HTTP status code should be "200"
And the profile photo should contain file "<file>"
Examples:
| file |
| filesForUpload/testavatar.jpg |
| filesForUpload/testavatar.png |
| filesForUpload/example.gif |
Scenario Outline: change profile photo
Given user "Alice" has set the profile photo to "filesForUpload/testavatar.jpg"
When user "Alice" changes the profile photo to "<file>" using the Graph API
Then the HTTP status code should be "<http-status-code>"
And for user "Alice" the profile photo should contain file "<file>"
Examples:
| file | http-status-code |
| filesForUpload/testavatar.jpg | 200 |
| filesForUpload/testavatar.png | 200 |
| filesForUpload/example.gif | 200 |
| filesForUpload/lorem.txt | 400 |
| filesForUpload/simple.pdf | 400 |
| filesForUpload/broken-image-file.png | 400 |
Scenario Outline: delete profile photo
Given user "Alice" has set the profile photo to "<file>"
When user "Alice" deletes the profile photo using the Graph API
Then the HTTP status code should be "200"
When user "Alice" tries to get a profile photo using the Graph API
Then the HTTP status code should be "404"
Examples:
| file |
| filesForUpload/testavatar.jpg |
| filesForUpload/testavatar.png |
| filesForUpload/example.gif |

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 500 B

View File

@@ -0,0 +1 @@
X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*