2022-11-04 12:39:54 +01:00
<? php
declare ( strict_types = 1 );
2022-03-25 15:33:35 +05:45
/**
* ownCloud
*
* @author Kiran Parajuli <kiran@jankaritech.com>
* @copyright Copyright (c) 2021 Kiran Parajuli kiran@jankaritech.com
*/
use Behat\Behat\Context\Context ;
use Behat\Behat\Hook\Scope\BeforeScenarioScope ;
2023-04-05 14:05:34 +05:45
use Behat\Gherkin\Node\PyStringNode ;
2022-04-13 12:53:20 +05:45
use Behat\Gherkin\Node\TableNode ;
2022-03-25 15:33:35 +05:45
use GuzzleHttp\Exception\GuzzleException ;
2024-10-08 12:26:40 +05:45
use PHPUnit\Framework\Assert ;
2022-04-12 19:35:05 +05:45
use Psr\Http\Message\ResponseInterface ;
2022-04-06 20:16:33 +05:45
use TestHelpers\GraphHelper ;
2022-11-11 09:31:13 +05:45
use TestHelpers\WebDavHelper ;
2023-03-27 10:41:21 +05:45
use TestHelpers\HttpRequestHelper ;
2024-10-08 12:26:40 +05:45
use TestHelpers\BehatHelper ;
2026-07-14 10:53:02 +05:45
use TestHelpers\KeycloakHelper ;
2022-03-25 15:33:35 +05:45
2022-04-06 20:16:33 +05:45
require_once 'bootstrap.php' ;
2022-03-25 15:33:35 +05:45
/**
* Context for the provisioning specific steps using the Graph API
*/
class GraphContext implements Context {
private FeatureContext $featureContext ;
2024-09-25 16:26:13 +05:45
private SpacesContext $spacesContext ;
2022-03-25 15:33:35 +05:45
2023-02-20 09:49:05 +05:45
/**
* application Entity
*/
2023-05-02 17:25:56 +05:45
private array $appEntity = [];
2023-02-20 09:49:05 +05:45
2022-03-25 15:33:35 +05:45
/**
* This will run before EVERY scenario.
* It will set the properties for this object.
*
* @BeforeScenario
*
* @param BeforeScenarioScope $scope
*
* @return void
*/
2022-04-19 10:21:05 +05:45
public function before ( BeforeScenarioScope $scope ) : void {
2022-03-25 15:33:35 +05:45
// Get the environment
$environment = $scope -> getEnvironment ();
// Get all the contexts you need in this context from here
2024-10-08 12:26:40 +05:45
$this -> featureContext = BehatHelper :: getContext ( $scope , $environment , 'FeatureContext' );
$this -> spacesContext = BehatHelper :: getContext ( $scope , $environment , 'SpacesContext' );
2022-03-25 15:33:35 +05:45
}
2022-12-14 14:15:18 +05:45
/**
* @When /^the user "([^"]*)" changes the email of user "([^"]*)" to "([^"]*)" using the Graph API$/
* @When /^the user "([^"]*)" tries to change the email of user "([^"]*)" to "([^"]*)" using the Graph API$/
*
* @param string $byUser
* @param string $user
* @param string $email
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
public function theUserChangesTheEmailOfUserToUsingTheGraphApi ( string $byUser , string $user , string $email ) : void {
$response = $this -> editUserUsingTheGraphApi ( $byUser , $user , null , null , $email );
$this -> featureContext -> setResponse ( $response );
}
/**
* @When /^the user "([^"]*)" changes the display name of user "([^"]*)" to "([^"]*)" using the Graph API$/
* @When /^the user "([^"]*)" tries to change the display name of user "([^"]*)" to "([^"]*)" using the Graph API$/
*
* @param string $byUser
* @param string $user
* @param string $displayName
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function theUserChangesTheDisplayNameOfUserToUsingTheGraphApi (
string $byUser ,
string $user ,
2025-06-19 15:34:02 +05:45
string $displayName ,
2024-12-24 09:30:42 +05:45
) : void {
2022-12-14 14:15:18 +05:45
$response = $this -> editUserUsingTheGraphApi ( $byUser , $user , null , null , null , $displayName );
$this -> featureContext -> setResponse ( $response );
}
2023-03-10 09:02:33 +01:00
/**
* @When /^the user "([^"]*)" changes the user name of user "([^"]*)" to "([^"]*)" using the Graph API$/
* @When /^the user "([^"]*)" tries to change the user name of user "([^"]*)" to "([^"]*)" using the Graph API$/
*
* @param string $byUser
* @param string $user
2025-02-17 18:44:30 +05:45
* @param string $newUsername
2023-03-10 09:02:33 +01:00
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function theUserChangesTheUserNameOfUserToUsingTheGraphApi (
string $byUser ,
string $user ,
2025-06-19 15:34:02 +05:45
string $newUsername ,
2024-12-24 09:30:42 +05:45
) : void {
2025-02-17 18:44:30 +05:45
$response = $this -> editUserUsingTheGraphApi ( $byUser , $user , $newUsername );
2023-03-10 09:02:33 +01:00
$this -> featureContext -> setResponse ( $response );
2025-02-17 18:44:30 +05:45
// save the updated user
if ( ! empty ( $newUsername ) && $response -> getStatusCode () === 200 ) {
$this -> featureContext -> rememberThatUserIsNotExpectedToExist ( $user );
$this -> featureContext -> addUserToCreatedUsersList (
$newUsername ,
2025-06-19 15:34:02 +05:45
$this -> featureContext -> getUserPassword ( $user ),
2025-02-17 18:44:30 +05:45
);
2023-03-10 09:02:33 +01:00
}
}
2023-03-06 12:07:55 +01:00
/**
* @When /^the user "([^"]*)" disables user "([^"]*)" using the Graph API$/
* @When /^the user "([^"]*)" tries to disable user "([^"]*)" using the Graph API$/
*
* @param string $byUser
* @param string $user
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
public function theUserDisablesUserToUsingTheGraphApi ( string $byUser , string $user ) : void {
$response = $this -> editUserUsingTheGraphApi ( $byUser , $user , null , null , null , null , false );
$this -> featureContext -> setResponse ( $response );
}
/**
2024-01-11 11:31:55 +05:45
* @Given /^the user "([^"]*)" has disabled user "([^"]*)"$/
2023-03-06 12:07:55 +01:00
*
* @param string $byUser
* @param string $user
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
2024-01-11 11:31:55 +05:45
public function theUserHasDisabledUser ( string $byUser , string $user ) : void {
2024-05-06 09:36:35 +05:45
$response = $this -> editUserUsingTheGraphApi ( $byUser , $user , null , null , null , null , false );
$this -> featureContext -> theHTTPStatusCodeShouldBe ( 200 , '' , $response );
2023-03-06 12:07:55 +01:00
}
/**
* @When /^the user "([^"]*)" enables user "([^"]*)" using the Graph API$/
* @When /^the user "([^"]*)" tries to enable user "([^"]*)" using the Graph API$/
*
* @param string $byUser
* @param string $user
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
public function theUserEnablesUserToUsingTheGraphApi ( string $byUser , string $user ) : void {
2023-05-02 17:25:56 +05:45
$response = $this -> editUserUsingTheGraphApi ( $byUser , $user );
2023-03-06 12:07:55 +01:00
$this -> featureContext -> setResponse ( $response );
}
2022-12-14 14:15:18 +05:45
/**
2023-04-05 14:05:34 +05:45
* @Then /^the user information of "([^"]*)" should match this JSON schema$/
2022-12-14 14:15:18 +05:45
*
* @param string $user
2023-04-05 14:05:34 +05:45
* @param PyStringNode $schemaString
2022-12-14 14:15:18 +05:45
*
* @return void
* @throws Exception
* @throws GuzzleException
* @throws JsonException
*/
2023-04-05 14:05:34 +05:45
public function theUserInformationShouldMatchTheJSON ( string $user , PyStringNode $schemaString ) : void {
2023-10-31 12:17:50 +05:45
$response = $this -> adminHasRetrievedUserUsingTheGraphApi ( $user );
2024-02-23 16:24:22 +05:45
$responseBody = $this -> featureContext -> getJsonDecodedResponseBodyContent ( $response );
$this -> featureContext -> assertJsonDocumentMatchesSchema (
$responseBody ,
2025-06-19 15:34:02 +05:45
$this -> featureContext -> getJSONSchema ( $schemaString ),
2024-02-23 16:24:22 +05:45
);
2022-12-14 14:15:18 +05:45
}
/**
* Edits the user information
*
* @param string $byUser
* @param string $user
* @param string|null $userName
* @param string|null $password
* @param string|null $email
* @param string|null $displayName
2023-03-06 12:07:55 +01:00
* @param bool|true $accountEnabled
2023-10-31 12:17:50 +05:45
* @param string $method
2022-12-14 14:15:18 +05:45
*
* @return void
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function editUserUsingTheGraphApi (
string $byUser ,
string $user ,
2025-06-24 11:39:50 +02:00
? string $userName = null ,
? string $password = null ,
? string $email = null ,
? string $displayName = null ,
2024-12-24 09:30:42 +05:45
bool $accountEnabled = true ,
2025-06-19 15:34:02 +05:45
string $method = "PATCH" ,
2024-12-24 09:30:42 +05:45
) : ResponseInterface {
2022-12-14 14:15:18 +05:45
$user = $this -> featureContext -> getActualUsername ( $user );
2024-07-18 16:17:52 +05:45
$userId = $this -> featureContext -> getAttributeOfCreatedUser ( $user , 'id' ) ?: $user ;
2022-12-14 14:15:18 +05:45
return GraphHelper :: editUser (
$this -> featureContext -> getBaseUrl (),
$byUser ,
$this -> featureContext -> getPasswordForUser ( $byUser ),
$userId ,
2023-10-31 12:17:50 +05:45
$method ,
2022-12-14 14:15:18 +05:45
$userName ,
$password ,
$email ,
2023-03-06 12:07:55 +01:00
$displayName ,
2025-06-19 15:34:02 +05:45
$accountEnabled ,
2022-12-14 14:15:18 +05:45
);
}
2022-04-06 20:16:33 +05:45
/**
2022-03-25 15:33:35 +05:45
* @param string $user
*
2023-10-31 12:17:50 +05:45
* @return ResponseInterface
2022-04-06 20:16:33 +05:45
* @throws JsonException
2022-03-25 15:33:35 +05:45
* @throws GuzzleException
*/
2023-10-31 12:17:50 +05:45
public function adminHasRetrievedUserUsingTheGraphApi ( string $user ) : ResponseInterface {
2022-03-25 15:33:35 +05:45
$user = $this -> featureContext -> getActualUsername ( $user );
2023-03-09 16:21:50 +05:45
$userId = $this -> featureContext -> getAttributeOfCreatedUser ( $user , "id" );
2023-05-02 17:25:56 +05:45
$userId = $userId ?: $user ;
2026-07-30 12:07:41 +05:45
$adminUser = $this -> featureContext -> getAdminUsername ();
$headers = [];
if ( KeycloakHelper :: isTestingWithKeycloak ()) {
$accessToken = $this -> featureContext -> getOcisUserToken ( $adminUser )[ "token" ][ "accessToken" ];
$headers [ 'Authorization' ] = 'Bearer ' . $accessToken ;
$adminUser = null ;
$adminPassword = null ;
} else {
$adminPassword = $this -> featureContext -> getAdminPassword ();
}
2023-10-31 12:17:50 +05:45
return GraphHelper :: getUser (
2022-03-25 15:33:35 +05:45
$this -> featureContext -> getBaseUrl (),
2026-07-30 12:07:41 +05:45
$adminUser ,
$adminPassword ,
2025-06-19 15:34:02 +05:45
$userId ,
2026-07-30 12:07:41 +05:45
$headers ,
2022-04-06 20:16:33 +05:45
);
}
2022-11-23 17:20:37 +05:45
/**
* @param string $groupId
* @param string|null $user
*
* @return ResponseInterface
* @throws GuzzleException
*/
2024-04-18 17:28:38 +05:45
public function deleteGroupWithId (
2022-11-23 17:20:37 +05:45
string $groupId ,
2025-06-19 15:34:02 +05:45
? string $user = null ,
2022-11-23 17:20:37 +05:45
) : ResponseInterface {
$credentials = $this -> getAdminOrUserCredentials ( $user );
2026-09-14 15:49:35 +02:00
$requestUser = $credentials [ "username" ];
$requestPass = $credentials [ "password" ];
$headers = [];
if ( KeycloakHelper :: isTestingWithKeycloak ()) {
$access_token = $this -> featureContext -> getOcisUserToken ( $requestUser )[ "token" ][ "accessToken" ];
$headers [ 'Authorization' ] = 'Bearer ' . $access_token ;
$requestUser = null ;
$requestPass = null ;
}
2022-11-23 17:20:37 +05:45
return GraphHelper :: deleteGroup (
$this -> featureContext -> getBaseUrl (),
2026-09-14 15:49:35 +02:00
$requestUser ,
$requestPass ,
2025-06-19 15:34:02 +05:45
$groupId ,
2026-09-14 15:49:35 +02:00
$headers ,
2022-11-23 17:20:37 +05:45
);
}
2022-04-06 20:16:33 +05:45
/**
* @param string $group
*
2024-04-18 17:28:38 +05:45
* @return ResponseInterface
2022-04-06 20:16:33 +05:45
* @throws Exception
* @throws GuzzleException
*/
2024-04-18 17:28:38 +05:45
public function deleteGroupWithName (
2025-06-19 15:34:02 +05:45
string $group ,
2024-04-18 17:28:38 +05:45
) : ResponseInterface {
2022-04-06 20:16:33 +05:45
$groupId = $this -> featureContext -> getAttributeOfCreatedGroup ( $group , "id" );
2024-04-18 17:28:38 +05:45
return $this -> deleteGroupWithId ( $groupId );
2022-04-06 20:16:33 +05:45
}
/**
* sends a request to delete a user using the Graph API
*
* @param string $user username is used as the id
2022-11-30 18:54:09 +05:45
* @param string|null $byUser
2022-04-06 20:16:33 +05:45
*
2023-12-01 14:02:39 +05:45
* @return ResponseInterface
2022-04-06 20:16:33 +05:45
* @throws GuzzleException
*/
2023-10-31 12:01:36 +05:45
public function adminDeletesUserUsingTheGraphApi ( string $user , ? string $byUser = null ) : ResponseInterface {
2022-11-30 18:54:09 +05:45
$credentials = $this -> getAdminOrUserCredentials ( $byUser );
2026-07-14 10:53:02 +05:45
$adminUser = $credentials [ "username" ];
$adminPass = $credentials [ "password" ];
$headers = [];
if ( KeycloakHelper :: isTestingWithKeycloak ()) {
$access_token = $this -> featureContext -> getOcisUserToken ( $adminUser )[ "token" ][ "accessToken" ];
$headers [ 'Authorization' ] = 'Bearer ' . $access_token ;
$adminUser = null ;
$adminPass = null ;
}
2025-02-17 18:44:30 +05:45
$response = GraphHelper :: deleteUser (
2023-10-31 12:01:36 +05:45
$this -> featureContext -> getBaseUrl (),
2025-06-19 15:34:02 +05:45
$user ,
2026-07-14 10:53:02 +05:45
$adminUser ,
$adminPass ,
$headers ,
2022-03-25 15:33:35 +05:45
);
2025-02-17 18:44:30 +05:45
if ( $response -> getStatusCode () === 204 ) {
$this -> featureContext -> rememberThatUserIsNotExpectedToExist ( $user );
}
return $response ;
2022-03-25 15:33:35 +05:45
}
2022-11-28 14:13:52 +05:45
/**
2024-04-26 15:27:00 +05:45
* remove user from a group
2022-11-28 14:13:52 +05:45
*
2023-11-29 10:35:55 +05:45
* @param string $group
* @param string $user
2022-11-28 14:13:52 +05:45
* @param string|null $byUser
*
* @return ResponseInterface
* @throws GuzzleException
*/
2023-11-29 10:35:55 +05:45
public function removeUserFromGroup ( string $group , string $user , ? string $byUser = null ) : ResponseInterface {
$groupId = $this -> featureContext -> getAttributeOfCreatedGroup ( $group , "id" ) ?: WebDavHelper :: generateUUIDv4 ();
$userId = $this -> featureContext -> getAttributeOfCreatedUser ( $user , "id" );
2022-11-28 14:13:52 +05:45
$credentials = $this -> getAdminOrUserCredentials ( $byUser );
return GraphHelper :: removeUserFromGroup (
$this -> featureContext -> getBaseUrl (),
$credentials [ 'username' ],
$credentials [ 'password' ],
$userId ,
$groupId ,
);
}
2023-03-21 10:03:51 +05:45
/**
* sends a request to delete a user with the help of userID using the Graph API
*
2025-02-17 18:44:30 +05:45
* @param string $user
2023-03-21 10:03:51 +05:45
* @param string $byUser
*
* @return ResponseInterface
* @throws GuzzleException
*/
2025-02-17 18:44:30 +05:45
public function deleteUserByUserId ( string $user , string $byUser ) : ResponseInterface {
if ( $user === "nonexistent" ) {
$userId = WebDavHelper :: generateUUIDv4 ();
} else {
$userId = $this -> featureContext -> getUserIdByUserName ( $user );
}
2023-03-21 10:03:51 +05:45
$credentials = $this -> getAdminOrUserCredentials ( $byUser );
2025-02-17 18:44:30 +05:45
$response = GraphHelper :: deleteUserByUserId (
2023-03-21 10:03:51 +05:45
$this -> featureContext -> getBaseUrl (),
$credentials [ "username" ],
$credentials [ "password" ],
2025-06-19 15:34:02 +05:45
$userId ,
2023-03-21 10:03:51 +05:45
);
2025-02-17 18:44:30 +05:45
if ( $response -> getStatusCode () === 204 ) {
$this -> featureContext -> rememberThatUserIsNotExpectedToExist ( $user );
}
return $response ;
2023-03-21 10:03:51 +05:45
}
2022-11-30 18:54:09 +05:45
/**
* @When /^the user "([^"]*)" deletes a user "([^"]*)" using the Graph API$/
*
* @param string $byUser
* @param string $user
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
public function theUserDeletesAUserUsingTheGraphAPI ( string $byUser , string $user ) : void {
2025-02-17 18:44:30 +05:45
$this -> featureContext -> setResponse ( $this -> deleteUserByUserId ( $user , $byUser ));
2023-03-21 10:03:51 +05:45
}
/**
* @When /^the user "([^"]*)" tries to delete a nonexistent user using the Graph API$/
*
* @param string $byUser
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
public function theUserTriesToDeleteNonExistingUser ( string $byUser ) : void {
2025-02-17 18:44:30 +05:45
$this -> featureContext -> setResponse ( $this -> deleteUserByUserId ( "nonexistent" , $byUser ));
2022-11-30 18:54:09 +05:45
}
2023-03-06 12:07:55 +01:00
/**
2024-01-11 14:21:28 +05:45
* @Given /^the user "([^"]*)" has deleted a user "([^"]*)"$/
2023-03-06 12:07:55 +01:00
*
* @param string $byUser
* @param string $user
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
2024-01-11 14:21:28 +05:45
public function theUserHasDeletedAUser ( string $byUser , string $user ) : void {
2023-10-31 12:01:36 +05:45
$response = $this -> adminDeletesUserUsingTheGraphApi ( $user , $byUser );
$this -> featureContext -> theHttpStatusCodeShouldBe ( 204 , "" , $response );
2023-03-06 12:07:55 +01:00
}
2022-03-25 15:33:35 +05:45
/**
2022-04-06 20:16:33 +05:45
* @param string $user
* @param string $group
2022-03-25 15:33:35 +05:45
*
* @return void
2022-04-06 20:16:33 +05:45
* @throws JsonException
* @throws GuzzleException
*/
2022-04-19 10:21:05 +05:45
public function adminHasRemovedUserFromGroupUsingTheGraphApi ( string $user , string $group ) : void {
2022-04-06 20:16:33 +05:45
$user = $this -> featureContext -> getActualUsername ( $user );
2023-11-29 10:35:55 +05:45
$response = $this -> removeUserFromGroup ( $group , $user );
$this -> featureContext -> TheHTTPStatusCodeShouldBe ( 204 , '' , $response );
2022-04-06 20:16:33 +05:45
}
/**
* check if the provided user is present as a member in the provided group
*
* @param string $user
* @param string $group
*
* @return bool
* @throws JsonException
* @throws Exception
2022-03-25 15:33:35 +05:45
* @throws GuzzleException
*/
2022-04-06 20:16:33 +05:45
public function getUserPresenceInGroupUsingTheGraphApi ( string $user , string $group ) : bool {
$user = $this -> featureContext -> getActualUsername ( $user );
$userId = $this -> featureContext -> getAttributeOfCreatedUser ( $user , "id" );
$members = $this -> theAdminHasRetrievedMembersListOfGroupUsingTheGraphApi ( $group );
$found = false ;
foreach ( $members as $member ) {
if ( $member [ "id" ] === $userId ) {
$found = true ;
break ;
}
2022-03-25 15:33:35 +05:45
}
2022-04-06 20:16:33 +05:45
return $found ;
2022-03-25 15:33:35 +05:45
}
2022-04-12 19:35:05 +05:45
/**
* @param string $user
* @param string $group
*
* @return void
* @throws JsonException
* @throws GuzzleException
*/
2022-04-19 10:21:05 +05:45
public function userShouldNotBeMemberInGroupUsingTheGraphApi ( string $user , string $group ) : void {
2022-04-06 20:16:33 +05:45
$found = $this -> getUserPresenceInGroupUsingTheGraphApi ( $user , $group );
Assert :: assertFalse ( $found , __METHOD__ . " User $user is member of group $group " );
}
/**
* @param string $user
* @param string $group
2022-03-25 15:33:35 +05:45
*
* @return void
2022-04-06 20:16:33 +05:45
* @throws JsonException
2022-04-06 20:48:29 +05:45
* @throws GuzzleException
2022-04-06 20:16:33 +05:45
*/
2022-04-19 10:21:05 +05:45
public function userShouldBeMemberInGroupUsingTheGraphApi ( string $user , string $group ) : void {
2022-04-06 20:16:33 +05:45
$found = $this -> getUserPresenceInGroupUsingTheGraphApi ( $user , $group );
Assert :: assertTrue ( $found , __METHOD__ . "User $user is not member of group $group " );
}
/**
* @param string $user
* @param string $password
2022-12-14 14:15:18 +05:45
* @param string|null $byUser
2022-04-06 20:16:33 +05:45
*
* @return void
* @throws JsonException
*/
public function adminChangesPasswordOfUserToUsingTheGraphApi (
string $user ,
2022-12-14 14:15:18 +05:45
string $password ,
2025-06-19 15:34:02 +05:45
? string $byUser = null ,
2023-10-31 12:17:50 +05:45
) : ResponseInterface {
2022-12-14 14:15:18 +05:45
$credentials = $this -> getAdminOrUserCredentials ( $byUser );
2022-04-06 20:16:33 +05:45
$user = $this -> featureContext -> getActualUsername ( $user );
2024-07-18 16:17:52 +05:45
$userId = $this -> featureContext -> getAttributeOfCreatedUser ( $user , "id" ) ?: $user ;
2023-10-31 12:17:50 +05:45
return GraphHelper :: editUser (
2022-04-06 20:16:33 +05:45
$this -> featureContext -> getBaseUrl (),
2022-12-14 14:15:18 +05:45
$credentials [ "username" ],
$credentials [ "password" ],
2022-04-06 20:16:33 +05:45
$userId ,
2023-10-31 12:17:50 +05:45
"PATCH" ,
$user ,
2025-06-19 15:34:02 +05:45
$password ,
2022-04-06 20:16:33 +05:45
);
}
2022-12-14 14:15:18 +05:45
/**
* @When /^the user "([^"]*)" resets the password of user "([^"]*)" to "([^"]*)" using the Graph API$/
*
* @param string $byUser
* @param string $user
* @param string $password
*
* @return void
* @throws Exception
*/
2025-06-19 12:15:41 +05:45
public function theUserResetsThePasswordOfUserToUsingTheGraphApi (
string $byUser ,
string $user ,
2025-06-19 15:34:02 +05:45
string $password ,
2025-06-19 12:15:41 +05:45
) : void {
2023-10-31 12:17:50 +05:45
$response = $this -> adminChangesPasswordOfUserToUsingTheGraphApi ( $user , $password , $byUser );
$this -> featureContext -> setResponse ( $response );
2022-12-14 14:15:18 +05:45
}
2022-04-06 20:16:33 +05:45
/**
2022-04-12 19:35:05 +05:45
*
2022-11-15 20:56:43 +05:45
* @param array $groups
*
* @return void
* @throws Exception
*/
public function theseGroupsShouldBeInTheResponse ( array $groups ) : void {
$respondedGroups = $this -> getArrayOfGroupsResponded ( $this -> featureContext -> getResponse ());
foreach ( $groups as $group ) {
$found = false ;
foreach ( $respondedGroups as $respondedGroup ) {
if ( $respondedGroup [ "displayName" ] === $group ) {
$found = true ;
break ;
}
}
Assert :: assertTrue ( $found , "Group ' $group ' not found in the list" );
}
}
/**
*
* @param array $users
*
* @return void
2022-03-25 15:33:35 +05:45
* @throws Exception
2022-11-15 20:56:43 +05:45
*/
public function theseUsersShouldBeInTheResponse ( array $users ) : void {
$respondedUsers = $this -> getArrayOfUsersResponded ( $this -> featureContext -> getResponse ());
foreach ( $users as $user ) {
$found = false ;
foreach ( $respondedUsers as $respondedUser ) {
if ( $respondedUser [ "onPremisesSamAccountName" ] === $user ) {
$found = true ;
break ;
}
}
Assert :: assertTrue ( $found , "User ' $user ' not found in the list" );
}
}
/**
*
* @param string|null $user
*
* @return array
*/
public function getAdminOrUserCredentials ( ? string $user ) : array {
2024-12-24 09:30:42 +05:45
$credentials [ "username" ] = $user ? $this -> featureContext -> getActualUsername ( $user )
: $this -> featureContext -> getAdminUsername ();
$credentials [ "password" ] = $user ? $this -> featureContext -> getPasswordForUser ( $user )
: $this -> featureContext -> getAdminPassword ();
2022-11-15 20:56:43 +05:45
return $credentials ;
}
/**
*
* @param string|null $user
*
* @return ResponseInterface
2022-04-12 19:35:05 +05:45
* @throws GuzzleException
2022-03-25 15:33:35 +05:45
*/
2022-11-15 20:56:43 +05:45
public function listGroups ( ? string $user = null ) : ResponseInterface {
$credentials = $this -> getAdminOrUserCredentials ( $user );
return GraphHelper :: getGroups (
2022-04-06 20:16:33 +05:45
$this -> featureContext -> getBaseUrl (),
2022-11-15 20:56:43 +05:45
$credentials [ "username" ],
2025-06-19 15:34:02 +05:45
$credentials [ "password" ],
2022-03-25 15:33:35 +05:45
);
2022-11-15 20:56:43 +05:45
}
/**
* returns list of groups
*
* @param ResponseInterface $response
*
* @return array
* @throws Exception
*/
public function getArrayOfGroupsResponded ( ResponseInterface $response ) : array {
2022-04-06 20:16:33 +05:45
if ( $response -> getStatusCode () === 200 ) {
2022-04-12 19:35:05 +05:45
$jsonResponseBody = $this -> featureContext -> getJsonDecodedResponse ( $response );
return $jsonResponseBody [ "value" ];
2022-04-06 20:16:33 +05:45
}
2025-06-19 10:58:37 +05:45
$this -> throwHttpException ( $response , "Could not retrieve groups list." );
2022-04-06 20:16:33 +05:45
}
/**
*
* @return array
* @throws Exception
* @throws GuzzleException
*/
2022-11-15 20:56:43 +05:45
public function adminHasRetrievedGroupListUsingTheGraphApi () : array {
2024-12-24 09:30:42 +05:45
return $this -> getArrayOfGroupsResponded ( $this -> listGroups ());
2022-11-15 20:56:43 +05:45
}
/**
*
* @param string $group
* @param string|null $user
*
* @return ResponseInterface
* @throws GuzzleException
*/
public function listGroupMembers ( string $group , ? string $user = null ) : ResponseInterface {
$credentials = $this -> getAdminOrUserCredentials ( $user );
return GraphHelper :: getMembersList (
2022-04-06 20:16:33 +05:45
$this -> featureContext -> getBaseUrl (),
2022-11-15 20:56:43 +05:45
$credentials [ "username" ],
$credentials [ "password" ],
2025-06-19 15:34:02 +05:45
$this -> featureContext -> getAttributeOfCreatedGroup ( $group , 'id' ),
2022-04-06 20:16:33 +05:45
);
2022-11-15 20:56:43 +05:45
}
2023-02-27 11:16:50 +05:45
/**
*
* @param string $user
* @param string|null $group
*
* @return ResponseInterface
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function listSingleOrAllGroupsAlongWithAllMemberInformation (
string $user ,
2025-06-19 15:34:02 +05:45
? string $group = null ,
2024-12-24 09:30:42 +05:45
) : ResponseInterface {
2023-02-27 11:16:50 +05:45
$credentials = $this -> getAdminOrUserCredentials ( $user );
return GraphHelper :: getSingleOrAllGroupsAlongWithMembers (
$this -> featureContext -> getBaseUrl (),
$credentials [ "username" ],
$credentials [ "password" ],
2025-06-19 15:34:02 +05:45
( $group ) ? $this -> featureContext -> getAttributeOfCreatedGroup ( $group , 'id' ) : null ,
2023-02-27 11:16:50 +05:45
);
}
2022-11-15 20:56:43 +05:45
/**
* returns list of users of a group
*
* @param ResponseInterface $response
*
* @return array
* @throws Exception
*/
public function getArrayOfUsersResponded ( ResponseInterface $response ) : array {
2022-04-06 20:16:33 +05:45
if ( $response -> getStatusCode () === 200 ) {
2022-04-06 20:48:29 +05:45
return $this -> featureContext -> getJsonDecodedResponse ( $response );
2022-04-06 20:16:33 +05:45
}
2025-06-19 10:58:37 +05:45
$this -> throwHttpException ( $response , "Could not retrieve group members list." );
2022-04-06 20:16:33 +05:45
}
2022-11-15 20:56:43 +05:45
/**
2024-04-26 15:27:00 +05:45
* returns a list of members in a group
2022-11-15 20:56:43 +05:45
*
* @param string $group
*
* @return array
* @throws Exception
* @throws GuzzleException
*/
public function theAdminHasRetrievedMembersListOfGroupUsingTheGraphApi ( string $group ) : array {
return $this -> getArrayOfUsersResponded ( $this -> listGroupMembers ( $group ));
}
2022-11-04 12:39:54 +01:00
/**
2023-10-11 15:55:26 +05:45
* @When /^the user "([^"]*)" creates a new user with the following attributes using the Graph API:$/
2022-11-04 12:39:54 +01:00
*
* @param string $user
* @param TableNode $table
*
* @return void
* @throws Exception|GuzzleException
*/
public function theUserCreatesNewUser ( string $user , TableNode $table ) : void {
$rows = $table -> getRowsHash ();
$response = GraphHelper :: createUser (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$rows [ "userName" ],
$rows [ "password" ],
$rows [ "email" ],
2025-06-19 15:34:02 +05:45
$rows [ "displayName" ],
2022-11-04 12:39:54 +01:00
);
2025-02-17 18:44:30 +05:45
$this -> featureContext -> setResponse ( $response );
2022-11-04 12:39:54 +01:00
// add created user to list except for the user with an empty name
// because request /graph/v1.0/users/emptyUserName exits with 200
// and we cannot check that the user with empty name doesn't exist
2025-02-17 18:44:30 +05:45
if ( ! empty ( $rows [ "userName" ]) && $response -> getStatusCode () === 201 ) {
2022-11-04 12:39:54 +01:00
$this -> featureContext -> addUserToCreatedUsersList (
$rows [ "userName" ],
$rows [ "password" ],
$rows [ "displayName" ],
2025-06-19 15:34:02 +05:45
$rows [ "email" ],
2022-11-04 12:39:54 +01:00
);
}
}
2022-03-25 15:33:35 +05:45
/**
2022-04-06 20:16:33 +05:45
* adds a user to a group
2023-10-17 11:34:53 +05:45
* NOTE: If you want to make a request with non-existing user or group,provide "nonexistent" as their name
2022-03-25 15:33:35 +05:45
*
2022-11-23 16:18:04 +05:45
* @param string $group
* @param string $user
* @param string|null $byUser
*
* @return ResponseInterface
* @throws GuzzleException
*/
public function addUserToGroup ( string $group , string $user , ? string $byUser = null ) : ResponseInterface {
$credentials = $this -> getAdminOrUserCredentials ( $byUser );
2023-10-17 11:34:53 +05:45
if ( $group === "nonexistent" ) {
$groupId = WebDavHelper :: generateUUIDv4 ();
} else {
$groupId = $this -> featureContext -> getAttributeOfCreatedGroup ( $group , "id" );
}
if ( $user === "nonexistent" ) {
$userId = WebDavHelper :: generateUUIDv4 ();
} else {
$userId = $this -> featureContext -> getAttributeOfCreatedUser ( $user , "id" );
}
2026-09-14 15:49:35 +02:00
$requestUser = $credentials [ 'username' ];
$requestPass = $credentials [ 'password' ];
$headers = [];
if ( KeycloakHelper :: isTestingWithKeycloak ()) {
$access_token = $this -> featureContext -> getOcisUserToken ( $requestUser )[ "token" ][ "accessToken" ];
$headers [ 'Authorization' ] = 'Bearer ' . $access_token ;
$requestUser = null ;
$requestPass = null ;
}
2022-11-23 16:18:04 +05:45
return GraphHelper :: addUserToGroup (
$this -> featureContext -> getBaseUrl (),
2026-09-14 15:49:35 +02:00
$requestUser ,
$requestPass ,
2022-11-23 16:18:04 +05:45
$userId ,
2025-06-19 15:34:02 +05:45
$groupId ,
2026-09-14 15:49:35 +02:00
$headers ,
2022-11-23 16:18:04 +05:45
);
}
/**
2023-10-30 17:57:42 +05:45
* @Given /^the administrator has added a user "([^"]*)" to the group "([^"]*)" using the Graph API$/
2022-07-08 05:18:40 +02:00
*
2022-04-06 20:16:33 +05:45
* @param string $user
2022-04-06 20:48:29 +05:45
* @param string $group
2022-03-25 15:33:35 +05:45
*
* @return void
2022-04-06 20:16:33 +05:45
* @throws Exception
2022-03-25 15:33:35 +05:45
* @throws GuzzleException
*/
2022-04-06 20:16:33 +05:45
public function adminHasAddedUserToGroupUsingTheGraphApi (
string $user ,
2025-06-19 15:34:02 +05:45
string $group ,
2022-04-19 10:21:05 +05:45
) : void {
2023-10-17 11:34:53 +05:45
$response = $this -> addUserToGroup ( $group , $user );
$this -> featureContext -> theHTTPStatusCodeShouldBe ( 204 , '' , $response );
2022-03-25 15:33:35 +05:45
}
2022-11-23 16:18:04 +05:45
/**
* @When the administrator adds the following users to the following groups using the Graph API
*
* @param TableNode $table
*
* @return void
*/
public function theAdministratorAddsTheFollowingUsersToTheFollowingGroupsUsingTheGraphAPI ( TableNode $table ) : void {
$this -> featureContext -> verifyTableNodeColumns ( $table , [ 'username' , 'groupname' ]);
$userGroupList = $table -> getColumnsHash ();
foreach ( $userGroupList as $userGroup ) {
$this -> featureContext -> setResponse ( $this -> addUserToGroup ( $userGroup [ 'groupname' ], $userGroup [ 'username' ]));
$this -> featureContext -> pushToLastHttpStatusCodesArray ();
}
}
/**
2023-10-17 11:34:53 +05:45
* @When the administrator tries to add nonexistent user to group :group using the Graph API
2024-07-18 16:17:52 +05:45
* @When user :byUser tries to add nonexistent user to group :group using the Graph API
2022-11-23 16:18:04 +05:45
*
* @param string $group
2024-07-18 16:17:52 +05:45
* @param string|null $byUser
2022-11-23 16:18:04 +05:45
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function theAdministratorTriesToAddNonExistentUserToGroupUsingTheGraphAPI (
string $group ,
2025-06-19 15:34:02 +05:45
? string $byUser = null ,
2024-12-24 09:30:42 +05:45
) : void {
2024-07-18 16:17:52 +05:45
$this -> featureContext -> setResponse ( $this -> addUserToGroup ( $group , "nonexistent" , $byUser ));
2022-11-23 16:18:04 +05:45
}
2022-11-22 13:03:56 +05:45
2023-03-09 16:21:50 +05:45
/**
* @When the administrator tries to add user :user to a nonexistent group using the Graph API
2024-07-18 16:17:52 +05:45
* @When user :byUser tries to add user :user to a nonexistent group using the Graph API
2023-03-09 16:21:50 +05:45
*
* @param string $user
* @param string|null $byUser
*
* @return void
*
* @throws GuzzleException | Exception
*/
2024-12-24 09:30:42 +05:45
public function theAdministratorTriesToAddUserToNonExistentGroupUsingTheGraphAPI (
string $user ,
2025-06-19 15:34:02 +05:45
? string $byUser = null ,
2024-12-24 09:30:42 +05:45
) : void {
2023-10-17 11:34:53 +05:45
$this -> featureContext -> setResponse ( $this -> addUserToGroup ( "nonexistent" , $user , $byUser ));
2023-03-09 16:21:50 +05:45
}
2022-11-23 16:18:04 +05:45
/**
* @When user :user tries to add himself/herself to group :group using the Graph API
*
* @param string $user
* @param string $group
*
* @return void
*/
public function theUserTriesToAddHimselfToGroupUsingTheGraphAPI ( string $user , string $group ) : void {
$this -> featureContext -> setResponse ( $this -> addUserToGroup ( $group , $user , $user ));
}
/**
* @When user :byUser tries to add user :user to group :group using the Graph API
*
* @param string $byUser
* @param string $user
* @param string $group
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function theUserTriesToAddAnotherUserToGroupUsingTheGraphAPI (
string $byUser ,
string $user ,
2025-06-19 15:34:02 +05:45
string $group ,
2024-12-24 09:30:42 +05:45
) : void {
2024-11-25 16:59:11 +05:45
$this -> featureContext -> setResponse ( $this -> addUserToGroup ( $group , $user , $byUser ));
2022-11-23 16:18:04 +05:45
}
2022-08-19 17:16:12 +05:45
/**
*
* @param string $group
2022-11-11 09:31:13 +05:45
* @param ?string $user
2022-08-19 17:16:12 +05:45
*
2022-11-11 09:31:13 +05:45
* @return ResponseInterface
2022-08-19 17:16:12 +05:45
* @throws GuzzleException
*/
2022-11-11 09:31:13 +05:45
public function createGroup ( string $group , ? string $user = null ) : ResponseInterface {
2022-11-15 20:56:43 +05:45
$credentials = $this -> getAdminOrUserCredentials ( $user );
2026-09-14 15:49:35 +02:00
$requestUser = $credentials [ "username" ];
$requestPass = $credentials [ "password" ];
$headers = [];
if ( KeycloakHelper :: isTestingWithKeycloak ()) {
$access_token = $this -> featureContext -> getOcisUserToken ( $requestUser )[ "token" ][ "accessToken" ];
$headers [ 'Authorization' ] = 'Bearer ' . $access_token ;
$requestUser = null ;
$requestPass = null ;
}
2022-11-15 20:56:43 +05:45
2022-11-11 09:31:13 +05:45
return GraphHelper :: createGroup (
2022-08-19 17:16:12 +05:45
$this -> featureContext -> getBaseUrl (),
2026-09-14 15:49:35 +02:00
$requestUser ,
$requestPass ,
2022-08-19 17:16:12 +05:45
$group ,
2026-09-14 15:49:35 +02:00
$headers ,
2022-08-19 17:16:12 +05:45
);
2022-11-11 09:31:13 +05:45
}
/**
* @When /^the administrator creates a group "([^"]*)" using the Graph API$/
* @When user :user creates a group :group using the Graph API
* @When user :user tries to create a group :group using the Graph API
*
* @param string $group
* @param ?string $user
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
public function userCreatesGroupUsingTheGraphApi ( string $group , ? string $user = null ) : void {
$response = $this -> createGroup ( $group , $user );
2022-08-19 17:16:12 +05:45
$this -> featureContext -> setResponse ( $response );
$this -> featureContext -> pushToLastHttpStatusCodesArray (( string ) $response -> getStatusCode ());
2023-11-15 17:45:23 +01:00
if ( $response -> getStatusCode () === 201 ) {
2022-08-19 17:16:12 +05:45
$groupId = $this -> featureContext -> getJsonDecodedResponse ( $response )[ "id" ];
$this -> featureContext -> addGroupToCreatedGroupsList ( $group , true , true , $groupId );
}
}
2023-03-07 14:36:04 +05:45
/**
* @Given /^the administrator has created a group "([^"]*)" using the Graph API$/
* @Given user :user has created a group :group using the Graph API
*
* @param string $group
* @param ?string $user
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
public function userHasCreatedGroupUsingTheGraphApi ( string $group , ? string $user = null ) : void {
$response = $this -> createGroup ( $group , $user );
2023-11-15 17:45:23 +01:00
if ( $response -> getStatusCode () === 201 ) {
2023-03-07 14:36:04 +05:45
$groupId = $this -> featureContext -> getJsonDecodedResponse ( $response )[ "id" ];
$this -> featureContext -> addGroupToCreatedGroupsList ( $group , true , true , $groupId );
} else {
$this -> throwHttpException ( $response , "Could not create group ' $group '." );
}
}
2022-04-12 19:35:05 +05:45
/**
* @param ResponseInterface $response
* @param string $errorMsg
*
* @return void
* @throws Exception
*/
2022-04-19 10:21:05 +05:45
private function throwHttpException ( ResponseInterface $response , string $errorMsg ) : void {
2022-04-12 19:35:05 +05:45
try {
$jsonBody = $this -> featureContext -> getJsonDecodedResponse ( $response );
throw new Exception (
__METHOD__
. " \n $errorMsg "
. " \n HTTP status code: " . $response -> getStatusCode ()
. " \n Error code: " . $jsonBody [ "error" ][ "code" ]
2025-06-19 15:34:02 +05:45
. " \n Message: " . $jsonBody [ "error" ][ "message" ],
2022-04-12 19:35:05 +05:45
);
} catch ( TypeError $e ) {
throw new Exception (
__METHOD__
. " \n $errorMsg "
. " \n HTTP status code: " . $response -> getStatusCode ()
2025-06-19 15:34:02 +05:45
. " \n Response body: " . $response -> getBody (),
2022-04-12 19:35:05 +05:45
);
2022-03-25 15:33:35 +05:45
}
}
2022-04-13 12:53:20 +05:45
2022-04-19 10:21:05 +05:45
/**
* @param string $shouldOrNot (not|)
* @param TableNode $table
*
2022-09-06 12:32:56 +05:45
* @return void
2022-04-19 10:21:05 +05:45
* @throws GuzzleException
* @throws Exception
*/
public function theseGroupsShouldNotExist ( string $shouldOrNot , TableNode $table ) : void {
$should = ( $shouldOrNot !== "not" );
$this -> featureContext -> verifyTableNodeColumns ( $table , [ 'groupname' ]);
$actualGroupsList = $this -> adminHasRetrievedGroupListUsingTheGraphApi ();
$expectedGroups = $table -> getColumnsHash ();
// check if every expected group is(not) in the actual groups list
foreach ( $expectedGroups as $expectedGroup ) {
$groupName = $expectedGroup [ 'groupname' ];
$groupExists = false ;
foreach ( $actualGroupsList as $actualGroup ) {
if ( $actualGroup [ 'displayName' ] === $groupName ) {
$groupExists = true ;
break ;
}
}
if ( $groupExists !== $should ) {
throw new Exception (
__METHOD__
. " \n Group ' $groupName ' is expected " . ( $should ? "" : "not " )
2025-06-19 15:34:02 +05:45
. "to exist, but it does" . ( $should ? " not" : "" ) . " exist." ,
2022-04-19 10:21:05 +05:45
);
}
}
}
2022-08-31 13:02:33 +02:00
/**
* @When /^the user "([^"]*)" changes its own password "([^"]*)" to "([^"]*)" using the Graph API$/
2022-09-06 12:32:56 +05:45
*
2022-08-31 13:02:33 +02:00
* @param string $user
* @param string $currentPassword
* @param string $newPassword
*
2022-09-06 12:32:56 +05:45
* @return void
2022-08-31 13:02:33 +02:00
* @throws GuzzleException
* @throws Exception
*/
2022-11-04 12:39:54 +01:00
public function userChangesOwnPassword ( string $user , string $currentPassword , string $newPassword ) : void {
2022-08-31 13:02:33 +02:00
$response = GraphHelper :: changeOwnPassword (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$currentPassword ,
2025-06-19 15:34:02 +05:45
$newPassword ,
2022-08-31 13:02:33 +02:00
);
$this -> featureContext -> setResponse ( $response );
}
2022-11-15 20:56:43 +05:45
2026-08-05 11:46:39 +05:45
/**
* @When user :user tries to change their password to :new_password with patch request using the Graph API
*
* @param string $user
* @param string $newPassword
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
public function usertriesToChangesOwnPassword ( string $user , string $newPassword ) : void {
$response = GraphHelper :: updateUserPasswordUsingPatch (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$newPassword ,
);
$this -> featureContext -> setResponse ( $response );
}
2022-11-15 20:56:43 +05:45
/**
* @When user :user gets all the groups using the Graph API
*
* @param string $user
*
* @return void
*/
public function userGetsAllTheGroupsUsingTheGraphApi ( string $user ) : void {
$this -> featureContext -> setResponse ( $this -> listGroups ( $user ));
}
/**
* @When user :user gets all the members of group :group using the Graph API
*
* @param string $user
* @param string $group
*
* @return void
*/
2023-05-02 17:25:56 +05:45
public function userGetsAllTheMembersOfGroupUsingTheGraphApi ( string $user , string $group ) : void {
2022-11-15 20:56:43 +05:45
$this -> featureContext -> setResponse ( $this -> listGroupMembers ( $group , $user ));
}
2023-02-27 11:16:50 +05:45
/**
* @When user :user retrieves all groups along with their members using the Graph API
* @When user :user gets all the members information of group :group using the Graph API
*
* @param string $user
* @param string $group
*
* @return void
* @throws GuzzleException
*/
public function userRetrievesAllMemberInformationOfSingleOrAllGroups ( string $user , string $group = '' ) : void {
$this -> featureContext -> setResponse ( $this -> listSingleOrAllGroupsAlongWithAllMemberInformation ( $user , $group ));
}
2022-11-23 17:20:37 +05:45
/**
* @When user :user deletes group :group using the Graph API
* @When the administrator deletes group :group using the Graph API
* @When user :user tries to delete group :group using the Graph API
*
* @param string $group
* @param string|null $user
*
* @return void
*/
2023-01-10 12:03:52 +01:00
public function userDeletesGroupUsingTheGraphApi ( string $group , ? string $user = null ) : void {
2024-07-18 16:17:52 +05:45
$groupId = $this -> featureContext -> getAttributeOfCreatedGroup ( $group , "id" ) ?: $group ;
2024-04-18 17:28:38 +05:45
$response = $this -> deleteGroupWithId ( $groupId , $user );
if ( $response -> getStatusCode () === 204 ) {
$this -> featureContext -> rememberThatGroupIsNotExpectedToExist ( $group );
}
2022-11-23 17:20:37 +05:45
$this -> featureContext -> setResponse ( $response );
}
2022-11-22 13:03:56 +05:45
2022-11-23 16:18:04 +05:45
/**
* @Then the following users should be listed in the following groups
*
* @param TableNode $table
*
* @return void
* @throws Exception
*/
public function theFollowingUsersShouldBeListedInFollowingGroups ( TableNode $table ) : void {
$this -> featureContext -> verifyTableNodeColumns ( $table , [ 'username' , 'groupname' ]);
$usersGroups = $table -> getColumnsHash ();
foreach ( $usersGroups as $userGroup ) {
$members = $this -> listGroupMembers ( $userGroup [ 'groupname' ]);
$members = $this -> featureContext -> getJsonDecodedResponse ( $members );
$exists = false ;
foreach ( $members as $member ) {
if ( $member [ 'onPremisesSamAccountName' ] === $userGroup [ 'username' ]) {
$exists = true ;
break ;
}
}
Assert :: assertTrue (
$exists ,
__METHOD__
2024-12-24 09:30:42 +05:45
. " \n Expected user '" . $userGroup [ 'username' ] . "' to be in group '"
2025-06-19 15:34:02 +05:45
. $userGroup [ 'groupname' ] . "'. But not found." ,
2022-11-23 16:18:04 +05:45
);
}
}
2022-11-24 15:13:27 +05:45
/**
* rename group name
*
2023-03-28 09:09:37 +05:45
* @param string $oldGroupId
2022-11-24 15:13:27 +05:45
* @param string $newGroup
2023-05-02 17:25:56 +05:45
* @param string|null $user
2022-11-24 15:13:27 +05:45
*
* @return ResponseInterface
* @throws GuzzleException
*/
2023-03-28 09:09:37 +05:45
public function renameGroup ( string $oldGroupId , string $newGroup , ? string $user = null ) : ResponseInterface {
2022-11-24 15:13:27 +05:45
$credentials = $this -> getAdminOrUserCredentials ( $user );
return GraphHelper :: updateGroup (
$this -> featureContext -> getBaseUrl (),
$credentials [ 'username' ],
$credentials [ 'password' ],
2023-03-28 09:09:37 +05:45
$oldGroupId ,
2025-06-19 15:34:02 +05:45
$newGroup ,
2022-11-24 15:13:27 +05:45
);
}
/**
* @When user :user renames group :oldGroup to :newGroup using the Graph API
2023-03-28 09:09:37 +05:45
* @When user :user tries to rename group :oldGroup to :newGroup using the Graph API
2022-11-24 15:13:27 +05:45
*
* @param string $user
* @param string $oldGroup
* @param string $newGroup
*
* @return void
2023-03-28 09:09:37 +05:45
* @throws GuzzleException
2022-11-24 15:13:27 +05:45
*/
public function userRenamesGroupUsingTheGraphApi ( string $user , string $oldGroup , string $newGroup ) : void {
2023-03-28 09:09:37 +05:45
$oldGroupId = $this -> featureContext -> getAttributeOfCreatedGroup ( $oldGroup , "id" );
$this -> featureContext -> setResponse ( $this -> renameGroup ( $oldGroupId , $newGroup , $user ));
}
/**
* @When user :user tries to rename a nonexistent group to :newGroup using the Graph API
*
* @param string $user
* @param string $newGroup
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
public function userTriesToRenameNonExistentGroupToNewGroupName ( string $user , string $newGroup ) : void {
$oldGroupId = WebDavHelper :: generateUUIDv4 ();
$this -> featureContext -> setResponse ( $this -> renameGroup ( $oldGroupId , $newGroup , $user ));
2022-11-24 15:13:27 +05:45
}
2022-11-28 14:13:52 +05:45
/**
* @When the administrator removes the following users from the following groups using the Graph API
*
* @param TableNode $table
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function theAdministratorRemovesTheFollowingUsersFromTheFollowingGroupsUsingTheGraphApi (
2025-06-19 15:34:02 +05:45
TableNode $table ,
2024-12-24 09:30:42 +05:45
) : void {
2022-11-28 14:13:52 +05:45
$this -> featureContext -> verifyTableNodeColumns ( $table , [ 'username' , 'groupname' ]);
$usersGroups = $table -> getColumnsHash ();
foreach ( $usersGroups as $userGroup ) {
2024-12-24 09:30:42 +05:45
$this -> featureContext -> setResponse (
2025-06-19 15:34:02 +05:45
$this -> removeUserFromGroup ( $userGroup [ 'groupname' ], $userGroup [ 'username' ]),
2024-12-24 09:30:42 +05:45
);
2022-11-28 14:13:52 +05:45
$this -> featureContext -> pushToLastHttpStatusCodesArray ();
}
}
/**
* @When user :byUser tries to remove user :user from group :group using the Graph API
*
* @param string $user
* @param string $group
* @param string|null $byUser
*
* @return void
2023-03-09 16:21:50 +05:45
* @throws Exception | GuzzleException
2022-11-28 14:13:52 +05:45
*/
2024-12-24 09:30:42 +05:45
public function theUserTriesToRemoveAnotherUserFromGroupUsingTheGraphAPI (
string $user ,
string $group ,
2025-06-19 15:34:02 +05:45
? string $byUser = null ,
2024-12-24 09:30:42 +05:45
) : void {
2023-11-29 10:35:55 +05:45
$this -> featureContext -> setResponse ( $this -> removeUserFromGroup ( $group , $user , $byUser ));
2023-03-09 16:21:50 +05:45
}
/**
* @When the administrator tries to remove user :user from a nonexistent group using the Graph API
* @When user :byUser tries to remove user :user from a nonexistent group using the Graph API
*
* @param string $user
* @param string|null $byUser
*
* @return void
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function theUserTriesToRemoveAnotherUserFromNonExistentGroupUsingTheGraphAPI (
string $user ,
2025-06-19 15:34:02 +05:45
? string $byUser = null ,
2024-12-24 09:30:42 +05:45
) : void {
2023-11-29 10:35:55 +05:45
$this -> featureContext -> setResponse ( $this -> removeUserFromGroup ( '' , $user , $byUser ));
2022-11-28 14:13:52 +05:45
}
2022-11-22 13:03:56 +05:45
/**
* @param string $user
*
* @return ResponseInterface
* @throws JsonException
* @throws GuzzleException
*/
public function retrieveUserInformationUsingGraphApi (
2025-06-19 15:34:02 +05:45
string $user ,
2024-12-24 09:30:42 +05:45
) : ResponseInterface {
2022-11-22 13:03:56 +05:45
$credentials = $this -> getAdminOrUserCredentials ( $user );
2022-11-24 14:12:26 +05:45
return GraphHelper :: getOwnInformationAndGroupMemberships (
2022-11-22 13:03:56 +05:45
$this -> featureContext -> getBaseUrl (),
$credentials [ "username" ],
$credentials [ "password" ],
);
}
/**
2022-11-24 14:12:26 +05:45
* @When /^the user "([^"]*)" retrieves (her|his) information using the Graph API$/
2022-11-22 13:03:56 +05:45
*
* @param string $user
*
* @return void
* @throws JsonException
*/
2023-04-21 14:59:50 +05:45
public function userRetrievesHisOrHerInformationOfUserUsingGraphApi (
2025-06-19 15:34:02 +05:45
string $user ,
2024-12-24 09:30:42 +05:45
) : void {
2022-11-22 13:03:56 +05:45
$response = $this -> retrieveUserInformationUsingGraphApi ( $user );
$this -> featureContext -> setResponse ( $response );
}
2022-11-29 16:39:10 +05:45
/**
2022-12-19 11:34:25 +05:45
* @When user :byUser tries to get information of user :user using Graph API
* @When user :byUser gets information of user :user using Graph API
2022-11-29 16:39:10 +05:45
*
2022-12-19 11:34:25 +05:45
* @param string $byUser
2022-11-29 16:39:10 +05:45
* @param string $user
*
* @return void
2022-12-19 11:34:25 +05:45
* @throws GuzzleException
2022-11-29 16:39:10 +05:45
*/
2022-12-19 11:34:25 +05:45
public function userTriesToGetInformationOfUser ( string $byUser , string $user ) : void {
$credentials = $this -> getAdminOrUserCredentials ( $byUser );
2022-11-29 16:39:10 +05:45
$response = GraphHelper :: getUser (
$this -> featureContext -> getBaseUrl (),
$credentials [ 'username' ],
$credentials [ 'password' ],
2025-06-19 15:34:02 +05:45
$user ,
2022-11-29 16:39:10 +05:45
);
$this -> featureContext -> setResponse ( $response );
}
2024-01-18 15:14:10 +05:45
/**
* @When user :byUser tries to search for user :searchTerm using Graph API
* @When user :byUser searches for user :searchTerm using Graph API
*
* @param string $byUser
* @param string $searchTerm
*
* @return void
*/
public function userSearchesForUserUsingGraphApi ( string $byUser , string $searchTerm ) : void {
$credentials = $this -> getAdminOrUserCredentials ( $byUser );
$response = GraphHelper :: searchUser (
$this -> featureContext -> getBaseUrl (),
2024-08-13 12:09:09 +02:00
$credentials [ 'username' ],
$credentials [ 'password' ],
$searchTerm ,
);
$this -> featureContext -> setResponse ( $response );
}
/**
* @When user :byUser searches for federated user :searchTerm using Graph API
*
* @param string $byUser
* @param string $searchTerm
*
* @return void
* @throws GuzzleException
*/
public function userSearchesForFederatedUserUsingGraphApi ( string $byUser , string $searchTerm ) : void {
$credentials = $this -> getAdminOrUserCredentials ( $byUser );
$response = GraphHelper :: searchFederatedUser (
$this -> featureContext -> getBaseUrl (),
2024-01-18 15:14:10 +05:45
$credentials [ 'username' ],
$credentials [ 'password' ],
$searchTerm ,
);
$this -> featureContext -> setResponse ( $response );
}
2022-11-29 16:39:10 +05:45
/**
2022-12-19 11:34:25 +05:45
* @When user :user tries to get all users using the Graph API
* @When user :user gets all users using the Graph API
2022-11-29 16:39:10 +05:45
*
* @param string $user
*
* @return void
2022-12-19 11:34:25 +05:45
* @throws GuzzleException
2022-11-29 16:39:10 +05:45
*/
2025-04-07 16:55:33 +05:45
public function userGetsAllUserUsingTheGraphApi ( string $user ) : void {
2022-11-29 16:39:10 +05:45
$credentials = $this -> getAdminOrUserCredentials ( $user );
$response = GraphHelper :: getUsers (
$this -> featureContext -> getBaseUrl (),
$credentials [ 'username' ],
$credentials [ 'password' ],
);
$this -> featureContext -> setResponse ( $response );
}
/**
2022-12-19 11:34:25 +05:45
* @param string $byUser
* @param string|null $user
2022-11-29 16:39:10 +05:45
*
* @return ResponseInterface
* @throws JsonException
* @throws GuzzleException
*/
public function retrieveUserInformationAlongWithDriveUsingGraphApi (
2022-12-19 11:34:25 +05:45
string $byUser ,
2025-06-19 15:34:02 +05:45
? string $user = null ,
2024-12-24 09:30:42 +05:45
) : ResponseInterface {
2022-12-19 11:34:25 +05:45
$user = $user ?? $byUser ;
2022-11-29 16:39:10 +05:45
$credentials = $this -> getAdminOrUserCredentials ( $user );
return GraphHelper :: getUserWithDriveInformation (
$this -> featureContext -> getBaseUrl (),
$credentials [ "username" ],
$credentials [ "password" ],
2025-06-19 15:34:02 +05:45
$user ,
2022-11-29 16:39:10 +05:45
);
}
2023-02-01 08:41:16 +01:00
/**
* @param string $byUser
* @param string|null $user
*
* @return ResponseInterface
* @throws JsonException
* @throws GuzzleException
*/
public function retrieveUserInformationAlongWithGroupUsingGraphApi (
string $byUser ,
2025-06-19 15:34:02 +05:45
? string $user = null ,
2024-12-24 09:30:42 +05:45
) : ResponseInterface {
2023-02-01 08:41:16 +01:00
$user = $user ?? $byUser ;
$credentials = $this -> getAdminOrUserCredentials ( $user );
return GraphHelper :: getUserWithGroupInformation (
$this -> featureContext -> getBaseUrl (),
$credentials [ "username" ],
$credentials [ "password" ],
2025-06-19 15:34:02 +05:45
$user ,
2023-02-01 08:41:16 +01:00
);
}
2022-11-29 16:39:10 +05:45
/**
2022-12-19 11:34:25 +05:45
* @When /^the user "([^"]*)" gets user "([^"]*)" along with (his|her) drive information using Graph API$/
2022-11-29 16:39:10 +05:45
*
2022-12-19 11:34:25 +05:45
* @param string $byUser
2022-11-29 16:39:10 +05:45
* @param string $user
*
* @return void
*/
2025-04-07 16:55:33 +05:45
public function userTriesToGetInformationOfUserAlongWithHisDriveData ( string $byUser , string $user ) : void {
2022-12-19 11:34:25 +05:45
$response = $this -> retrieveUserInformationAlongWithDriveUsingGraphApi ( $byUser , $user );
2022-11-29 16:39:10 +05:45
$this -> featureContext -> setResponse ( $response );
}
2023-02-01 08:41:16 +01:00
/**
* @When /^the user "([^"]*)" gets user "([^"]*)" along with (his|her) group information using Graph API$/
*
* @param string $byUser
* @param string $user
*
* @return void
*/
2025-04-07 16:55:33 +05:45
public function userTriesToGetInformationOfUserAlongWithHisGroup ( string $byUser , string $user ) : void {
2023-02-01 08:41:16 +01:00
$response = $this -> retrieveUserInformationAlongWithGroupUsingGraphApi ( $byUser , $user );
$this -> featureContext -> setResponse ( $response );
}
2022-11-29 16:39:10 +05:45
/**
*
2022-12-19 11:34:25 +05:45
* @When /^the user "([^"]*)" gets (his|her) drive information using Graph API$/
2022-11-29 16:39:10 +05:45
*
* @param string $user
*
* @return void
*/
2025-06-19 12:15:41 +05:45
public function userTriesToGetOwnDriveInformation ( string $user ) : void {
2022-11-29 16:39:10 +05:45
$response = $this -> retrieveUserInformationAlongWithDriveUsingGraphApi ( $user );
$this -> featureContext -> setResponse ( $response );
}
2022-11-30 16:50:58 +05:45
2023-03-07 14:36:04 +05:45
/**
* add multiple users in a group at once
*
* @param string $user
* @param array $userIds
* @param string $groupId
*
2023-10-31 12:17:50 +05:45
* @return ResponseInterface
2023-03-07 14:36:04 +05:45
* @throws GuzzleException
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function addMultipleUsersToGroup (
string $user ,
array $userIds ,
2025-06-19 15:34:02 +05:45
string $groupId ,
2024-12-24 09:30:42 +05:45
) : ResponseInterface {
2023-03-07 14:36:04 +05:45
$credentials = $this -> getAdminOrUserCredentials ( $user );
2023-10-17 11:34:53 +05:45
return GraphHelper :: addUsersToGroup (
$this -> featureContext -> getBaseUrl (),
$credentials [ "username" ],
$credentials [ "password" ],
$groupId ,
2025-06-19 15:34:02 +05:45
$userIds ,
2023-03-07 14:36:04 +05:45
);
}
/**
* @When /^the administrator "([^"]*)" adds the following users to a group "([^"]*)" at once using the Graph API$/
*
* @param string $user
* @param string $group
* @param TableNode $table
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function theAdministratorAddsTheFollowingUsersToAGroupInASingleRequestUsingTheGraphApi (
string $user ,
string $group ,
2025-06-19 15:34:02 +05:45
TableNode $table ,
2024-12-24 09:30:42 +05:45
) : void {
2023-03-07 14:36:04 +05:45
$userIds = [];
$groupId = $this -> featureContext -> getAttributeOfCreatedGroup ( $group , "id" );
foreach ( $table -> getHash () as $row ) {
$userIds [] = $this -> featureContext -> getAttributeOfCreatedUser ( $row [ 'username' ], "id" );
}
2023-10-17 11:34:53 +05:45
$this -> featureContext -> verifyTableNodeColumns ( $table , [ 'username' ]);
$response = $this -> addMultipleUsersToGroup ( $user , $userIds , $groupId );
$this -> featureContext -> setResponse ( $response );
2023-03-07 14:36:04 +05:45
}
2023-03-27 15:47:55 +05:45
/**
* @When /^user "([^"]*)" tries to add the following users to a group "([^"]*)" at once with an invalid host using the Graph API$/
*
* @param string $user
* @param string $group
* @param TableNode $table
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function userTriesToAddTheFollowingUsersToAGroupAtOnceWithInvalidHostUsingTheGraphApi (
string $user ,
string $group ,
2025-06-19 15:34:02 +05:45
TableNode $table ,
2024-12-24 09:30:42 +05:45
) : void {
2023-03-27 15:47:55 +05:45
$userIds = [];
$groupId = $this -> featureContext -> getAttributeOfCreatedGroup ( $group , "id" );
$credentials = $this -> getAdminOrUserCredentials ( $user );
$this -> featureContext -> verifyTableNodeColumns ( $table , [ 'username' ]);
2023-03-31 08:59:25 +05:45
2023-03-27 15:47:55 +05:45
foreach ( $table -> getHash () as $row ) {
$userIds [] = $this -> featureContext -> getAttributeOfCreatedUser ( $row [ 'username' ], "id" );
}
$payload = [ "members@odata.bind" => [] ];
foreach ( $userIds as $userId ) {
$payload [ "members@odata.bind" ][] = GraphHelper :: getFullUrl ( 'https://invalid/' , 'users/' . $userId );
}
$this -> featureContext -> setResponse (
HttpRequestHelper :: sendRequest (
GraphHelper :: getFullUrl ( $this -> featureContext -> getBaseUrl (), 'groups/' . $groupId ),
'PATCH' ,
$credentials [ "username" ],
$credentials [ "password" ],
[ 'Content-Type' => 'application/json' ],
2025-06-19 15:34:02 +05:45
\json_encode ( $payload ),
),
2023-03-27 15:47:55 +05:45
);
}
/**
* @When /^user "([^"]*)" tries to add user "([^"]*)" to group "([^"]*)" with an invalid host using the Graph API$/
*
* @param string $adminUser
* @param string $user
* @param string $group
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function userTriesToAddUserToGroupWithInvalidHostUsingTheGraphApi (
string $adminUser ,
string $user ,
2025-06-19 15:34:02 +05:45
string $group ,
2024-12-24 09:30:42 +05:45
) : void {
2023-03-27 15:47:55 +05:45
$groupId = $this -> featureContext -> getAttributeOfCreatedGroup ( $group , "id" );
$userId = $this -> featureContext -> getAttributeOfCreatedUser ( $user , "id" );
$credentials = $this -> getAdminOrUserCredentials ( $adminUser );
$body = [
2025-06-19 10:46:56 +05:45
"@odata.id" => GraphHelper :: getFullUrl ( 'https://invalid/' , 'users/' . $userId ),
2023-03-27 15:47:55 +05:45
];
$this -> featureContext -> setResponse (
HttpRequestHelper :: post (
GraphHelper :: getFullUrl ( $this -> featureContext -> getBaseUrl (), 'groups/' . $groupId . '/members/$ref' ),
$credentials [ "username" ],
$credentials [ "password" ],
[ 'Content-Type' => 'application/json' ],
2025-06-19 15:34:02 +05:45
\json_encode ( $body ),
),
2023-03-27 15:47:55 +05:45
);
}
2023-03-07 14:36:04 +05:45
/**
2023-03-09 16:21:50 +05:45
* @When /^the administrator "([^"]*)" tries to add the following users to a nonexistent group at once using the Graph API$/
2023-03-07 14:36:04 +05:45
*
* @param string $user
* @param TableNode $table
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function theAdministratorTriesToAddsTheFollowingUsersToANonExistingGroupAtOnceUsingTheGraphApi (
string $user ,
2025-06-19 15:34:02 +05:45
TableNode $table ,
2024-12-24 09:30:42 +05:45
) : void {
2023-03-07 14:36:04 +05:45
$userIds = [];
$groupId = WebDavHelper :: generateUUIDv4 ();
foreach ( $table -> getHash () as $row ) {
$userIds [] = $this -> featureContext -> getAttributeOfCreatedUser ( $row [ 'username' ], "id" );
}
2023-10-17 11:34:53 +05:45
$this -> featureContext -> verifyTableNodeColumns ( $table , [ 'username' ]);
$response = $this -> addMultipleUsersToGroup ( $user , $userIds , $groupId );
$this -> featureContext -> setResponse ( $response );
2023-03-07 14:36:04 +05:45
}
/**
2023-03-09 16:21:50 +05:45
* @When /^the administrator "([^"]*)" tries to add the following nonexistent users to a group "([^"]*)" at once using the Graph API$/
2023-03-07 14:36:04 +05:45
*
* @param string $user
* @param string $group
* @param TableNode $table
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function theAdministratorTriesToAddTheFollowingNonExistingUsersToAGroupAtOnceUsingTheGraphApi (
string $user ,
string $group ,
2025-06-19 15:34:02 +05:45
TableNode $table ,
2024-12-24 09:30:42 +05:45
) : void {
2023-03-07 14:36:04 +05:45
$userIds = [];
$groupId = $this -> featureContext -> getAttributeOfCreatedGroup ( $group , "id" );
foreach ( $table -> getHash () as $row ) {
$userIds [] = WebDavHelper :: generateUUIDv4 ();
}
2023-10-17 11:34:53 +05:45
$this -> featureContext -> verifyTableNodeColumns ( $table , [ 'username' ]);
$response = $this -> addMultipleUsersToGroup ( $user , $userIds , $groupId );
$this -> featureContext -> setResponse ( $response );
2023-03-07 14:36:04 +05:45
}
/**
* @When /^the administrator "([^"]*)" tries to add the following users to a group "([^"]*)" at once using the Graph API$/
2023-03-09 16:21:50 +05:45
* @When /^the administrator "([^"]*)" tries to add the following existent and nonexistent users to a group "([^"]*)" at once using the Graph API$/
2023-03-07 14:36:04 +05:45
*
* @param string $user
* @param string $group
* @param TableNode $table
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function theAdministratorTriesToAddTheFollowingUsersToAGroupAtOnceUsingTheGraphApi (
string $user ,
string $group ,
2025-06-19 15:34:02 +05:45
TableNode $table ,
2024-12-24 09:30:42 +05:45
) : void {
2023-03-07 14:36:04 +05:45
$userIds = [];
$groupId = $this -> featureContext -> getAttributeOfCreatedGroup ( $group , "id" );
foreach ( $table -> getHash () as $row ) {
2023-03-09 16:21:50 +05:45
$userId = $this -> featureContext -> getAttributeOfCreatedUser ( $row [ 'username' ], "id" );
2023-05-02 17:25:56 +05:45
$userIds [] = $userId ?: WebDavHelper :: generateUUIDv4 ();
2023-03-07 14:36:04 +05:45
}
2023-10-17 11:34:53 +05:45
$this -> featureContext -> verifyTableNodeColumns ( $table , [ 'username' ]);
$response = $this -> addMultipleUsersToGroup ( $user , $userIds , $groupId );
$this -> featureContext -> setResponse ( $response );
2023-03-07 14:36:04 +05:45
}
2023-02-13 04:53:04 +01:00
/**
* @When user :user gets all applications using the Graph API
*
* @param string $user
*
* @return void
* @throws GuzzleException
*/
2025-06-19 12:15:41 +05:45
public function userGetsAllApplicationsUsingTheGraphApi ( string $user ) : void {
2023-02-13 04:53:04 +01:00
$response = GraphHelper :: getApplications (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
);
$this -> featureContext -> setResponse ( $response );
}
/**
2023-04-24 10:58:05 +05:45
* @Then the user API response should contain the following application information:
2023-02-13 04:53:04 +01:00
*
* @param TableNode $table
*
* @return void
*/
2023-04-24 10:58:05 +05:45
public function theResponseShouldContainTheFollowingApplicationInformation ( TableNode $table ) : void {
2024-12-24 09:30:42 +05:45
Assert :: assertIsArray (
$responseArray = (
$this -> featureContext -> getJsonDecodedResponse ( $this -> featureContext -> getResponse ())
2025-06-19 15:34:02 +05:45
)[ 'value' ][ 0 ],
2024-12-24 09:30:42 +05:45
);
2023-02-13 04:53:04 +01:00
foreach ( $table -> getHash () as $row ) {
$key = $row [ "key" ];
if ( $key === 'id' ) {
Assert :: assertTrue (
GraphHelper :: isUUIDv4 ( $responseArray [ $key ]),
2025-06-19 15:34:02 +05:45
__METHOD__ . ' Expected id to have UUIDv4 pattern but found: ' . $row [ "value" ],
2023-02-13 04:53:04 +01:00
);
} else {
Assert :: assertEquals ( $responseArray [ $key ], $row [ "value" ]);
}
}
}
/**
2023-04-24 10:58:05 +05:45
* @Then the user API response should contain the following app roles:
2023-02-13 04:53:04 +01:00
*
* @param TableNode $table
*
* @return void
*/
public function theResponseShouldContainTheFollowingAppRolesInformation ( TableNode $table ) : void {
2024-12-24 09:30:42 +05:45
Assert :: assertIsArray (
$responseArray = (
$this -> featureContext -> getJsonDecodedResponse ( $this -> featureContext -> getResponse ())
2025-06-19 15:34:02 +05:45
)[ 'value' ][ 0 ],
2024-12-24 09:30:42 +05:45
);
2023-02-13 04:53:04 +01:00
foreach ( $table -> getRows () as $row ) {
$foundRoleInResponse = false ;
foreach ( $responseArray [ 'appRoles' ] as $role ) {
if ( $role [ 'displayName' ] === $row [ 0 ]) {
$foundRoleInResponse = true ;
break ;
}
}
Assert :: assertTrue ( $foundRoleInResponse , "the response does not contain the role $row[0] " );
}
}
2023-02-16 16:34:13 +01:00
/**
* @When the user :user gets all users of the group :group using the Graph API
*
* @param string $user
* @param string $group
*
* @return void
* @throws GuzzleException
*/
2025-06-19 12:15:41 +05:45
public function userGetsAllUsersOfTheGroupUsingTheGraphApi ( string $user , string $group ) : void {
2023-02-16 16:34:13 +01:00
$groupId = $this -> featureContext -> getGroupIdByGroupName ( $group );
$response = GraphHelper :: getUsersWithFilterMemberOf (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
2025-06-19 15:34:02 +05:45
$groupId ,
2023-02-16 16:34:13 +01:00
);
$this -> featureContext -> setResponse ( $response );
}
/**
* @When the user :user gets all users of two groups :groups using the Graph API
*
* @param string $user
* @param string $groups
*
* @return void
* @throws GuzzleException
*/
2025-06-19 12:15:41 +05:45
public function userGetsAllUsersOfTwoGroupsUsingTheGraphApi ( string $user , string $groups ) : void {
2023-02-16 16:34:13 +01:00
$groupsIdArray = [];
foreach ( explode ( ',' , $groups ) as $group ) {
2023-05-02 17:25:56 +05:45
$groupsIdArray [] = $this -> featureContext -> getGroupIdByGroupName ( $group );
2023-02-16 16:34:13 +01:00
}
$response = GraphHelper :: getUsersOfTwoGroups (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
2025-06-19 15:34:02 +05:45
$groupsIdArray ,
2023-02-16 16:34:13 +01:00
);
$this -> featureContext -> setResponse ( $response );
}
2023-02-23 09:53:12 +01:00
2023-03-10 09:05:00 +01:00
/**
2023-04-17 17:05:12 +05:45
* @When the user :user gets all users that are members in the group :firstGroup or the group :secondGroup using the Graph API
2023-03-10 09:05:00 +01:00
*
* @param string $user
* @param string $firstGroup
* @param string $secondGroup
*
* @return void
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function userGetsAllUsersOfFirstGroupOderSecondGroupUsingTheGraphApi (
string $user ,
string $firstGroup ,
2025-06-19 15:34:02 +05:45
string $secondGroup ,
2025-06-19 12:15:41 +05:45
) : void {
2023-03-10 09:05:00 +01:00
$response = GraphHelper :: getUsersFromOneOrOtherGroup (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$firstGroup ,
2025-06-19 15:34:02 +05:45
$secondGroup ,
2023-03-10 09:05:00 +01:00
);
$this -> featureContext -> setResponse ( $response );
}
2023-02-23 09:53:12 +01:00
/**
* Get roleId by role name
*
* @param string $role
*
* @return string
* @throws GuzzleException
*/
public function getRoleIdByRoleName ( string $role ) : string {
$response = GraphHelper :: getApplications (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getAdminUsername (),
2025-06-19 15:34:02 +05:45
$this -> featureContext -> getAdminPassword (),
2023-02-23 09:53:12 +01:00
);
$responseData = \json_decode ( $response -> getBody () -> getContents (), true , 512 , JSON_THROW_ON_ERROR );
if ( isset ( $responseData [ "value" ][ 0 ][ "appRoles" ])) {
foreach ( $responseData [ "value" ][ 0 ][ "appRoles" ] as $value ) {
if ( $value [ "displayName" ] === $role ) {
return $value [ "id" ];
}
}
throw new Exception ( __METHOD__ . " role with name $role not found" );
}
}
/**
* @When the user :user gets all users with role :role using the Graph API
*
* @param string $user
* @param string $role
*
* @return void
* @throws GuzzleException
*/
2025-06-19 12:15:41 +05:45
public function userGetsAllUsersWithRoleUsingTheGraphApi ( string $user , string $role ) : void {
2023-02-23 09:53:12 +01:00
$response = GraphHelper :: getUsersWithFilterRoleAssignment (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
2025-06-19 15:34:02 +05:45
$this -> getRoleIdByRoleName ( $role ),
2023-02-23 09:53:12 +01:00
);
$this -> featureContext -> setResponse ( $response );
}
/**
* @When the user :user gets all users with role :role and member of the group :group using the Graph API
*
* @param string $user
* @param string $role
* @param string $group
*
* @return void
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function userGetsAllUsersWithRoleAndMemberOfGroupUsingTheGraphApi (
string $user ,
string $role ,
2025-06-19 15:34:02 +05:45
string $group ,
2025-06-19 12:15:41 +05:45
) : void {
2023-02-23 09:53:12 +01:00
$response = GraphHelper :: getUsersWithFilterRolesAssignmentAndMemberOf (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$this -> getRoleIdByRoleName ( $role ),
2025-06-19 15:34:02 +05:45
$this -> featureContext -> getGroupIdByGroupName ( $group ),
2023-02-23 09:53:12 +01:00
);
$this -> featureContext -> setResponse ( $response );
}
2023-02-20 09:49:05 +05:45
/**
* @Given /^the administrator has assigned the role "([^"]*)" to user "([^"]*)" using the Graph API$/
*
* @param string $role
* @param string $user
*
* @return void
*
* @throws GuzzleException
* @throws Exception
*/
public function theAdministratorHasGivenTheRoleUsingTheGraphApi ( string $role , string $user ) : void {
2026-07-14 10:53:02 +05:45
if ( KeycloakHelper :: isTestingWithKeycloak ()) {
2026-07-30 12:07:41 +05:45
$userAttribute = $this -> featureContext -> getCreatedKeycloakUsers ();
$userId = $userAttribute [ strtolower ( $user )][ 'id' ];
$currentRole = $userAttribute [ strtolower ( $user )][ 'role' ];
/*
* The oCIS API request for assigning roles allows only one role per user,
* whereas the Keycloak API request can assign multiple roles to a user.
* If multiple roles are assigned to a user in Keycloak,
* oCIS map the highest priority role among Keycloak assigned roles.
* Therefore, we need to unassign the previous role before
* assigning a new one when using the Keycloak API.
*/
$res = KeycloakHelper :: unassignRole ( $userId , $currentRole );
Assert :: assertEquals (
204 ,
$res -> getStatusCode (),
__METHOD__
. " \n Expected status code '204' but got '" . $res -> getStatusCode () . "'" ,
);
$response = KeycloakHelper :: assignRole ( $userId , $role );
2026-07-14 10:53:02 +05:45
Assert :: assertEquals (
204 ,
$response -> getStatusCode (),
__METHOD__
. " \n Expected status code '204' but got '" . $response -> getStatusCode () . "'" ,
);
} else {
2026-07-30 12:07:41 +05:45
$userId = $this -> featureContext -> getAttributeOfCreatedUser ( $user , 'id' ) ?: $user ;
2026-07-14 10:53:02 +05:45
if ( empty ( $this -> appEntity )) {
$this -> setApplicationEntity ();
}
2023-02-20 09:49:05 +05:45
2026-07-14 10:53:02 +05:45
$response = GraphHelper :: assignRole (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getAdminUsername (),
$this -> featureContext -> getAdminPassword (),
$this -> appEntity [ "appRoles" ][ $role ],
$this -> appEntity [ "id" ],
$userId ,
);
Assert :: assertEquals (
201 ,
$response -> getStatusCode (),
__METHOD__
. " \n Expected status code '200' but got '" . $response -> getStatusCode () . "'" ,
);
2023-02-20 09:49:05 +05:45
}
}
/**
* @When /^the administrator retrieves the assigned role of user "([^"]*)" using the Graph API$/
*
* @param string $user
*
* @return void
* @throws GuzzleException
*/
public function userRetrievesAssignedRoleUsingTheGraphApi ( string $user ) : void {
$admin = $this -> featureContext -> getAdminUserName ();
2024-07-18 16:17:52 +05:45
$userId = $this -> featureContext -> getAttributeOfCreatedUser ( $user , 'id' ) ?: $user ;
2023-02-20 09:49:05 +05:45
$this -> featureContext -> setResponse (
GraphHelper :: getAssignedRole (
$this -> featureContext -> getBaseUrl (),
$admin ,
$this -> featureContext -> getPasswordForUser ( $admin ),
2025-06-19 15:34:02 +05:45
$userId ,
),
2023-02-20 09:49:05 +05:45
);
}
2024-07-18 16:17:52 +05:45
/**
* @When /^user "([^"]*)" tries to get the assigned role of user "([^"]*)" using the Graph API$/
*
* @param string $user
* @param string $ofUser
*
* @return void
* @throws GuzzleException
*/
public function userTriesToGetAssignedRoleOfUserUsingTheGraphApi ( string $user , string $ofUser ) : void {
$credentials = $this -> getAdminOrUserCredentials ( $user );
$userId = $this -> featureContext -> getAttributeOfCreatedUser ( $ofUser , 'id' ) ?: $user ;
$this -> featureContext -> setResponse (
GraphHelper :: getAssignedRole (
$this -> featureContext -> getBaseUrl (),
$credentials [ 'username' ],
$credentials [ 'password' ],
2025-06-19 15:34:02 +05:45
$userId ,
),
2024-07-18 16:17:52 +05:45
);
}
2023-03-03 09:17:34 +05:45
/**
* set application Entity in global variable
*
* @return void
* @throws GuzzleException
*/
public function setApplicationEntity () : void {
$applicationEntity = (
$this -> featureContext -> getJsonDecodedResponse (
GraphHelper :: getApplications (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getAdminUsername (),
$this -> featureContext -> getAdminPassword (),
2025-06-19 15:34:02 +05:45
),
2023-03-03 09:17:34 +05:45
)
)[ 'value' ][ 0 ];
$this -> appEntity [ "id" ] = $applicationEntity [ "id" ];
foreach ( $applicationEntity [ "appRoles" ] as $value ) {
$this -> appEntity [ "appRoles" ][ $value [ 'displayName' ]] = $value [ 'id' ];
}
}
2023-02-20 09:49:05 +05:45
/**
* @Then /^the Graph API response should have the role "([^"]*)"$/
*
* @param string $role
*
* @return void
* @throws Exception
2023-03-03 09:17:34 +05:45
* @throws GuzzleException
2023-02-20 09:49:05 +05:45
*/
public function theGraphApiResponseShouldHaveTheRole ( string $role ) : void {
$response = $this -> featureContext -> getJsonDecodedResponse ( $this -> featureContext -> getResponse ())[ 'value' ][ 0 ];
2023-03-03 09:17:34 +05:45
if ( empty ( $this -> appEntity )) {
$this -> setApplicationEntity ();
}
2023-02-20 09:49:05 +05:45
Assert :: assertEquals (
$this -> appEntity [ "appRoles" ][ $role ],
$response [ 'appRoleId' ],
__METHOD__
2024-12-24 09:30:42 +05:45
. " \n Expected rolId for role ' $role '' to be '" . $this -> appEntity [ "appRoles" ][ $role ]
2025-06-19 15:34:02 +05:45
. "' but got '" . $response [ 'appRoleId' ] . "'" ,
2023-02-20 09:49:05 +05:45
);
}
2023-03-15 12:10:59 +05:45
2023-06-29 18:10:49 +02:00
/**
* @Then /^the Graph API response should have no role$/
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
public function theGraphApiResponseShouldHaveNoRole () : void {
Assert :: assertEmpty (
$this -> featureContext -> getJsonDecodedResponse ( $this -> featureContext -> getResponse ())[ 'value' ],
2025-06-19 15:34:02 +05:45
"the user has a role, but should not" ,
2023-06-29 18:10:49 +02:00
);
}
2023-03-15 12:10:59 +05:45
/**
* @When user :user gets details of the group :groupName using the Graph API
*
* @param string $user
* @param string $groupName
*
* @return void
*/
public function userGetsDetailsOfTheGroupUsingTheGraphApi ( string $user , string $groupName ) : void {
$credentials = $this -> getAdminOrUserCredentials ( $user );
$this -> featureContext -> setResponse (
GraphHelper :: getGroup (
$this -> featureContext -> getBaseUrl (),
$credentials [ "username" ],
$credentials [ "password" ],
2025-06-19 15:34:02 +05:45
$groupName ,
),
2023-03-15 12:10:59 +05:45
);
}
2023-03-15 13:58:04 +05:45
2024-01-18 15:14:10 +05:45
/**
* @When user :user tries to search for group :searchTerm using Graph API
* @When user :user searches for group :searchTerm using Graph API
*
* @param string $user
* @param string $searchTerm
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function userSearchesForGroupUsingGraphApi ( string $user , string $searchTerm ) : void {
2024-01-18 15:14:10 +05:45
$credentials = $this -> getAdminOrUserCredentials ( $user );
$this -> featureContext -> setResponse (
GraphHelper :: searchGroup (
$this -> featureContext -> getBaseUrl (),
$credentials [ "username" ],
$credentials [ "password" ],
2025-06-19 15:34:02 +05:45
$searchTerm ,
),
2024-01-18 15:14:10 +05:45
);
}
2023-04-05 14:05:34 +05:45
/**
* @Then /^the JSON data of the response should (not )?contain the user "([^"]*)" in the item 'value'(?:, the user-details should match)?$/
* @Then /^the JSON data of the response should (not )?contain the group "([^"]*)" in the item 'value'(?:, the group-details should match)?$/
*
* @param string $shouldOrNot (not| )
* @param string $userOrGroup
* @param PyStringNode|null $schemaString
*
* @return void
* @throws Exception
*/
public function theJsonDataResponseShouldOrNotContainUserOrGroupAndMatch (
string $shouldOrNot ,
string $userOrGroup ,
2025-06-19 15:34:02 +05:45
? PyStringNode $schemaString = null ,
2023-04-05 14:05:34 +05:45
) : void {
$responseBody = $this -> featureContext -> getJsonDecodedResponseBodyContent () -> value ;
$userOrGroupFound = false ;
foreach ( $responseBody as $value ) {
if ( isset ( $value -> displayName ) && $value -> displayName === $userOrGroup ) {
$responseBody = $value ;
$userOrGroupFound = true ;
break ;
}
}
$shouldContain = \trim ( $shouldOrNot ) !== 'not' ;
if ( ! $shouldContain && ! $userOrGroupFound ) {
return ;
}
Assert :: assertFalse (
! $shouldContain && $userOrGroupFound ,
2025-06-19 15:34:02 +05:45
'Response contains user or group "' . $userOrGroup . '" but should not have.' ,
2023-04-05 14:05:34 +05:45
);
2023-06-02 14:36:05 +05:45
$this -> featureContext -> assertJsonDocumentMatchesSchema (
2023-04-05 14:05:34 +05:45
$responseBody ,
2025-06-19 15:34:02 +05:45
$this -> featureContext -> getJSONSchema ( $schemaString ),
2023-04-05 14:05:34 +05:45
);
}
2023-03-15 13:58:04 +05:45
/**
* @Given /^the administrator "([^"]*)" has added the following users to a group "([^"]*)" at once using the Graph API$/
*
* @param string $user
* @param string $group
* @param TableNode $table
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function theAdministratorHasAddedTheFollowingUsersToAGroupAtOnceUsingTheGraphApi (
string $user ,
string $group ,
2025-06-19 15:34:02 +05:45
TableNode $table ,
2025-06-19 12:15:41 +05:45
) : void {
2023-03-15 13:58:04 +05:45
$userIds = [];
$groupId = $this -> featureContext -> getAttributeOfCreatedGroup ( $group , "id" );
foreach ( $table -> getHash () as $row ) {
$userIds [] = $this -> featureContext -> getAttributeOfCreatedUser ( $row [ 'username' ], "id" );
}
2023-10-17 11:34:53 +05:45
$this -> featureContext -> verifyTableNodeColumns ( $table , [ 'username' ]);
$response = $this -> addMultipleUsersToGroup ( $user , $userIds , $groupId );
$this -> featureContext -> theHTTPStatusCodeShouldBe ( 204 , '' , $response );
2023-03-15 13:58:04 +05:45
}
/**
2023-04-17 16:05:35 +05:45
* @When /^the administrator "([^"]*)" tries to add a group "([^"]*)" to another group "([^"]*)" with PATCH request using the Graph API$/
2023-03-15 13:58:04 +05:45
*
* @param string $user
* @param string $groupToAdd
* @param string $group
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function theAdministratorTriesToAddGroupToAGroupAtOnceUsingTheGraphApi (
string $user ,
string $groupToAdd ,
2025-06-19 15:34:02 +05:45
string $group ,
2025-06-19 12:15:41 +05:45
) : void {
2023-03-15 13:58:04 +05:45
$groupId = $this -> featureContext -> getAttributeOfCreatedGroup ( $group , "id" );
$groupIdToAdd = $this -> featureContext -> getAttributeOfCreatedGroup ( $groupToAdd , "id" );
$credentials = $this -> getAdminOrUserCredentials ( $user );
2023-04-17 16:05:35 +05:45
$payload = [
2024-12-24 09:30:42 +05:45
"members@odata.bind" => [
2025-06-19 10:46:56 +05:45
GraphHelper :: getFullUrl ( $this -> featureContext -> getBaseUrl (), 'groups/' . $groupIdToAdd )],
2023-04-17 16:05:35 +05:45
];
2023-03-15 13:58:04 +05:45
$this -> featureContext -> setResponse (
2023-04-17 16:05:35 +05:45
HttpRequestHelper :: sendRequest (
GraphHelper :: getFullUrl ( $this -> featureContext -> getBaseUrl (), 'groups/' . $groupId ),
'PATCH' ,
2023-03-15 13:58:04 +05:45
$credentials [ "username" ],
$credentials [ "password" ],
2023-04-17 16:05:35 +05:45
[ 'Content-Type' => 'application/json' ],
2025-06-19 15:34:02 +05:45
\json_encode ( $payload ),
),
2023-04-17 16:05:35 +05:45
);
}
/**
* @When /^the administrator "([^"]*)" tries to add a group "([^"]*)" to another group "([^"]*)" with POST request using the Graph API$/
*
* @param string $user
* @param string $groupToAdd
* @param string $group
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function theAdministratorTriesToAddAGroupToAGroupThroughPostRequestUsingTheGraphApi (
string $user ,
string $groupToAdd ,
2025-06-19 15:34:02 +05:45
string $group ,
2025-06-19 12:15:41 +05:45
) : void {
2023-04-17 16:05:35 +05:45
$groupId = $this -> featureContext -> getAttributeOfCreatedGroup ( $group , "id" );
$groupIdToAdd = $this -> featureContext -> getAttributeOfCreatedGroup ( $groupToAdd , "id" );
$credentials = $this -> getAdminOrUserCredentials ( $user );
$payload = [
2025-06-19 10:46:56 +05:45
"@odata.id" => GraphHelper :: getFullUrl ( $this -> featureContext -> getBaseUrl (), 'groups/' . $groupIdToAdd ),
2023-04-17 16:05:35 +05:45
];
$this -> featureContext -> setResponse (
HttpRequestHelper :: post (
GraphHelper :: getFullUrl ( $this -> featureContext -> getBaseUrl (), 'groups/' . $groupId . '/members/$ref' ),
$credentials [ "username" ],
$credentials [ "password" ],
[ 'Content-Type' => 'application/json' ],
2025-06-19 15:34:02 +05:45
\json_encode ( $payload ),
),
2023-03-15 13:58:04 +05:45
);
}
2023-03-27 10:41:21 +05:45
/**
* @When /^user "([^"]*)" tries to add user "([^"]*)" to group "([^"]*)" with invalid JSON "([^"]*)" using the Graph API$/
*
* @param string $adminUser
* @param string $user
* @param string $group
* @param string $invalidJSON
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function userTriesToAddUserToGroupWithInvalidJsonUsingTheGraphApi (
string $adminUser ,
string $user ,
string $group ,
2025-06-19 15:34:02 +05:45
string $invalidJSON ,
2024-12-24 09:30:42 +05:45
) : void {
2023-03-27 10:41:21 +05:45
$groupId = $this -> featureContext -> getAttributeOfCreatedGroup ( $group , "id" );
$credentials = $this -> getAdminOrUserCredentials ( $adminUser );
$invalidJSON = $this -> featureContext -> substituteInLineCodes (
$invalidJSON ,
null ,
[],
[],
null ,
2025-06-19 15:34:02 +05:45
$user ,
2023-03-27 10:41:21 +05:45
);
$this -> featureContext -> setResponse (
HttpRequestHelper :: post (
GraphHelper :: getFullUrl ( $this -> featureContext -> getBaseUrl (), 'groups/' . $groupId . '/members/$ref' ),
$credentials [ "username" ],
$credentials [ "password" ],
[ 'Content-Type' => 'application/json' ],
2025-06-19 15:34:02 +05:45
\json_encode ( $invalidJSON ),
),
2023-03-27 10:41:21 +05:45
);
}
/**
* @When /^user "([^"]*)" tries to add the following users to a group "([^"]*)" at once with invalid JSON "([^"]*)" using the Graph API$/
*
* @param string $user
* @param string $group
* @param string $invalidJSON
* @param TableNode $table
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function userTriesToAddTheFollowingUsersToAGroupAtOnceWithInvalidJsonUsingTheGraphApi (
string $user ,
string $group ,
string $invalidJSON ,
2025-06-19 15:34:02 +05:45
TableNode $table ,
2024-12-24 09:30:42 +05:45
) : void {
2023-03-27 10:41:21 +05:45
$groupId = $this -> featureContext -> getAttributeOfCreatedGroup ( $group , "id" );
$credentials = $this -> getAdminOrUserCredentials ( $user );
foreach ( $table -> getHash () as $row ) {
$invalidJSON = $this -> featureContext -> substituteInLineCodes (
$invalidJSON ,
null ,
[],
[],
null ,
2025-06-19 15:34:02 +05:45
$row [ 'username' ],
2023-03-27 10:41:21 +05:45
);
}
$this -> featureContext -> setResponse (
HttpRequestHelper :: sendRequest (
GraphHelper :: getFullUrl ( $this -> featureContext -> getBaseUrl (), 'groups/' . $groupId ),
'PATCH' ,
$credentials [ "username" ],
$credentials [ "password" ],
[ 'Content-Type' => 'application/json' ],
2025-06-19 15:34:02 +05:45
\json_encode ( $invalidJSON ),
),
2023-03-27 10:41:21 +05:45
);
}
2023-03-31 08:59:25 +05:45
/**
* @When /^the administrator "([^"]*)" tries to add the following invalid user ids to a group "([^"]*)" at once using the Graph API$/
*
* @param string $user
* @param string $group
* @param TableNode $table
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function theAdministratorTriesToAddTheFollowingUserIdWithInvalidCharacterToAGroup (
string $user ,
string $group ,
2025-06-19 15:34:02 +05:45
TableNode $table ,
2025-06-19 12:15:41 +05:45
) : void {
2023-03-31 08:59:25 +05:45
$userIds = [];
$credentials = $this -> getAdminOrUserCredentials ( $user );
$groupId = $this -> featureContext -> getAttributeOfCreatedGroup ( $group , "id" );
foreach ( $table -> getHash () as $row ) {
$userIds [] = \implode ( " " , $row );
}
$this -> featureContext -> setResponse (
GraphHelper :: addUsersToGroup (
$this -> featureContext -> getBaseUrl (),
$credentials [ "username" ],
$credentials [ "password" ],
$groupId ,
2025-06-19 15:34:02 +05:45
$userIds ,
),
2023-03-31 08:59:25 +05:45
);
}
/**
* @When /^the administrator "([^"]*)" tries to add an invalid user id "([^"]*)" to a group "([^"]*)" using the Graph API$/
*
* @param string $user
* @param string $userId
* @param string $group
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function theAdministratorTriesToAddUserIdWithInvalidCharactersToAGroup (
string $user ,
string $userId ,
2025-06-19 15:34:02 +05:45
string $group ,
2024-12-24 09:30:42 +05:45
) : void {
2023-03-31 08:59:25 +05:45
$credentials = $this -> getAdminOrUserCredentials ( $user );
$groupId = $this -> featureContext -> getAttributeOfCreatedGroup ( $group , "id" );
$this -> featureContext -> setResponse (
GraphHelper :: addUserToGroup (
$this -> featureContext -> getBaseUrl (),
$credentials [ 'username' ],
$credentials [ 'password' ],
$userId ,
2025-06-19 15:34:02 +05:45
$groupId ,
),
2023-03-31 08:59:25 +05:45
);
}
/**
* @Then the user :user should be listed once in the group :group
*
* @param string $user
* @param string $group
*
* @return void
* @throws GuzzleException
*/
public function theUsersShouldBeListedOnceToAGroup ( string $user , string $group ) : void {
$count = 0 ;
$members = $this -> listGroupMembers ( $group );
$members = $this -> featureContext -> getJsonDecodedResponse ( $members );
foreach ( $members as $member ) {
if ( $member [ 'onPremisesSamAccountName' ] === $user ) {
$count ++ ;
}
}
Assert :: assertEquals (
1 ,
$count ,
2024-12-24 09:30:42 +05:45
"Expected user '" . $user . "' to be added once to group '"
2025-06-19 15:34:02 +05:45
. $group . "' but the user is listed '" . $count . "' times" ,
2023-03-31 08:59:25 +05:45
);
}
2023-04-21 16:59:16 +05:45
/**
* @When /^user "([^"]*)" gets the personal drive information of user "([^"]*)" using Graph API$/
* @When /^user "([^"]*)" gets own personal drive information using Graph API$/
*
* @param string $byUser
* @param string|null $user
*
* @return void
*/
public function userGetsThePersonalDriveInformationOfUserUsingGraphApi ( string $byUser , ? string $user = null ) : void {
$user = $user ?? $byUser ;
$credentials = $this -> getAdminOrUserCredentials ( $byUser );
$userId = $this -> featureContext -> getAttributeOfCreatedUser ( $user , 'id' );
$this -> featureContext -> setResponse (
GraphHelper :: getPersonalDriveInformationByUserId (
$this -> featureContext -> getBaseUrl (),
$credentials [ "username" ],
$credentials [ "password" ],
2025-06-19 15:34:02 +05:45
$userId ,
),
2023-04-21 16:59:16 +05:45
);
}
2023-04-27 16:04:17 +05:45
/**
* @When /^user "([^"]*)" exports (?:her|his) GDPR report to "([^"]*)" using the Graph API$/
*
* @param string $user
* @param string $path
*
* @return void
* @throws GuzzleException
*/
public function userGeneratesGDPRReportOfOwnDataToPath ( string $user , string $path ) : void {
$credentials = $this -> getAdminOrUserCredentials ( $user );
$userId = $this -> featureContext -> getAttributeOfCreatedUser ( $user , 'id' );
$this -> featureContext -> setResponse (
GraphHelper :: generateGDPRReport (
$this -> featureContext -> getBaseUrl (),
$credentials [ 'username' ],
$credentials [ 'password' ],
$userId ,
2025-06-19 15:34:02 +05:45
$path ,
),
2023-04-27 16:04:17 +05:45
);
$this -> featureContext -> pushToLastStatusCodesArrays ();
}
/**
* @Then the downloaded JSON content should contain event type :eventType in item 'events' and should match
2023-05-28 22:27:39 -07:00
* @Then the downloaded JSON content should contain event type :eventType for :spaceType space and should match
2023-04-27 16:04:17 +05:45
*
* @param string $eventType
2023-05-28 22:27:39 -07:00
* @param string|null $spaceType
* @param PyStringNode|null $schemaString
2023-04-27 16:04:17 +05:45
*
* @return void
2024-04-26 15:27:00 +05:45
* @throws Exception
2023-04-27 16:04:17 +05:45
*
*/
2024-12-24 09:30:42 +05:45
public function downloadedJsonContentShouldContainEventTypeInItemAndShouldMatch (
string $eventType ,
2025-06-19 12:12:17 +05:45
? string $spaceType = null ,
2025-06-24 11:39:50 +02:00
? PyStringNode $schemaString = null ,
2024-12-24 09:30:42 +05:45
) : void {
2023-04-27 16:04:17 +05:45
$actualResponseToAssert = null ;
$events = $this -> featureContext -> getJsonDecodedResponseBodyContent () -> events ;
foreach ( $events as $event ) {
if ( $event -> type === $eventType ) {
2023-05-28 22:27:39 -07:00
if ( $spaceType !== null ) {
if ( $event -> event -> Type === $spaceType ) {
$actualResponseToAssert = $event ;
break ;
}
continue ;
}
2023-04-27 16:04:17 +05:45
$actualResponseToAssert = $event ;
break ;
}
}
if ( $actualResponseToAssert === null ) {
throw new Error (
2025-06-19 15:34:02 +05:45
"Response does not contain event type '" . $eventType . "'." ,
2023-04-27 16:04:17 +05:45
);
}
2023-06-02 14:36:05 +05:45
$this -> featureContext -> assertJsonDocumentMatchesSchema (
2023-04-27 16:04:17 +05:45
$actualResponseToAssert ,
2025-06-19 15:34:02 +05:45
$this -> featureContext -> getJSONSchema ( $schemaString ),
2023-04-27 16:04:17 +05:45
);
}
/**
* @Then the downloaded JSON content should contain key 'user' and match
*
* @param PyStringNode $schemaString
*
* @return void
* @throws GuzzleException
*
*/
public function downloadedJsonContentShouldContainKeyUserAndMatch ( PyStringNode $schemaString ) : void {
$actualResponseToAssert = $this -> featureContext -> getJsonDecodedResponseBodyContent ();
if ( ! isset ( $actualResponseToAssert -> user )) {
throw new Error (
2025-06-19 15:34:02 +05:45
"Response does not contain key 'user'" ,
2023-04-27 16:04:17 +05:45
);
}
2023-06-02 14:36:05 +05:45
$this -> featureContext -> assertJsonDocumentMatchesSchema (
2023-04-27 16:04:17 +05:45
$actualResponseToAssert -> user ,
2025-06-19 15:34:02 +05:45
$this -> featureContext -> getJSONSchema ( $schemaString ),
2023-04-27 16:04:17 +05:45
);
}
2023-05-10 11:37:13 +05:45
/**
* @When user :user tries to export GDPR report of user :ofUser to :path using Graph API
*
* @param string $user
* @param string $ofUser
* @param string $path
*
* @return void
*
*/
2024-12-24 09:30:42 +05:45
public function userTriesToExportGdprReportOfAnotherUserUsingGraphApi (
string $user ,
string $ofUser ,
2025-06-19 15:34:02 +05:45
string $path ,
2024-12-24 09:30:42 +05:45
) : void {
2023-05-10 11:37:13 +05:45
$credentials = $this -> getAdminOrUserCredentials ( $user );
$this -> featureContext -> setResponse (
GraphHelper :: generateGDPRReport (
$this -> featureContext -> getBaseUrl (),
$credentials [ 'username' ],
$credentials [ 'password' ],
$this -> featureContext -> getAttributeOfCreatedUser ( $ofUser , 'id' ),
2025-06-19 15:34:02 +05:45
$path ,
),
2023-05-10 11:37:13 +05:45
);
}
2023-05-15 14:30:24 +05:45
/**
2023-06-28 10:56:08 +05:45
* @param string $user
*
* @return ResponseInterface
* @throws GuzzleException
*/
2024-04-26 15:27:00 +05:45
public function getAssignedRole ( string $user ) : ResponseInterface {
2024-12-24 09:30:42 +05:45
$userId = $this -> featureContext -> getAttributeOfCreatedUser ( $user , 'id' )
?: $this -> featureContext -> getUserIdByUserName ( $user );
2023-06-28 10:56:08 +05:45
return (
GraphHelper :: getAssignedRole (
$this -> featureContext -> getBAseUrl (),
$this -> featureContext -> getAdminUsername (),
$this -> featureContext -> getAdminPassword (),
2025-06-19 15:34:02 +05:45
$userId ,
2023-06-28 10:56:08 +05:45
)
);
}
/**
* @When /^user "([^"]*)" (?:unassigns|tries to unassign) the role of user "([^"]*)" using the Graph API$/
2023-05-15 14:30:24 +05:45
*
* @param string $user
* @param string $ofUser
*
* @return void
*
* @throws GuzzleException
* @throws Exception
*/
public function theUserUnassignsTheRoleOfUserUsingTheGraphApi ( string $user , string $ofUser ) : void {
$credentials = $this -> getAdminOrUserCredentials ( $user );
2024-07-18 16:17:52 +05:45
$userId = $this -> featureContext -> getAttributeOfCreatedUser ( $ofUser , 'id' );
// get 'User' role id for nonexistent user
if ( ! $userId && $ofUser !== $this -> featureContext -> getAdminUsername ()) {
$appRoleAssignmentId = $this -> getRoleIdByRoleName ( "User" );
} else {
2024-12-24 09:30:42 +05:45
$appRoleAssignmentId = $this -> featureContext -> getJsonDecodedResponse (
2025-06-19 15:34:02 +05:45
$this -> getAssignedRole ( $ofUser ),
2024-12-24 09:30:42 +05:45
)[ "value" ][ 0 ][ "id" ];
2024-07-18 16:17:52 +05:45
}
$userId = $userId ?: $ofUser ;
2023-05-15 14:30:24 +05:45
$this -> featureContext -> setResponse (
GraphHelper :: unassignRole (
$this -> featureContext -> getBaseUrl (),
$credentials [ 'username' ],
$credentials [ 'password' ],
$appRoleAssignmentId ,
2025-06-19 15:34:02 +05:45
$userId ,
),
2023-05-15 14:30:24 +05:45
);
}
/**
* @Then user :user should have the role :role assigned
*
* @param string $user
* @param string $role
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
public function userShouldHaveTheRoleAssigned ( string $user , string $role ) : void {
2023-06-28 10:56:08 +05:45
$jsonDecodedResponse = $this -> featureContext -> getJsonDecodedResponse ( $this -> getAssignedRole ( $user ))[ 'value' ][ 0 ];
2023-05-15 14:30:24 +05:45
if ( empty ( $this -> appEntity )) {
$this -> setApplicationEntity ();
}
Assert :: assertEquals (
$this -> appEntity [ "appRoles" ][ $role ],
$jsonDecodedResponse [ 'appRoleId' ],
__METHOD__
. " \n Expected user ' $user ' to have role ' $role ' with role id '" . $this -> appEntity [ "appRoles" ][ $role ] .
2025-06-19 15:34:02 +05:45
"' but got the role id is '" . $jsonDecodedResponse [ 'appRoleId' ] . "'" ,
2023-05-15 14:30:24 +05:45
);
}
/**
* @Then user :user should not have any role assigned
*
* @param string $user
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
public function userShouldNotHaveAnyRoleAssigned ( string $user ) : void {
2023-06-28 10:56:08 +05:45
$jsonDecodedResponse = $this -> featureContext -> getJsonDecodedResponse ( $this -> getAssignedRole ( $user ))[ 'value' ];
2023-05-15 14:30:24 +05:45
Assert :: assertEmpty (
$jsonDecodedResponse ,
__METHOD__
2025-06-19 15:34:02 +05:45
. " \n Expected user ' $user ' to have no roles assigned but got '" . json_encode ( $jsonDecodedResponse ) . "'" ,
2023-05-15 14:30:24 +05:45
);
}
2023-05-22 16:05:54 +05:45
/**
* @When user :user changes the role of user :ofUser to role :role using the Graph API
* @When user :user tries to change the role of user :ofUser to role :role using the Graph API
*
* @param string $user
* @param string $ofUser
* @param string $role
*
* @return void
*
* @throws GuzzleException
* @throws Exception
*/
public function userChangesTheRoleOfUserToRoleUsingTheGraphApi ( string $user , string $ofUser , string $role ) : void {
2024-07-18 16:17:52 +05:45
$userId = $this -> featureContext -> getAttributeOfCreatedUser ( $ofUser , 'id' ) ?: $ofUser ;
2023-05-22 16:05:54 +05:45
$credentials = $this -> getAdminOrUserCredentials ( $user );
if ( empty ( $this -> appEntity )) {
$this -> setApplicationEntity ();
}
$this -> featureContext -> setResponse (
GraphHelper :: assignRole (
$this -> featureContext -> getBaseUrl (),
$credentials [ 'username' ],
$credentials [ 'password' ],
$this -> appEntity [ "appRoles" ][ $role ],
$this -> appEntity [ "id" ],
2025-06-19 15:34:02 +05:45
$userId ,
),
2023-05-22 16:05:54 +05:45
);
}
2023-11-28 15:33:17 +05:45
/**
* @Given user :user has switched the system language to :language using the Graph API
*
* @param string $user
* @param string $language
*
* @return void
* @throws GuzzleException
*/
public function userHasSwitchedTheSystemLanguageUsingGraphApi ( string $user , string $language ) : void {
$credentials = $this -> getAdminOrUserCredentials ( $user );
2025-06-19 12:12:17 +05:45
$response = GraphHelper :: switchSystemLanguage (
2023-11-28 15:33:17 +05:45
$this -> featureContext -> getBaseUrl (),
$credentials [ 'username' ],
$credentials [ 'password' ],
2025-06-19 15:34:02 +05:45
$language ,
2023-11-28 15:33:17 +05:45
);
$this -> featureContext -> theHTTPStatusCodeShouldBe (
200 ,
"Expected response status code should be 200" ,
2025-06-19 15:34:02 +05:45
$response ,
2023-11-28 15:33:17 +05:45
);
}
/**
* @When user :user switches the system language to :language using the Graph API
*
* @param string $user
* @param string $language
*
* @return void
* @throws GuzzleException
*/
public function userSwitchesTheSystemLanguageUsingGraphApi ( string $user , string $language ) : void {
$credentials = $this -> getAdminOrUserCredentials ( $user );
$this -> featureContext -> setResponse (
GraphHelper :: switchSystemLanguage (
$this -> featureContext -> getBaseUrl (),
$credentials [ 'username' ],
$credentials [ 'password' ],
2025-06-19 15:34:02 +05:45
$language ,
),
2023-11-28 15:33:17 +05:45
);
}
2024-01-25 09:47:56 +05:45
/**
2024-09-24 15:59:10 +02:00
* @When /^user "([^"]*)" lists the shares shared with (?:him|her)(| after clearing user cache)(| without retry) using the Graph API$/
2024-01-25 09:47:56 +05:45
*
* @param string $user
2024-03-01 15:36:51 +05:45
* @param string $cacheStepString
2024-09-24 15:59:10 +02:00
* @param string $retryOption
2024-01-25 09:47:56 +05:45
*
* @return void
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function userListsTheResourcesSharedWithThemUsingGraphApi (
string $user ,
string $cacheStepString ,
2025-06-19 15:34:02 +05:45
string $retryOption ,
2024-12-24 09:30:42 +05:45
) : void {
2024-03-01 15:36:51 +05:45
if ( $cacheStepString !== '' ) {
// ENV (GRAPH_SPACES_GROUPS_CACHE_TTL | GRAPH_SPACES_USERS_CACHE_TTL) is set default to 60 sec
// which means 60 sec is required to clean up all the user|group cache once they are deleted
// for tests we have set the above ENV's to minimum which is 1 sec as we check the details for the deleted users
sleep ( 1 );
}
2024-01-25 09:47:56 +05:45
$credentials = $this -> getAdminOrUserCredentials ( $user );
2024-04-25 12:15:08 +05:45
// Sometimes listing shares might not return the updated shares list
// so try again until @client.synchronize is true for the max. number of retries (i.e. 10)
// and do not retry when the share is expected to be not synced
2024-09-24 15:59:10 +02:00
$retryEnabled = ( $retryOption === '' );
2024-04-25 12:15:08 +05:45
$tryAgain = false ;
$retried = 0 ;
do {
$response = GraphHelper :: getSharesSharedWithMe (
2024-01-25 09:47:56 +05:45
$this -> featureContext -> getBaseUrl (),
$credentials [ 'username' ],
2025-06-19 15:34:02 +05:45
$credentials [ 'password' ],
2024-04-25 12:15:08 +05:45
);
2024-07-03 12:16:06 +05:45
$jsonBody = $this -> featureContext -> getJsonDecodedResponseBodyContent ( $response );
2024-04-25 12:15:08 +05:45
2024-09-24 15:59:10 +02:00
if ( $retryEnabled ) {
foreach ( $jsonBody -> value as $share ) {
$autoSync = $this -> featureContext -> getUserAutoSyncSetting ( $credentials [ 'username' ]);
2024-12-24 09:30:42 +05:45
$tryAgain = ! $share -> { '@client.synchronize' }
&& $autoSync
2025-02-17 17:44:48 +05:45
&& $retried < HttpRequestHelper :: maxHTTPRequestRetries ();
2024-09-24 15:59:10 +02:00
if ( $tryAgain ) {
$retried += 1 ;
echo "auto-sync share for user ' $user ' is enabled \n " ;
echo "but share ' $share->name ' was not auto-synced, retrying ( $retried )... \n " ;
// wait 500ms and try again
\usleep ( 500 * 1000 );
break ;
}
2024-04-25 12:15:08 +05:45
}
}
} while ( $tryAgain );
$this -> featureContext -> setResponse ( $response );
2024-03-21 14:03:09 +05:45
$this -> featureContext -> pushToLastStatusCodesArrays ();
2024-01-25 09:47:56 +05:45
}
2024-02-01 13:54:44 +05:45
2024-02-16 15:16:29 +05:45
/**
*
* @param string $user
* @param bool $waitForCacheExpiry
*
2024-05-17 14:19:53 +05:45
* @return ResponseInterface
2024-02-16 15:16:29 +05:45
*/
2024-05-17 14:19:53 +05:45
public function listSharesSharedByMe ( string $user , bool $waitForCacheExpiry = false ) : ResponseInterface {
2024-02-16 15:16:29 +05:45
$credentials = $this -> getAdminOrUserCredentials ( $user );
if ( $waitForCacheExpiry ) {
// ENV (GRAPH_SPACES_GROUPS_CACHE_TTL | GRAPH_SPACES_USERS_CACHE_TTL) is set default to 60 sec
// which means 60 sec is required to clean up all the user|group cache once they are deleted
// for tests we have set the above ENV's to minimum which is 1 sec as we check the details for the deleted users
sleep ( 1 );
}
2024-05-17 14:19:53 +05:45
return GraphHelper :: getSharesSharedByMe (
2024-02-16 15:16:29 +05:45
$this -> featureContext -> getBaseUrl (),
$credentials [ 'username' ],
2025-06-19 15:34:02 +05:45
$credentials [ 'password' ],
2024-02-16 15:16:29 +05:45
);
}
2024-02-01 13:54:44 +05:45
/**
2024-02-01 16:40:29 +05:45
* @When user :user lists the shares shared by him/her using the Graph API
2024-02-01 13:54:44 +05:45
*
* @param string $user
*
* @return void
* @throws GuzzleException
*/
public function userListsTheResourcesSharedByAUserUsingGraphApi ( string $user ) : void {
2024-05-17 14:19:53 +05:45
$response = $this -> listSharesSharedByMe ( $user );
$this -> featureContext -> setResponse ( $response );
2024-02-16 15:16:29 +05:45
}
/**
* @When user :user lists the shares shared by him/her after clearing user/group cache using the Graph API
*
* @param string $user
*
* @return void
* @throws GuzzleException
*/
public function userListsTheResourcesSharedByAUserAfterClearingUserOrGroupSpaceUsingGraphApi ( string $user ) : void {
2024-05-17 14:19:53 +05:45
$response = $this -> listSharesSharedByMe ( $user , true );
$this -> featureContext -> setResponse ( $response );
2024-02-01 13:54:44 +05:45
}
/**
2024-02-01 16:40:29 +05:45
* @Then /^the JSON data of the response should (not )?contain resource "([^"]*)" with the following data:?$/
2024-02-01 13:54:44 +05:45
*
* @param string $shouldOrNot (not| )
* @param string $fileName
* @param PyStringNode $schemaString
*
* @return void
* @throws Exception
*/
public function theJsonDataResponseShouldOrNotContainSharedByMeDetails (
string $shouldOrNot ,
string $fileName ,
2025-06-19 15:34:02 +05:45
PyStringNode $schemaString ,
2024-02-01 13:54:44 +05:45
) : void {
$responseBody = $this -> featureContext -> getJsonDecodedResponseBodyContent () -> value ;
$fileOrFolderFound = false ;
foreach ( $responseBody as $value ) {
if ( isset ( $value -> name ) && $value -> name === $fileName ) {
$responseBody = $value ;
$fileOrFolderFound = true ;
break ;
}
}
$shouldContain = \trim ( $shouldOrNot ) !== 'not' ;
if ( ! $shouldContain && ! $fileOrFolderFound ) {
return ;
}
2025-06-12 10:59:16 +05:45
if ( $shouldContain && ! $fileOrFolderFound ) {
Assert :: fail (
'Response does not contain file or folder "' . $fileName . '" but should.' ,
);
}
2024-02-01 13:54:44 +05:45
Assert :: assertFalse (
! $shouldContain && $fileOrFolderFound ,
2025-06-19 15:34:02 +05:45
'Response contains file "' . $fileName . '" but should.' ,
2024-02-01 13:54:44 +05:45
);
$this -> featureContext -> assertJsonDocumentMatchesSchema (
$responseBody ,
2025-06-19 15:34:02 +05:45
$this -> featureContext -> getJSONSchema ( $schemaString ),
2024-02-01 13:54:44 +05:45
);
}
2024-04-17 11:42:09 +02:00
/**
* @Then the JSON data of the search response should not contain user(s) email
*
* @return void
* @throws Exception
*/
public function theJsonDataResponseShouldNotContainUserEmail () : void {
$responseBody = $this -> featureContext -> getJsonDecodedResponseBodyContent () -> value ;
$mailValueExist = false ;
$email = "" ;
foreach ( $responseBody as $value ) {
if ( isset ( $value -> mail )) {
$mailValueExist = true ;
$email = $value -> mail ;
break ;
}
}
Assert :: assertFalse (
$mailValueExist ,
2025-06-19 15:34:02 +05:45
"Response contains email ' $email ' but should not." ,
2024-04-17 11:42:09 +02:00
);
}
2024-07-12 13:27:34 +05:45
/**
* @Then user :byUser using password :password should be able to create a new user :user with default attributes
*
* @param string $byUser
* @param string $password
* @param string $user
*
* @return void
* @throws GuzzleException
* @throws JsonException
*/
2024-12-24 09:30:42 +05:45
public function userUsingPasswordShouldBeAbleToCreateANewUserWithDefaultAttributes (
string $byUser ,
string $password ,
2025-06-19 15:34:02 +05:45
string $user ,
2024-12-24 09:30:42 +05:45
) : void {
2024-07-12 13:27:34 +05:45
$response = GraphHelper :: createUser (
$this -> featureContext -> getBaseUrl (),
$byUser ,
$password ,
$user ,
2025-06-19 15:34:02 +05:45
$this -> featureContext -> getPasswordForUser ( $user ),
2024-07-12 13:27:34 +05:45
);
Assert :: assertEquals (
201 ,
$response -> getStatusCode (),
__METHOD__ . " cannot create new user ' $user ' by user ' $byUser '. \n Response:" .
2025-06-19 15:34:02 +05:45
json_encode ( $this -> featureContext -> getJsonDecodedResponse ( $response )),
2024-07-12 13:27:34 +05:45
);
$this -> featureContext -> addUserToCreatedUsersList ( $user , $this -> featureContext -> getPasswordForUser ( $user ));
}
/**
* @Given user :byUser has changed the username to :userName
*
* @param string $byUser
* @param string $userName
*
* @return void
* @throws GuzzleException
* @throws JsonException
*/
public function theUserHasChangedItsOwnUsernameTo ( string $byUser , string $userName ) : void {
$userId = $this -> featureContext -> getUserIdByUserName ( $byUser );
$response = GraphHelper :: editUser (
$this -> featureContext -> getBaseUrl (),
$byUser ,
$this -> featureContext -> getPasswordForUser ( $byUser ),
$userId ,
'PATCH' ,
$userName ,
);
$this -> featureContext -> theHTTPStatusCodeShouldBe ( 200 , '' , $response );
$this -> featureContext -> updateUsernameInCreatedUserList ( $byUser , $userName );
}
2024-07-18 15:59:32 +05:45
/**
* @When user :user gets a list of permissions role definitions using the Graph API
*
* @param string $user
*
* @return void
* @throws GuzzleException
*/
public function getListOfPermissionRoleDefinitionsUsingTheGraphAPI ( string $user ) : void {
$credentials = $this -> getAdminOrUserCredentials ( $user );
$this -> featureContext -> setResponse (
GraphHelper :: getPermissionsRoleDefinitions (
$this -> featureContext -> getBaseUrl (),
$credentials [ 'username' ],
$credentials [ 'password' ],
2025-06-19 15:34:02 +05:45
),
2024-07-18 15:59:32 +05:45
);
}
/**
* @When user :user gets the :permissionRole role definition using the Graph API
*
* @param string $user
* @param string $permissionRole
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function getPermissionRoleDefinitionUsingGraphAPI ( string $user , string $permissionRole ) : void {
2024-07-18 15:59:32 +05:45
$credentials = $this -> getAdminOrUserCredentials ( $user );
$this -> featureContext -> setResponse (
GraphHelper :: getPermissionRoleDefinition (
$permissionRole ,
$this -> featureContext -> getBaseUrl (),
$credentials [ 'username' ],
$credentials [ 'password' ],
2025-06-19 15:34:02 +05:45
),
2024-07-18 15:59:32 +05:45
);
}
2024-07-23 16:57:58 +05:45
/**
*
* @param string $user
* @param string $resource
* @param string $spaceName
*
2025-04-15 11:21:59 +05:45
* @return ResponseInterface
* @throws GuzzleException
2024-07-23 16:57:58 +05:45
*/
2025-04-15 11:21:59 +05:45
public function getActivities (
2024-12-24 09:30:42 +05:45
string $user ,
string $resource ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2025-04-15 11:21:59 +05:45
) : ResponseInterface {
2025-04-07 16:30:48 +05:45
if ( $spaceName === "Shares" ) {
$resourceId = $this -> spacesContext -> getSharesRemoteItemId ( $user , $resource );
} else {
$resourceId = $this -> spacesContext -> getResourceId ( $user , $spaceName , $resource );
}
2025-04-15 11:21:59 +05:45
return GraphHelper :: getActivities (
2024-07-23 16:57:58 +05:45
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
2025-06-19 15:34:02 +05:45
$resourceId ,
2024-07-23 16:57:58 +05:45
);
2025-04-15 11:21:59 +05:45
}
/**
* @When /^user "([^"]*)" lists the activities of (?:folder|file) "([^"]*)" from space "([^"]*)" using the Graph API$/
*
* @param string $user
* @param string $resource
* @param string $spaceName
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
public function userListsTheActivitiesForResourceOfSpaceUsingTheGraphAPI (
string $user ,
string $resource ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2025-04-15 11:21:59 +05:45
) : void {
$this -> featureContext -> setResponse ( $this -> getActivities ( $user , $resource , $spaceName ));
}
/**
* @Then /^for user "([^"]*)" (?:folder|file) "([^"]*)" of the space "([^"]*)" should have the following activities:$/
*
* @param string $user
* @param string $resource
* @param string $spaceName
* @param TableNode $table
*
* @return void
* @throws GuzzleException
*/
public function forUserFolderOrFileOfTheSpaceShouldHaveTheseActivities (
string $user ,
string $resource ,
string $spaceName ,
2025-06-19 15:34:02 +05:45
TableNode $table ,
2025-04-15 11:21:59 +05:45
) : void {
$unmatchedActivities = [];
$activities = $this -> featureContext -> getJsonDecodedResponse (
2025-06-19 15:34:02 +05:45
$this -> getActivities ( $user , $resource , $spaceName ),
2025-04-15 11:21:59 +05:45
);
foreach ( $table -> getRows () as $expectedActivity ) {
$matched = false ;
foreach ( $activities [ 'value' ] as $activity ) {
if ( $expectedActivity [ 0 ] === $activity [ 'template' ][ 'message' ]) {
$matched = true ;
break ;
}
}
if ( ! $matched ) {
$unmatchedActivities [] = "Expected activity ' $expectedActivity[0] ' was not found in the response. " ;
}
}
if ( ! empty ( $unmatchedActivities )) {
Assert :: fail ( implode ( " \n " , $unmatchedActivities ));
}
}
/**
* @Then /^for user "([^"]*)" (?:folder|file) "([^"]*)" of the space "([^"]*)" should not have any activity$/
*
* @param string $user
* @param string $resource
* @param string $spaceName
*
* @return void
* @throws GuzzleException
*/
public function forUserFileOfTheSpaceShouldNotHaveAnyActivity (
string $user ,
string $resource ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2025-04-15 11:21:59 +05:45
) : void {
$activities = $this -> getActivities ( $user , $resource , $spaceName );
$responseBody = $activities -> getBody () -> getContents ();
Assert :: assertEmpty (
$responseBody ,
__METHOD__
. " \n Expected no activity of resource ' $resource ' for user ' $user ', but some activities were found \n " .
2025-06-19 15:34:02 +05:45
print_r ( json_decode ( $responseBody , true ), true ),
2025-04-15 11:21:59 +05:45
);
2024-07-23 16:57:58 +05:45
}
2024-07-29 17:13:01 +05:45
2024-08-19 09:55:19 +05:45
/**
* @When user :user tries to list the activities of folder :folder with share mount-point id using the Graph API
*
* @param string $user
* @param string $folder
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function userTriesToListTheActivitiesOfFolderWithShareMountIdPointIdUsingTheGraphApi (
string $user ,
2025-06-19 15:34:02 +05:45
string $folder ,
2024-12-24 09:30:42 +05:45
) : void {
2024-08-19 09:55:19 +05:45
$resourceId = GraphHelper :: getShareMountId (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
2025-06-19 15:34:02 +05:45
$folder ,
2024-08-19 09:55:19 +05:45
);
$response = GraphHelper :: getActivities (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
2025-06-19 15:34:02 +05:45
$resourceId ,
2024-08-19 09:55:19 +05:45
);
$this -> featureContext -> setResponse ( $response );
}
/**
* @When user :user tries to list the activities of file :file from space :spaceName owned by user :owner using the Graph API
*
* @param string $user
* @param string $file
* @param string $owner
* @param string $spaceName
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function userTriesToListActivitiesOfFileFromSpaceOwnedByUserUsingTheGraphApi (
string $user ,
string $file ,
string $owner ,
2025-06-19 15:34:02 +05:45
string $spaceName ,
2024-12-24 09:30:42 +05:45
) : void {
2025-02-17 17:44:48 +05:45
$resourceId = $this -> spacesContext -> getResourceId ( $owner , $spaceName , $file );
2024-08-19 09:55:19 +05:45
$response = GraphHelper :: getActivities (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
2025-06-19 15:34:02 +05:45
$resourceId ,
2024-08-19 09:55:19 +05:45
);
$this -> featureContext -> setResponse ( $response );
}
2024-07-29 17:13:01 +05:45
/**
* @When user :user lists the activities of space :spaceName using the Graph API
*
* @param string $user
* @param string $spaceName
*
* @return void
*/
2024-08-12 16:10:51 +05:45
public function userListsTheActivitiesOfSpaceUsingTheGraphApi ( string $user , string $spaceName ) : void {
2025-02-17 18:44:30 +05:45
$spaceId = ( $this -> spacesContext -> getSpaceByName ( $user , $spaceName ))[ "id" ];
2024-07-29 17:13:01 +05:45
$response = GraphHelper :: getActivities (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
2025-06-19 15:34:02 +05:45
$spaceId ,
2024-07-29 17:13:01 +05:45
);
$this -> featureContext -> setResponse ( $response );
}
2024-08-14 16:38:42 +02:00
2024-09-25 16:26:13 +05:45
/**
* @When the public tries to check the activities of space :spaceName owned by user :user with password :password using the Graph API
*
* @param string $spaceName
* @param string $user
* @param string $password
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function thePublicTriesToCheckTheActivitiesOfSpaceOwnedByUserWithPasswordUsingGraphApi (
string $spaceName ,
string $user ,
2025-06-19 15:34:02 +05:45
string $password ,
2024-12-24 09:30:42 +05:45
) : void {
2024-09-25 16:26:13 +05:45
$response = GraphHelper :: getActivities (
$this -> featureContext -> getBaseUrl (),
"public" ,
$this -> featureContext -> getActualPassword ( $password ),
2025-06-19 15:34:02 +05:45
$this -> spacesContext -> getSpaceIdByName ( $user , $spaceName ),
2024-09-25 16:26:13 +05:45
);
$this -> featureContext -> setResponse ( $response );
}
/**
* @When /^the public tries to check the activities of (?:folder|file) "([^"]*)" from space "([^"]*)" owned by user "([^"]*)" with password "([^"]*)" using the Graph API$/
*
* @param string $resource
* @param string $space
* @param string $owner
* @param string $password
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function thePublicTriesToCheckTheActivitiesOfResourceFromSpaceOwnedByUserWithPasswordUsingGraphApi (
string $resource ,
string $space ,
string $owner ,
2025-06-19 15:34:02 +05:45
string $password ,
2024-12-24 09:30:42 +05:45
) : void {
2024-09-25 16:26:13 +05:45
$response = GraphHelper :: getActivities (
$this -> featureContext -> getBaseUrl (),
"public" ,
$this -> featureContext -> getPasswordForUser ( $owner ),
2025-06-19 15:34:02 +05:45
$this -> spacesContext -> getResourceId ( $owner , $space , $resource ),
2024-09-25 16:26:13 +05:45
);
$this -> featureContext -> setResponse ( $response );
}
2024-08-20 17:13:37 +05:45
/**
2024-10-04 11:59:32 +05:45
* @When /^user "([^"]*)" lists the activities of (?:folder|file) "([^"]*)" from space "([^"]*)" with (depth|limit|sort) "([^"]*)" using the Graph API$/
2024-08-20 17:13:37 +05:45
*
* @param string $user
* @param string $resource
* @param string $spaceName
2024-08-21 16:22:59 +05:45
* @param string $filterType
* @param string $filterValue
2024-08-20 17:13:37 +05:45
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function userListsTheActivitiesForFolderOfSpaceWithDepthOrLimitUsingTheGraphApi (
string $user ,
string $resource ,
string $spaceName ,
string $filterType ,
2025-06-19 15:34:02 +05:45
string $filterValue ,
2024-12-24 09:30:42 +05:45
) : void {
2025-02-17 17:44:48 +05:45
$resourceId = $this -> spacesContext -> getResourceId ( $user , $spaceName , $resource );
2024-08-20 17:13:37 +05:45
$response = GraphHelper :: getActivities (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$resourceId ,
2025-06-19 15:34:02 +05:45
[ $filterType => $filterValue ],
2024-08-20 17:13:37 +05:45
);
$this -> featureContext -> setResponse ( $response );
}
2024-10-04 12:07:40 +05:45
/**
* @Then the activities should be in the following order:
*
* @param TableNode $table
*
* @return void
* @throws Exception
*/
public function theActivitiesShouldBeInTheFollowingOrder ( TableNode $table ) : void {
$responseBody = $this -> featureContext -> getJsonDecodedResponseBodyContent ();
$activities = $responseBody -> value ;
foreach ( $table -> getHash () as $index => $expectedValue ) {
$actualActivity = $activities [ $index ];
$expectedActivity = $expectedValue [ 'resource' ] . ":" . $expectedValue [ 'message' ];
2024-12-24 09:30:42 +05:45
$actualActivity = $actualActivity -> template -> variables -> resource -> name
. ":" . $actualActivity -> template -> message ;
2024-10-04 12:07:40 +05:45
Assert :: assertEquals ( $expectedActivity , $actualActivity , "Activity didn't match" );
}
}
2024-10-04 11:59:32 +05:45
/**
* @When /^user "([^"]*)" lists the activities of (?:folder|file) "([^"]*)" from space "([^"]*)" with (depth|limit) "([^"]*)" and sort "(asc|desc)" using the Graph API$/
*
* @param string $user
* @param string $resource
* @param string $spaceName
* @param string $filterType
* @param string $filterValue
* @param string $sortType
*
* @return void
* @throws GuzzleException
*/
public function userListsTheActivitiesOfResourceFromSpaceWithDepthOrLimitAndSortUsingTheGraphApi (
string $user ,
string $resource ,
string $spaceName ,
string $filterType ,
string $filterValue ,
2025-06-19 15:34:02 +05:45
string $sortType ,
2024-10-04 11:59:32 +05:45
) : void {
$resourceId = $this -> spacesContext -> getResourceId ( $user , $spaceName , $resource );
$response = GraphHelper :: getActivities (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$resourceId ,
[ $filterType => $filterValue , 'sort' => $sortType ],
);
$this -> featureContext -> setResponse ( $response );
}
2024-08-14 16:38:42 +02:00
/**
* @When the administrator gets federated users using the Graph API
* @When user :user tries to get federated users using the Graph API
*
* @param ?string $user
*
* @return void
*/
public function theUserGetsFederatedUsersUsingTheGraphApi ( ? string $user = null ) : void {
$credentials = $this -> getAdminOrUserCredentials ( $user );
2024-08-21 16:22:59 +05:45
2024-08-14 16:38:42 +02:00
$response = GraphHelper :: getFederatedUsers (
$this -> featureContext -> getBaseUrl (),
$credentials [ 'username' ],
2025-06-19 15:34:02 +05:45
$credentials [ 'password' ],
2024-08-14 16:38:42 +02:00
);
$this -> featureContext -> setResponse ( $response );
}
/**
2024-08-19 11:11:17 +02:00
* @When the administrator gets federated and local users using the Graph API
* @When user :user tries to get federated and local users using the Graph API
2024-08-14 16:38:42 +02:00
*
* @param ?string $user
*
* @return void
*/
public function theUserGetsAllUsersUsingTheGraphApi ( ? string $user = null ) : void {
$credentials = $this -> getAdminOrUserCredentials ( $user );
2024-08-21 16:22:59 +05:45
2024-08-14 16:38:42 +02:00
$response = GraphHelper :: getAllUsers (
$this -> featureContext -> getBaseUrl (),
$credentials [ 'username' ],
2025-06-19 15:34:02 +05:45
$credentials [ 'password' ],
2024-08-14 16:38:42 +02:00
);
$this -> featureContext -> setResponse ( $response );
}
2025-05-09 17:07:52 +05:45
/**
* @When user :user searches for user :searchTerm of the group :group using the Graph API
* @When user :user tries to search for user :searchTerm of the group :group using the Graph API
*
* @param string $user
* @param string $searchTerm
* @param string $group
*
* @return void
* @throws GuzzleException
*/
2025-06-19 12:15:41 +05:45
public function userSearchesForUserOfTheGroupUsingTheGraphApi (
string $user ,
string $searchTerm ,
2025-06-19 15:34:02 +05:45
string $group ,
2025-06-19 12:15:41 +05:45
) : void {
2025-05-09 17:07:52 +05:45
$groupId = $this -> featureContext -> getGroupIdByGroupName ( $group );
$response = GraphHelper :: searchUserWithFilterMemberOf (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$groupId ,
2025-06-19 15:34:02 +05:45
$searchTerm ,
2025-05-09 17:07:52 +05:45
);
$this -> featureContext -> setResponse ( $response );
}
2025-07-08 12:57:24 +05:45
/**
* @When user :user lists all the activities using the Graph API
*
* @param string $user
*
* @return void
* @throws GuzzleException
*/
public function userListsAllTheActivitiesUsingTheGraphApi ( string $user ) : void {
$response = GraphHelper :: getActivities (
$this -> featureContext -> getBaseUrl (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
);
$this -> featureContext -> setResponse ( $response );
}
2022-03-25 15:33:35 +05:45
}