Skip to content

Commit

Permalink
added feature file and step definition for enabling and disabling syn…
Browse files Browse the repository at this point in the history
…c of share (#107)

* updated stable and master commit

* updated drone to skip test on stable
  • Loading branch information
S-Panta authored Apr 26, 2024
1 parent 144c565 commit b7cceb2
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .drone.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# The version of OCIS to use in pipelines that test against OCIS
OCIS_COMMITID=2a300190cbccb2b4a93b7aa76abe4f204fb393bf
OCIS_COMMITID=c2ab6666a5b9bbba899fdf9486f8d9bae6bc12b4
OCIS_BRANCH=master
OCIS_STABLE_COMMITID=b8149ede7db9d510e1988ca9fdfe51fd44e7d603
OCIS_STABLE_COMMITID=08c6f41fc8a965b1a1dc83045b673ce1bdfc000e
OCIS_STABLE_BRANCH=stable-5.0
10 changes: 7 additions & 3 deletions .drone.star
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def behattest():
"depends_on": [],
"steps":generateSSLCert() + apacheService() + waitForService("apache",443) + runOcis(branch) + \
waitForService("ocis",9200) + databaseService() + waitForService("postgresql",5432) + \
seleniumService() + waitForService("selenium",4444) + setupMoodle() + runBehatTest() ,
seleniumService() + waitForService("selenium",4444) + setupMoodle() + runBehatTest(branch) ,
"volumes": [
{
"name":"www-moodle",
Expand Down Expand Up @@ -393,7 +393,11 @@ def seleniumService():
}
]

def runBehatTest():
def runBehatTest(branch):
if branch == "master":
tags = "@ocis"
else:
tags = "@ocis &&~@skipOnStable"
return [
{
"name":"behat-test",
Expand All @@ -402,7 +406,7 @@ def runBehatTest():
"commands": [
"update-ca-certificates",
"cd /var/www/html/moodle",
"vendor/bin/behat --config /var/www/behatdata/behatrun/behat/behat.yml --tags=@ocis",
'vendor/bin/behat --config /var/www/behatdata/behatrun/behat/behat.yml --tags="%s"' %tags,
],
"volumes":[
{
Expand Down
33 changes: 33 additions & 0 deletions tests/behat/behat_repository_ocis.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,4 +379,37 @@ public function i_should_see_after_refreshing_the_file_picker(string $text) {
$refreshbutton->click();
$this->execute('behat_general::assert_page_contains_text', [$text]);
}

/**
* Step definition for disabling sync of share
* @When user :user disables sync of share :share
*
* @param string $user
*
* @throws Exception
*/
public function user_disables_sync_of_share(string $user) {
$response = $this->graphhelper->disable_share_sync($user);
if ((!in_array($response['statusCode'], [200, 204]))) {
throw new Exception("Error disabling sync of share " . var_dump($response['statusCode']));
}
}

/**
* Step definition for enabling sync of share
* @When user :user enables sync of share :share offered by :offeredBy from :space space
*
* @param string $user
* @param string $share
* @param string $offeredby
* @param string $space
*
* @throws Exception
*/
public function user_enables_sync_of_share(string $user, string $share, string $offeredby, string $space) {
$response = $this->graphhelper->enable_share_sync($user, $share, $offeredby, $space);
if ($response['statusCode'] !== 201) {
throw new Exception("Error enabling sync of share");
}
}
}
55 changes: 54 additions & 1 deletion tests/behat/graph_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ class graph_helper {
*/
private const ALTERNATE_USER_PASSWORD = '1234';

/**
* shares space id
*/
private const SHARES_SPACE_ID = 'a0ca6a90-a365-4782-871e-d44447bbc668$a0ca6a90-a365-4782-871e-d44447bbc668';

/***
* array for storing response from share
* @var string $lastcreatedshareid
*/
private string $lastcreatedshareid;

/**
* Get a new SabreDAV client
* @param string $user
Expand Down Expand Up @@ -248,10 +259,52 @@ public function send_share_invitation(string $user, string $sharetype, string $s
];
$itemid = $this->get_resource_id($user, $resource, $space);
$client = $this->get_client($user);
return $client->request(
$response = $client->request(
'POST',
"/graph/v1beta1/drives/$spaceid/items/$itemid/invite",
json_encode($body)
);
$resbody = json_decode($response["body"], true);
$this->lastcreatedshareid = $resbody["value"][0]["id"];
return $response;
}

/**
* send request to disable sync of share
* @param string $user
*
* @return array
*/
public function disable_share_sync(string $user): array {
$itemid = self::SHARES_SPACE_ID . '!' . $this->lastcreatedshareid;
$client = $this->get_client($user);
return $client->request(
'DELETE',
"/graph/v1beta1/drives/" . self::SHARES_SPACE_ID . "/items/$itemid",
);
}

/**
* send request to enable sync of share
* @param string $user
* @param string $share
* @param string $offeredby
* @param string $space
*
* @return array
*/
public function enable_share_sync(string $user, string $share, string $offeredby, string $space): array {
$itemid = $this->get_resource_id($offeredby, $share, $space);
$body = [
"remoteItem" => [
"id" => $itemid,
],
];
$client = $this->get_client($user);
return $client->request(
'POST',
"/graph/v1beta1/drives/" . self::SHARES_SPACE_ID . "/root/children",
json_encode($body)
);
}
}
16 changes: 16 additions & 0 deletions tests/behat/uploadFileToMoodle.feature
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,19 @@ Feature: upload the resource in oCIS to moodle
Then I should see "Personal"
And I should see "Shares"
And I should see "ProjectMoodle"

@skipOnStable @ocis-issue-8961
Scenario: enable/disable sync of shared resource shared from Personal Space
Given user "Brian" has been created with default attributes
And user "Brian" has uploaded a file inside space "Personal" with content "some content" to "/testfile.txt"
And user "Brian" has sent the following share invitation:
| resource | testfile.txt |
| space | Personal |
| sharee | Admin |
| shareType | user |
When user "Admin" disables sync of share "testfile.txt"
And I click on "//*[@class='fp-filename-field']/p[text()='Shares']" "xpath_element"
Then I should not see "testfile.txt"
When user "Admin" enables sync of share "testfile.txt" offered by "Brian" from "Personal" space
And I refresh the file-picker
Then I should see "testfile.txt"

0 comments on commit b7cceb2

Please sign in to comment.