Commit 1050ab0d authored by Sergio Bertolin's avatar Sergio Bertolin

Changed getting id and post a comment

parent eef37109
......@@ -72,60 +72,41 @@ trait Comments {
* @param string $path
* @return int
*/
private function getFileIdForPath($path) {
$url = $this->baseUrl.'/remote.php/webdav/'.$path;
$context = stream_context_create([
'http' => [
'method' => 'PROPFIND',
'header' => "Authorization: Basic dXNlcjA6MTIzNDU2\r\nContent-Type: application/x-www-form-urlencoded",
'content' => '<?xml version="1.0"?>
<d:propfind xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns">
<d:prop>
<oc:fileid />
</d:prop>
</d:propfind>'
]
]);
$response = file_get_contents($url, false, $context);
preg_match_all('/\<oc:fileid\>(.*)\<\/oc:fileid\>/', $response, $matches);
return (int)$matches[1][0];
private function getFileIdForPath($user, $path) {
$propertiesTable = new \Behat\Gherkin\Node\TableNode([["{http://owncloud.org/ns}fileid"]]);
$this->asGetsPropertiesOfFolderWith($user, 'file', $path, $propertiesTable);
return (int) $this->response['{http://owncloud.org/ns}fileid'];
}
/**
* @When :user posts a comment with content :content on the file named :fileName it should return :statusCode
* @When /^user "([^"]*)" comments with content "([^"]*)" on (file|folder) "([^"]*)"$/
* @param string $user
* @param string $content
* @param string $fileName
* @param int $statusCode
* @param string $type
* @param string $path
* @throws \Exception
*/
public function postsACommentWithContentOnTheFileNamedItShouldReturn($user, $content, $fileName, $statusCode) {
$fileId = $this->getFileIdForPath($fileName);
$this->fileId = (int)$fileId;
$url = $this->baseUrl.'/remote.php/dav/comments/files/'.$fileId.'/';
$client = new \GuzzleHttp\Client();
public function postsAComment($user, $content, $type, $path) {
$fileId = $this->getFileIdForPath($user, $path);
$this->fileId = $fileId;
$commentsPath = '/comments/files/' . $fileId . '/';
try {
$res = $client->post(
$url,
[
'body' => '{"actorId":"user0","actorDisplayName":"user0","actorType":"users","verb":"comment","message":"' . $content . '","creationDateTime":"Thu, 18 Feb 2016 17:04:18 GMT","objectType":"files"}',
'auth' => [
$user,
'123456',
],
'headers' => [
'Content-Type' => 'application/json',
],
]
);
} catch (\GuzzleHttp\Exception\ClientException $e) {
$res = $e->getResponse();
}
if($res->getStatusCode() !== (int)$statusCode) {
throw new \Exception("Response status code was not $statusCode (".$res->getStatusCode().")");
$this->response = $this->makeDavRequest($user,
"POST",
$commentsPath,
['Content-Type' => 'application/json',
],
null,
"uploads",
'{"actorId":"user0",
"actorDisplayName":"user0",
"actorType":"users",
"verb":"comment",
"message":"' . $content . '",
"creationDateTime":"Thu, 18 Feb 2016 17:04:18 GMT",
"objectType":"files"}');
} catch (\GuzzleHttp\Exception\ClientException $ex) {
$this->response = $ex->getResponse();
}
}
......
......@@ -51,14 +51,24 @@ trait WebDav {
}
}
public function makeDavRequest($user, $method, $path, $headers, $body = null, $type = "files"){
public function makeDavRequest($user,
$method,
$path,
$headers,
$body = null,
$type = "files",
$requestBody = null){
if ( $type === "files" ){
$fullUrl = substr($this->baseUrl, 0, -4) . $this->getDavFilesPath($user) . "$path";
} else if ( $type === "uploads" ){
$fullUrl = substr($this->baseUrl, 0, -4) . $this->davPath . "$path";
}
$client = new GClient();
$options = [];
if (!is_null($requestBody)){
$options['body'] = $requestBody;
}
if ($user === 'admin') {
$options['auth'] = $this->adminUser;
} else {
......
Feature: comments
Background:
Given using new dav path
Scenario: Creating a comment on a file belonging to myself
Given user "user0" exists
Given As an "user0"
Given User "user0" uploads file "data/textfile.txt" to "/myFileToComment.txt"
When "user0" posts a comment with content "My first comment" on the file named "/myFileToComment.txt" it should return "201"
When user "user0" posts a comment with content "My first comment" on file "/myFileToComment.txt"
Then As "user0" load all the comments of the file named "/myFileToComment.txt" it should return "207"
And the response should contain a property "oc:parentId" with value "0"
And the response should contain a property "oc:childrenCount" with value "0"
......@@ -20,16 +23,17 @@ Feature: comments
And user "user1" exists
And User "user0" uploads file "data/textfile.txt" to "/myFileToComment.txt"
And file "/myFileToComment.txt" of user "user0" is shared with user "user1"
When "user1" posts a comment with content "A comment from another user" on the file named "/myFileToComment.txt" it should return "201"
Then As "user1" load all the comments of the file named "/myFileToComment.txt" it should return "207"
And the response should contain a property "oc:parentId" with value "0"
And the response should contain a property "oc:childrenCount" with value "0"
And the response should contain a property "oc:verb" with value "comment"
And the response should contain a property "oc:actorType" with value "users"
And the response should contain a property "oc:objectType" with value "files"
And the response should contain a property "oc:message" with value "A comment from another user"
And the response should contain a property "oc:actorDisplayName" with value "user1"
And the response should contain only "1" comments
And user "user1" comments with content "A comment from another user" on file "/myFileToComment.txt"
And the HTTP status code should be "201"
#Then As "user1" load all the comments of the file named "/myFileToComment.txt" it should return "207"
# And the response should contain a property "oc:parentId" with value "0"
# And the response should contain a property "oc:childrenCount" with value "0"
# And the response should contain a property "oc:verb" with value "comment"
# And the response should contain a property "oc:actorType" with value "users"
# And the response should contain a property "oc:objectType" with value "files"
# And the response should contain a property "oc:message" with value "A comment from another user"
# And the response should contain a property "oc:actorDisplayName" with value "user1"
# And the response should contain only "1" comments
Scenario: Creating a comment on a non-shared file belonging to another user
Given user "user0" exists
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment