Skip to content

Commit b27eef5

Browse files
committed
ApiTest: set user profile photo
1 parent b37a45f commit b27eef5

File tree

6 files changed

+321
-0
lines changed

6 files changed

+321
-0
lines changed

tests/acceptance/TestHelpers/GraphHelper.php

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2468,4 +2468,109 @@ public static function getAllUsers(
24682468
self::getRequestHeaders()
24692469
);
24702470
}
2471+
2472+
/**
2473+
* @param string $baseUrl
2474+
* @param string $xRequestId
2475+
* @param string $user
2476+
* @param string $password
2477+
* @param string $source
2478+
*
2479+
* @return ResponseInterface
2480+
* @throws GuzzleException
2481+
*/
2482+
public static function addUserPhoto(
2483+
string $baseUrl,
2484+
string $xRequestId,
2485+
string $user,
2486+
string $password,
2487+
string $source
2488+
): ResponseInterface {
2489+
$url = self::getFullUrl($baseUrl, "me/photo/\$value");
2490+
return HttpRequestHelper::put(
2491+
$url,
2492+
$xRequestId,
2493+
$user,
2494+
$password,
2495+
['Content-Type' => 'image/jpeg'],
2496+
$source
2497+
);
2498+
}
2499+
2500+
/**
2501+
* @param string $baseUrl
2502+
* @param string $xRequestId
2503+
* @param string $user
2504+
* @param string $password
2505+
*
2506+
* @return ResponseInterface
2507+
* @throws GuzzleException
2508+
*/
2509+
public static function getUserPhoto(
2510+
string $baseUrl,
2511+
string $xRequestId,
2512+
string $user,
2513+
string $password
2514+
): ResponseInterface {
2515+
$url = self::getFullUrl($baseUrl, "me/photo/\$value");
2516+
return HttpRequestHelper::get(
2517+
$url,
2518+
$xRequestId,
2519+
$user,
2520+
$password
2521+
);
2522+
}
2523+
2524+
/**
2525+
* @param string $baseUrl
2526+
* @param string $xRequestId
2527+
* @param string $user
2528+
* @param string $password
2529+
* @param string $source
2530+
*
2531+
* @return ResponseInterface
2532+
* @throws GuzzleException
2533+
*/
2534+
public static function changeUserPhoto(
2535+
string $baseUrl,
2536+
string $xRequestId,
2537+
string $user,
2538+
string $password,
2539+
string $source
2540+
): ResponseInterface {
2541+
$url = self::getFullUrl($baseUrl, "me/photo/\$value");
2542+
return HttpRequestHelper::sendRequest(
2543+
$url,
2544+
$xRequestId,
2545+
"PATCH",
2546+
$user,
2547+
$password,
2548+
['Content-Type' => 'image/jpeg'],
2549+
$source
2550+
);
2551+
}
2552+
2553+
/**
2554+
* @param string $baseUrl
2555+
* @param string $xRequestId
2556+
* @param string $user
2557+
* @param string $password
2558+
*
2559+
* @return ResponseInterface
2560+
* @throws GuzzleException
2561+
*/
2562+
public static function deleteUserPhoto(
2563+
string $baseUrl,
2564+
string $xRequestId,
2565+
string $user,
2566+
string $password
2567+
): ResponseInterface {
2568+
$url = self::getFullUrl($baseUrl, "me/photo/\$value");
2569+
return HttpRequestHelper::delete(
2570+
$url,
2571+
$xRequestId,
2572+
$user,
2573+
$password
2574+
);
2575+
}
24712576
}

tests/acceptance/bootstrap/GraphContext.php

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3178,4 +3178,145 @@ public function theUserGetsAllUsersUsingTheGraphApi(?string $user = null): void
31783178

