Skip to content

Commit

Permalink
test with core branch
Browse files Browse the repository at this point in the history
  • Loading branch information
SwikritiT committed Sep 5, 2022
1 parent 4b7ca12 commit 7f18716
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 32 deletions.
3 changes: 2 additions & 1 deletion tests/acceptance/config/behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ default:
- SearchContext:
- TrashbinContext:
- WebDavPropertiesContext:
- TusContext:
- TUSContext:
- SpacesTusContext:

apiArchiver:
paths:
Expand Down
6 changes: 3 additions & 3 deletions tests/acceptance/features/apiSpaces/filePreviews.feature
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ Feature: Preview file in project space
Then the HTTP status code should be "200"
Examples:
| entity | width | height |
| qrcode.png | 36 | 36 |
| qrcode.png | 1200 | 1200 |
| qrcode.png | 1920 | 1920 |
| testavatar.png | 36 | 36 |
| testavatar.png | 1200 | 1200 |
| testavatar.png | 1920 | 1920 |
| testavatar.jpg | 36 | 36 |
| testavatar.jpg | 1200 | 1200 |
| testavatar.jpg | 1920 | 1920 |
Expand Down
19 changes: 12 additions & 7 deletions tests/acceptance/features/apiSpaces/tusUpload.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,22 @@ Feature: upload resources using TUS protocol
And the administrator has given "Alice" the role "Space Admin" using the settings api


Scenario: upload a file within the set quota to a project space
Scenario: upload a file within the set quota to a project space
Given user "Alice" has created a space "Project Jupiter" of type "project" with quota "10000"
When user "Alice" uploads a file "qrcode.png" via TUS inside of the space "Project Jupiter" using the WebDAV API
When user "Alice" uploads a file with content "uploaded content" to "upload.txt" via TUS inside of the space "Project Jupiter" using the WebDAV API
Then the HTTP status code should be "204"
And for user "Alice" the space "Project Jupiter" should contain these entries:
| qrcode.png |
| upload.txt |


Scenario: upload a file bigger than the set quota to a project space
Given user "Alice" has created a space "Project Jupiter" of type "project" with quota "10"
When user "Alice" creates a new TUS resource "qrcode.png" for the space "Project Jupiter" using the WebDAV API
When user "Alice" creates a new TUS resource for the space "Project Jupiter" using the WebDAV API with these headers:
| Upload-Length | 100 |
# dXBsb2FkLnR4dA== is the base64 encoded value of filename upload.txt
| Upload-Metadata | filename dXBsb2FkLnR4dA== |
| Tus-Resumable | 1.0.0 |
Then the HTTP status code should be "507"
And for user "Alice" the space "Project Jupiter" should not contain these entries:
| qrcode.png |
| upload.txt |

Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,25 @@
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use GuzzleHttp\Exception\GuzzleException;
use TestHelpers\HttpRequestHelper;
use Behat\Gherkin\Node\TableNode;

require_once 'bootstrap.php';

