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 { ...@@ -72,60 +72,41 @@ trait Comments {
* @param string $path * @param string $path
* @return int * @return int
*/ */
private function getFileIdForPath($path) { private function getFileIdForPath($user, $path) {
$url = $this->baseUrl.'/remote.php/webdav/'.$path; $propertiesTable = new \Behat\Gherkin\Node\TableNode([["{http://owncloud.org/ns}fileid"]]);
$context = stream_context_create([ $this->asGetsPropertiesOfFolderWith($user, 'file', $path, $propertiesTable);
'http' => [ return (int) $this->response['{http://owncloud.org/ns}fileid'];
'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];
} }
/** /**
* @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 $user
* @param string $content * @param string $content
* @param string $fileName * @param string $type
* @param int $statusCode * @param string $path
* @throws \Exception * @throws \Exception
*/ */
public function postsACommentWithContentOnTheFileNamedItShouldReturn($user, $content, $fileName, $statusCode) { public function postsAComment($user, $content, $type, $path) {
$fileId = $this->getFileIdForPath($fileName); $fileId = $this->getFileIdForPath($user, $path);
$this->fileId = (int)$fileId; $this->fileId = $fileId;
$url = $this->baseUrl.'/remote.php/dav/comments/files/'.$fileId.'/'; $commentsPath = '/comments/files/' . $fileId . '/';
$client = new \GuzzleHttp\Client();
try { try {
$res = $client->post( $this->response = $this->makeDavRequest($user,
$url, "POST",
[ $commentsPath,
'body' => '{"actorId":"user0","actorDisplayName":"user0","actorType":"users","verb":"comment","message":"' . $content . '","creationDateTime":"Thu, 18 Feb 2016 17:04:18 GMT","objectType":"files"}', ['Content-Type' => 'application/json',
'auth' => [ ],
$user, null,
'123456', "uploads",
], '{"actorId":"user0",
'headers' => [ "actorDisplayName":"user0",
'Content-Type' => 'application/json', "actorType":"users",
], "verb":"comment",
] "message":"' . $content . '",
); "creationDateTime":"Thu, 18 Feb 2016 17:04:18 GMT",
} catch (\GuzzleHttp\Exception\ClientException $e) { "objectType":"files"}');
$res = $e->getResponse(); } catch (\GuzzleHttp\Exception\ClientException $ex) {
} $this->response = $ex->getResponse();
if($res->getStatusCode() !== (int)$statusCode) {
throw new \Exception("Response status code was not $statusCode (".$res->getStatusCode().")");
} }
} }
......
...@@ -51,14 +51,24 @@ trait WebDav { ...@@ -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" ){ if ( $type === "files" ){
$fullUrl = substr($this->baseUrl, 0, -4) . $this->getDavFilesPath($user) . "$path"; $fullUrl = substr($this->baseUrl, 0, -4) . $this->getDavFilesPath($user) . "$path";
} else if ( $type === "uploads" ){ } else if ( $type === "uploads" ){
$fullUrl = substr($this->baseUrl, 0, -4) . $this->davPath . "$path"; $fullUrl = substr($this->baseUrl, 0, -4) . $this->davPath . "$path";
} }
$client = new GClient(); $client = new GClient();
$options = []; $options = [];
if (!is_null($requestBody)){
$options['body'] = $requestBody;
}
if ($user === 'admin') { if ($user === 'admin') {
$options['auth'] = $this->adminUser; $options['auth'] = $this->adminUser;
} else { } else {
......
Feature: comments Feature: comments
Background:
Given using new dav path
Scenario: Creating a comment on a file belonging to myself Scenario: Creating a comment on a file belonging to myself
Given user "user0" exists Given user "user0" exists
Given As an "user0" Given As an "user0"
Given User "user0" uploads file "data/textfile.txt" to "/myFileToComment.txt" 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" 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:parentId" with value "0"
And the response should contain a property "oc:childrenCount" with value "0" And the response should contain a property "oc:childrenCount" with value "0"
...@@ -20,16 +23,17 @@ Feature: comments ...@@ -20,16 +23,17 @@ Feature: comments
And user "user1" exists And user "user1" exists
And User "user0" uploads file "data/textfile.txt" to "/myFileToComment.txt" And User "user0" uploads file "data/textfile.txt" to "/myFileToComment.txt"
And file "/myFileToComment.txt" of user "user0" is shared with user "user1" 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" And user "user1" comments with content "A comment from another user" on file "/myFileToComment.txt"
Then As "user1" load all the comments of the file named "/myFileToComment.txt" it should return "207" And the HTTP status code should be "201"
And the response should contain a property "oc:parentId" with value "0" #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:childrenCount" with value "0" # And the response should contain a property "oc:parentId" with value "0"
And the response should contain a property "oc:verb" with value "comment" # And the response should contain a property "oc:childrenCount" with value "0"
And the response should contain a property "oc:actorType" with value "users" # And the response should contain a property "oc:verb" with value "comment"
And the response should contain a property "oc:objectType" with value "files" # And the response should contain a property "oc:actorType" with value "users"
And the response should contain a property "oc:message" with value "A comment from another user" # And the response should contain a property "oc:objectType" with value "files"
And the response should contain a property "oc:actorDisplayName" with value "user1" # And the response should contain a property "oc:message" with value "A comment from another user"
And the response should contain only "1" comments # 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 Scenario: Creating a comment on a non-shared file belonging to another user
Given user "user0" exists 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