31793179
$this->featureContext->setResponse($response);
31803180
}
3181+
3182+
/**
3183+
* @When /^user "([^"]*)" sets profile photo to "([^"]*)" using the Graph API$/
3184+
*
3185+
* @param string $user
3186+
* @param string $photo
3187+
*
3188+
* @return void
3189+
* @throws GuzzleException
3190+
*/
3191+
public function userSetsUserProfilePhotoUsingTheGraphApi(
3192+
string $user,
3193+
string $photo
3194+
): void {
3195+
$source = \file_get_contents(
3196+
$this->featureContext->acceptanceTestsDirLocation() . $photo
3197+
);
3198+
$response = GraphHelper::addUserPhoto(
3199+
$this->featureContext->getBaseUrl(),
3200+
$this->featureContext->getStepLineRef(),
3201+
$user,
3202+
$this->featureContext->getPasswordForUser($user),
3203+
$source
3204+
);
3205+
$this->featureContext->setResponse($response);
3206+
}
3207+
3208+
/**
3209+
* @Given /^user "([^"]*)" has set the profile photo to "([^"]*)"$/
3210+
*
3211+
* @param string $user
3212+
* @param string $photo
3213+
*
3214+
* @return void
3215+
* @throws GuzzleException
3216+
* @throws Exception
3217+
*/
3218+
public function theUserHasSetPhoto(string $user, string $photo): void {
3219+
$response = $this->userSetsUserProfilePhotoUsingTheGraphApi($user, $photo);
3220+
$this->featureContext->theHTTPStatusCodeShouldBe(200, '', $response);
3221+
}
3222+
3223+
/**
3224+
* @When /^user "([^"]*)" (gets|tries to get) a profile photo using the Graph API$/
3225+
*
3226+
* @param string $user
3227+
*
3228+
* @return void
3229+
* @throws GuzzleException
3230+
*/
3231+
public function userShouldHasAProfilePhotoUsingTheGraphApi(string $user): void {
3232+
$response = GraphHelper::getUserPhoto(
3233+
$this->featureContext->getBaseUrl(),
3234+
$this->featureContext->getStepLineRef(),
3235+
$user,
3236+
$this->featureContext->getPasswordForUser($user)
3237+
);
3238+
$this->featureContext->setResponse($response);
3239+
}
3240+
3241+
/**
3242+
* @Then /^the profile photo should contain file "([^"]*)"$/
3243+
*
3244+
* @param string $file
3245+
*
3246+
* @return void
3247+
* @throws GuzzleException
3248+
*/
3249+
public function profilePhotoShouldContainFile(string $file): void {
3250+
$source = \file_get_contents(
3251+
$this->featureContext->acceptanceTestsDirLocation() . $file
3252+
);
3253+
Assert::assertEquals(
3254+
$source,
3255+
$this->featureContext->getResponse()->getBody()->getContents(),
3256+
"The profile photo binary does not match expected content of $file"
3257+
);
3258+
}
3259+
3260+
/**
3261+
* @Then /^for user "([^"]*)" the profile photo should contain file "([^"]*)"$/
3262+
*
3263+
* @param string $user
3264+
* @param string $file
3265+
*
3266+
* @return void
3267+
* @throws GuzzleException
3268+
*/
3269+
public function profilePhotoForUserShouldContainFile(string $user, string $file): void {
3270+
$this->featureContext->theHTTPStatusCodeShouldBe(
3271+
200,
3272+
"Expected response status code should be 200",
3273+
$this->userShouldHasAProfilePhotoUsingTheGraphApi($user)
3274+
);
3275+
$this->profilePhotoShouldContainFile($file);
3276+
}
3277+
3278+
/**
3279+
* @When /^user "([^"]*)" changes the profile photo to "([^"]*)" using the Graph API$/
3280+
*
3281+
* @param string $user
3282+
* @param string $photo
3283+
*
3284+
* @return void
3285+
* @throws GuzzleException
3286+
*/
3287+
public function userChangesUserProfilePhotoUsingTheGraphApi(
3288+
string $user,
3289+
string $photo
3290+
): void {
3291+
$source = \file_get_contents(
3292+
$this->featureContext->acceptanceTestsDirLocation() . $photo
3293+
);
3294+
$response = GraphHelper::changeUserPhoto(
3295+
$this->featureContext->getBaseUrl(),
3296+
$this->featureContext->getStepLineRef(),
3297+
$user,
3298+
$this->featureContext->getPasswordForUser($user),
3299+
$source
3300+
);
3301+
$this->featureContext->setResponse($response);
3302+
}
3303+
3304+
/**
3305+
* @When /^user "([^"]*)" deletes the profile photo using the Graph API$/
3306+
*
3307+
* @param string $user
3308+
*
3309+
* @return void
3310+
* @throws GuzzleException
3311+
*/
3312+
public function userDeletesAProfilePhotoUsingTheGraphApi(string $user): void {
3313+
$response = GraphHelper::deleteUserPhoto(
3314+
$this->featureContext->getBaseUrl(),
3315+
$this->featureContext->getStepLineRef(),
3316+
$user,
3317+
$this->featureContext->getPasswordForUser($user)
3318+
);
3319+
$this->featureContext->setResponse($response);
3320+
}
3321+
31813322
}