/**
* Context for the TUS-specific steps using the Graph API
*/
class TusContext implements Context {
class SpacesTusContext implements Context {

/**
* @var FeatureContext
*/
private FeatureContext $featureContext;

/**
* @var TUSContext
*/
private TUSContext $tusContext;

/**
* @var SpacesContext
*/
Expand All @@ -35,13 +41,6 @@ class TusContext implements Context {
*/
private string $baseUrl;

/**
* @return string
*/
public function acceptanceTestsDirLocation(): string {
return \dirname(__FILE__) . "/../../filesForUpload/";
}

/**
* This will run before EVERY scenario.
* It will set the properties for this object.
Expand All @@ -58,6 +57,7 @@ public function before(BeforeScenarioScope $scope): void {
// Get all the contexts you need in this context from here
$this->featureContext = $environment->getContext('FeatureContext');
$this->spacesContext = $environment->getContext('SpacesContext');
$this->tusContext = $environment->getContext('TUSContext');
$this->baseUrl = \trim($this->featureContext->getBaseUrl(), "/");
}

Expand All @@ -77,25 +77,61 @@ public function uploadFileViaTus(string $user, string $resource, string $spaceNa
$this->userUploadsAFileViaTusInsideOfTheSpaceUsingTheWebdavApi($user, $resource, $spaceName);
$this->featureContext->theHTTPStatusCodeShouldBe(204, "Expected response status code should be 204");
}

/**
* @When /^user "([^"]*)" uploads a file "([^"]*)" via TUS inside of the space "([^"]*)" using the WebDAV API$/
*
* @param string $user
* @param string $resource
* @param string $spaceName
* @param array|null $headers
*
* @return void
*
* @throws Exception
* @throws GuzzleException
*/
public function userUploadsAFileViaTusInsideOfTheSpaceUsingTheWebdavApi(string $user, string $resource, string $spaceName) {
$this->createTusResource($user, $resource, $spaceName);
public function userUploadsAFileViaTusInsideOfTheSpaceUsingTheWebdavApi(string $user, string $resource, string $spaceName, ?array $headers = null) {
$this->createTusResource($user, $resource, $spaceName, $headers);
$this->featureContext->theHTTPStatusCodeShouldBe(201, "Expected response status code should be 201");
$this->uploadResourceThroughTUS($user, $resource);
}


/**
* @Given user :user has created a new TUS resource for the space :spaceName using the WebDAV API with these headers:
*
* @param string $user
* @param string $spaceName
* @param TableNode $headers
*
* @return void
*
* @throws Exception
* @throws GuzzleException
*/
public function userHasCreatedANewTusResourceForTheSpaceUsingTheWebdavApiWithTheseHeaders(string $user, string $spaceName, TableNode $headers):void {
$this->featureContext->verifyTableNodeColumnsCount($headers, 2);
$this->createTusResource($user, "", $spaceName, $headers->getRowsHash());
$this->featureContext->theHTTPStatusCodeShouldBe(201, "Expected response status code should be 201");
}

/**
* @When user :user creates a new TUS resource for the space :spaceName using the WebDAV API with these headers:
*
* @param string $user
* @param string $spaceName
* @param TableNode $headers
*
* @return void
*
* @throws Exception
* @throws GuzzleException
*/
public function userCreatesANewTusResourceForTheSpaceUsingTheWebdavApiWithTheseHeaders(string $user, string $spaceName, TableNode $headers):void {
$this->featureContext->verifyTableNodeColumnsCount($headers, 2);
$this->createTusResource($user, "", $spaceName, $headers->getRowsHash());
}

/**
* @When /^user "([^"]*)" creates a new TUS resource "([^"]*)" for the space "([^"]*)" using the WebDAV API$/
*
Expand All @@ -111,26 +147,48 @@ public function userCreatesANewTusResourceForTheSpaceUsingTheWebdavApi(string $u
}

/**
* send POST request to create the TUS resource
* @When /^user "([^"]*)" uploads a file with content "([^"]*)" to "([^"]*)" via TUS inside of the space "([^"]*)" using the WebDAV API$/
*
* @param string $user
* @param string $content
* @param string $resource
* @param string $spaceName
*
* @return void
* @throws Exception|GuzzleException
*/
public function createTusResource(string $user, string $resource, string $spaceName): void {
public function userUploadsAFileWithContentToViaTusInsideOfTheSpaceUsingTheWebdavApi(string $user, string $content, string $resource, string $spaceName) {
$sourceFile = fopen($this->featureContext->acceptanceTestsDirLocation() . 'filesForUpload/' . $resource, "w");
fwrite($sourceFile, $content);
$this->userUploadsAFileViaTusInsideOfTheSpaceUsingTheWebdavApi($user, $resource, $spaceName);
fclose($sourceFile);
\unlink($this->featureContext->acceptanceTestsDirLocation() . 'filesForUpload/' . $resource);
}

/**
* send POST request to create the TUS resource
*
* @param string $user
* @param string|null $resource
* @param string $spaceName
* @param array|null $headers
*
* @return void
* @throws Exception|GuzzleException
*/
public function createTusResource(string $user, ?string $resource, string $spaceName, ?array $headers = null): void {
$space = $this->spacesContext->getSpaceByName($user, $spaceName);
$fullUrl = $this->baseUrl . "/remote.php/dav/spaces/" . $space["id"];

$tusEndpoint = "tusEndpoint " . base64_encode(str_replace("$", "%", $fullUrl));
$fileName = "filename " . base64_encode($resource);
$headers = [
"Tus-Resumable" => "1.0.0",
"Upload-Metadata" => $tusEndpoint . ',' . $fileName,
"Upload-Length" => filesize($this->acceptanceTestsDirLocation() . $resource)
];
if ($headers === null) {
$fileName = "filename " . base64_encode($resource);
$headers = [
"Tus-Resumable" => "1.0.0",
"Upload-Metadata" => $tusEndpoint . ',' . $fileName,
"Upload-Length" => filesize($this->featureContext->acceptanceTestsDirLocation() . 'filesForUpload/' . $resource)
];
}
$this->featureContext->setResponse(
HttpRequestHelper::post(
$fullUrl,
Expand Down Expand Up @@ -159,7 +217,7 @@ public function uploadResourceThroughTUS(string $user, string $resource): void {
} else {
throw new \Exception(__METHOD__ . " Location header could not be found");
}
$file = \fopen($this->acceptanceTestsDirLocation() . $resource, 'r');
$file = \fopen($this->featureContext->acceptanceTestsDirLocation() . 'filesForUpload/' . $resource, 'r');

$this->featureContext->setResponse(
HttpRequestHelper::sendRequest(
Expand Down
Binary file removed tests/acceptance/filesForUpload/example.gif
Binary file not shown.
Binary file removed tests/acceptance/filesForUpload/qrcode.png
Binary file not shown.
Binary file removed tests/acceptance/filesForUpload/testavatar.jpg
Binary file not shown.

0 comments on commit 7f18716

Please sign in to comment.