Skip to content

Commit

Permalink
Added scenario to demonstrate bug in #1032
Browse files Browse the repository at this point in the history
  • Loading branch information
kiranparajuli589 authored and individual-it committed Nov 22, 2021
1 parent 8949c26 commit 6812886
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 10 deletions.
1 change: 1 addition & 0 deletions tests/acceptance/config/behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,5 @@ default:
- ActivityContext:
- OccContext:
- TrashbinContext:
- PublicWebDavContext:
- FeatureContext: *common_feature_context_params
22 changes: 22 additions & 0 deletions tests/acceptance/features/apiActivity/list.feature
Original file line number Diff line number Diff line change
Expand Up @@ -1133,3 +1133,25 @@ Feature: List activity
| object_type | /^files$/ |
| typeicon | /^icon-add-color/ |
| subject_prepared | /^<user display-name=\"Alice Hansen\">Alice<\/user> created <file link=\"%base_url%\/(index\.php\/)?apps\/files\/\?dir=\/FolderForG2\&scrollto=textfile0\.txt\" id=\"\d+\">FolderForG2\/textfile0\.txt<\/file>$/ |

@issue-1032
Scenario: public renames a link shared resource
Given user "Alice" has been created with default attributes and without skeleton files
And user "Alice" has created folder "parent"
And user "Alice" has uploaded file with content "ownCloud test text file 0" to "/parent/textfile0.txt"
And user "Alice" has created a public link share with settings
| path | /parent |
| permissions | read,update,create,delete |
When the public renames file "/textfile0.txt" to "textfile.txt" from the last public share using the new public WebDAV API
Then the HTTP status code should be "201"
And as "Alice" file "/parent/textfile.txt" should exist
And as user "Alice" the activity number 1 for "/parent/textfile.txt" should match these properties:
| type | /^file_created/ |
| user | /^Alice$/ |
| affecteduser | /^Alice$/ |
| app | /^files$/ |
| subject | /^created_self$/ |
| object_name | /^\/parent\/textfile0\.txt$/ |
| object_type | /^files$/ |
| typeicon | /^icon-add-color$/ |
| subject_prepared | /^You created <file link=\"%base_url%\/(index\.php\/)?apps\/files\/\?dir=\/parent\&scrollto=textfile\.txt\" id=\"\d+\">parent\/textfile0\.txt<\/file>$/ |
93 changes: 83 additions & 10 deletions tests/acceptance/features/bootstrap/ActivityContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Gherkin\Node\TableNode;
use GuzzleHttp\Exception\GuzzleException;
use PHPUnit\Framework\Assert;
use TestHelpers\HttpRequestHelper;

Expand All @@ -38,20 +39,21 @@ class ActivityContext implements Context {
private $featureContext;

/**
* @Then the activity number :index of user :user should match these properties:
* Asserts provided table data with index to json decoded activity response
*
* @param string $index (starting from 1, newest to the oldest)
* @param string $user
* @param string $index
* @param array $responseDecoded
* @param TableNode $expectedProperties
*
* @return void
*/
public function activityWithIndexShouldMatch(
string $index,
private function assertActivityIndexContent(
string $user,
string $index,
array $responseDecoded,
TableNode $expectedProperties
): void {
$responseDecoded = $this->getActivitiesForUser($user);
):void {
$activityData = $responseDecoded['ocs']['data'][$index - 1];
foreach ($expectedProperties->getRowsHash() as $key => $value) {
Assert::assertArrayHasKey(
Expand All @@ -70,12 +72,53 @@ public function activityWithIndexShouldMatch(
}
}

/**
* @Then the activity number :index of user :user should match these properties:
*
* @param string $index (starting from 1, newest to the oldest)
* @param string $user
* @param TableNode $expectedProperties
*
* @return void
* @throws GuzzleException
*/
public function activityWithIndexShouldMatch(
string $index,
string $user,
TableNode $expectedProperties
): void {
$responseDecoded = $this->getActivitiesForUser($user);
$this->assertActivityIndexContent($user, $index, $responseDecoded, $expectedProperties);
}

/**
* @Then /^as user "([^"]*)" the activity number (\d+) for "([^"]*)" should match these properties:$/
*
* @param string $user
* @param string $index
* @param string $path
* @param TableNode $expectedProperties
*
* @return void
* @throws GuzzleException
*/
public function asUserTheActivityNumberForShouldMatchTheseProperties(
string $user,
string $index,
string $path,
TableNode $expectedProperties
):void {
$responseDecoded = $this->getActivitiesForFileAsUser($user, $path);
$this->assertActivityIndexContent($user, $index, $responseDecoded, $expectedProperties);
}

/**
* @Then user :user should not have any activity entries
*
* @param string $user
*
* @return void
* @throws GuzzleException
*/
public function userShouldNotHaveAnyActivityEntries(
string $user
Expand All @@ -98,6 +141,7 @@ public function userShouldNotHaveAnyActivityEntries(
* @param string $activityType
*
* @return void
* @throws GuzzleException
*/
public function userShouldNotHaveAnyActivityEntriesWithType(
string $user,
Expand All @@ -123,13 +167,43 @@ public function userShouldNotHaveAnyActivityEntriesWithType(
* @param string $user
*
* @return array of activity entries
* @throws GuzzleException
*/
public function getActivitiesForUser(
string $user
): array {
$user = $this->featureContext->getActualUsername($user);
$fullUrl = $this->featureContext->getBaseUrl() .
"/index.php/apps/activity/api/v2/activity";
$url = "/index.php/apps/activity/api/v2/activity";
return $this->sendActivityGetRequest($url, $user);
}

/**
* @param string $user
* @param string $resource
*
* @return array
* @throws GuzzleException
* @throws JsonException
*/
public function getActivitiesForFileAsUser(
string $user,
string $resource
): array {
$user = $this->featureContext->getActualUsername($user);
$objectId = $this->featureContext->getFileIdForPath($user, $resource);
$url = "/index.php/apps/activity/api/v2/activity/filter?object_type=files&object_id=${objectId}";
return $this->sendActivityGetRequest($url, $user);
}

/**
* @param string $url
* @param string $user
*
* @return array
* @throws GuzzleException
*/
private function sendActivityGetRequest(string $url, string $user):array {
$fullUrl = $this->featureContext->getBaseUrl() . $url;
$response = HttpRequestHelper::get(
$fullUrl,
$this->featureContext->getStepLineRef(),
Expand All @@ -140,11 +214,10 @@ public function getActivitiesForUser(
200,
$response->getStatusCode()
);
$responseDecoded = \json_decode(
return \json_decode(
$response->getBody()->getContents(),
true
);
return $responseDecoded;
}

/**
Expand Down

0 comments on commit 6812886

Please sign in to comment.