tests/acceptance/features/apiAntivirus/antivirus.feature

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,3 +481,13 @@ Feature: antivirus
481481
| Virus found in text.txt. Upload not possible. Virus: Eicar-Signature |
482482
And for user "Brian" the content of the file "/text.txt" of the space "new-space" should be "hello world"
483483
And for user "Alice" the content of the file "/text.txt" of the space "new-space" should be "hello world"
484+
485+
486+
Scenario Outline: try to add vired user photo
487+
When user "Alice" sets profile photo to "filesForUpload/filesWithVirus/eicar-image.jpeg" using the Graph API
488+
Then the HTTP status code should be "200"
489+
And user "Alice" should get a notification with subject "Virus found" and message:
490+
| message |
491+
| Virus found in eicar-image.jpeg. Upload not possible. Virus: Eicar-Signature |
492+
When user "Alice" tries to get a profile photo using the Graph API
493+
Then the HTTP status code should be "404"
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
Feature: user profile photo
2+
As a user, I want to provide my avatar to make my actions more visible
3+
4+
Background:
5+
Given user "Alice" has been created with default attributes
6+
7+
8+
Scenario Outline: add profile photo
9+
When user "Alice" sets profile photo to "<file>" using the Graph API
10+
Then the HTTP status code should be "<http-status-code>"
11+
And for user "Alice" the profile photo should contain file "<file>"
12+
Examples:
13+
| file | http-status-code |
14+
| filesForUpload/testavatar.jpg | 200 |
15+
| filesForUpload/testavatar.png | 200 |
16+
| filesForUpload/example.gif | 200 |
17+
| filesForUpload/lorem.txt | 400 |
18+
| filesForUpload/simple.pdf | 400 |
19+
| filesForUpload/broken-image-file.png | 400 |
20+
21+
22+
Scenario: user tries to get profile photo when none is set
23+
When user "Alice" tries to get a profile photo using the Graph API
24+
Then the HTTP status code should be "404"
25+
26+
27+
Scenario Outline: get profile photo
28+
Given user "Alice" has set the profile photo to "<file>"
29+
When user "Alice" gets a profile photo using the Graph API
30+
Then the HTTP status code should be "200"
31+
And the profile photo should contain file "<file>"
32+
Examples:
33+
| file |
34+
| filesForUpload/testavatar.jpg |
35+
| filesForUpload/testavatar.png |
36+
| filesForUpload/example.gif |
37+
38+
39+
Scenario Outline: change profile photo
40+
Given user "Alice" has set the profile photo to "filesForUpload/testavatar.jpg"
41+
When user "Alice" changes the profile photo to "<file>" using the Graph API
42+
Then the HTTP status code should be "<http-status-code>"
43+
And for user "Alice" the profile photo should contain file "<file>"
44+
Examples:
45+
| file | http-status-code |
46+
| filesForUpload/testavatar.jpg | 200 |
47+
| filesForUpload/testavatar.png | 200 |
48+
| filesForUpload/example.gif | 200 |
49+
| filesForUpload/lorem.txt | 400 |
50+
| filesForUpload/simple.pdf | 400 |
51+
| filesForUpload/broken-image-file.png | 400 |
52+
53+
54+
Scenario Outline: delete profile photo
55+
Given user "Alice" has set the profile photo to "<file>"
56+
When user "Alice" deletes the profile photo using the Graph API
57+
Then the HTTP status code should be "200"
58+
When user "Alice" tries to get a profile photo using the Graph API
59+
Then the HTTP status code should be "404"
60+
Examples:
61+
| file |
62+
| filesForUpload/testavatar.jpg |
63+
| filesForUpload/testavatar.png |
64+
| filesForUpload/example.gif |
500 Bytes
Loading
Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)