Commit 3ab2fd90 authored by Sergio Bertolin's avatar Sergio Bertolin

Added deletion of comments and removed useless tests

parent 64d04947
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
/** /**
* @author Lukas Reschke <lukas@owncloud.com> * @author Lukas Reschke <lukas@owncloud.com>
* *
* @copyright Copyright (c) 2016, ownCloud, Inc. * @copyright Copyright (c) 2017, ownCloud, Gmbh.
* @license AGPL-3.0 * @license AGPL-3.0
* *
* This code is free software: you can redistribute it and/or modify * This code is free software: you can redistribute it and/or modify
...@@ -26,9 +26,10 @@ require __DIR__ . '/../../../../lib/composer/autoload.php'; ...@@ -26,9 +26,10 @@ require __DIR__ . '/../../../../lib/composer/autoload.php';
trait Comments { trait Comments {
use Sharing; use Sharing;
private $commentId;
/** @var int */ /** @var int */
private $fileId; private $lastCommentId;
/** @var int */
private $lastFileId;
/** /**
* @param string $path * @param string $path
...@@ -50,7 +51,7 @@ trait Comments { ...@@ -50,7 +51,7 @@ trait Comments {
*/ */
public function postsAComment($user, $content, $type, $path) { public function postsAComment($user, $content, $type, $path) {
$fileId = $this->getFileIdForPath($user, $path); $fileId = $this->getFileIdForPath($user, $path);
$this->fileId = $fileId; $this->lastFileId = $fileId;
$commentsPath = '/comments/files/' . $fileId . '/'; $commentsPath = '/comments/files/' . $fileId . '/';
try { try {
$this->response = $this->makeDavRequest($user, $this->response = $this->makeDavRequest($user,
...@@ -67,38 +68,14 @@ trait Comments { ...@@ -67,38 +68,14 @@ trait Comments {
"message":"' . $content . '", "message":"' . $content . '",
"creationDateTime":"Thu, 18 Feb 2016 17:04:18 GMT", "creationDateTime":"Thu, 18 Feb 2016 17:04:18 GMT",
"objectType":"files"}'); "objectType":"files"}');
$responseHeaders = $this->response->getHeaders();
$commentUrl = $responseHeaders['Content-Location'][0];
$this->lastCommentId = substr($commentUrl, strrpos($commentUrl,'/')+1);
} catch (\GuzzleHttp\Exception\ClientException $ex) { } catch (\GuzzleHttp\Exception\ClientException $ex) {
$this->response = $ex->getResponse(); $this->response = $ex->getResponse();
} }
} }
/**
* @Then /^As user "([^"]*)" gets all the comments of (file|folder) "([^"]*)"$/
* @param string $user
* @param string $path
* @param int $statusCode
* @throws \Exception
*/
public function getComments($user, $path, $statusCode) {
$fileId = $this->getFileIdForPath($path);
$commentsPath = 'comments/files/'.$fileId.'/';
try {
$properties = '<oc:limit>200</oc:limit>
<oc:offset>0</oc:offset>';
$commentList = $this->reportElementComments($user, $commentsPath, $properties);
} catch (\GuzzleHttp\Exception\ClientException $e) {
$res = $e->getResponse();
}
if($res->getStatusCode() !== (int)$statusCode) {
throw new \Exception("Response status code was not $statusCode (".$res->getStatusCode().")");
}
}
/** /**
* @Then /^user "([^"]*)" should have the following comments on (file|folder) "([^"]*)"$/ * @Then /^user "([^"]*)" should have the following comments on (file|folder) "([^"]*)"$/
* @param string $user * @param string $user
...@@ -136,37 +113,48 @@ trait Comments { ...@@ -136,37 +113,48 @@ trait Comments {
} }
/** /**
* @Then As :user delete the created comment it should return :statusCode * @Then /^user "([^"]*)" should have (\d+) comments on (file|folder) "([^"]*)"$/
* @param string $user * @param string $user
* @param int $statusCode * @param string $numberOfComments
* @throws \Exception * @param string $type
* @param string $path
*/ */
public function asDeleteTheCreatedCommentItShouldReturn($user, $statusCode) { public function checkNumberOfComments($user, $numberOfComments, $type, $path) {
$url = $this->baseUrl.'/remote.php/dav/comments/files/'.$this->fileId.'/'.$this->commentId; $fileId = $this->getFileIdForPath($user, $path);
$commentsPath = '/comments/files/' . $fileId . '/';
$client = new \GuzzleHttp\Client(); $properties = '<oc:limit>200</oc:limit><oc:offset>0</oc:offset>';
try { try{
$res = $client->delete( $elementList = $this->reportElementComments($user,$commentsPath,$properties);
$url, PHPUnit_Framework_Assert::assertEquals($numberOfComments, count($elementList));
[
'auth' => [
$user,
'123456',
],
'headers' => [
'Content-Type' => 'application/json',
],
]
);
} catch (\GuzzleHttp\Exception\ClientException $e) { } catch (\GuzzleHttp\Exception\ClientException $e) {
$res = $e->getResponse(); $this->response = $e->getResponse();
} }
}
if($res->getStatusCode() !== (int)$statusCode) { public function deleteComment($user, $id){
throw new \Exception("Response status code was not $statusCode (".$res->getStatusCode().")"); $commentsPath = '/comments/files/' . $this->lastFileId . '/' . $this->lastCommentId;
try {
$this->response = $this->makeDavRequest($user,
"DELETE",
$commentsPath,
[],
null,
"uploads",
null);
} catch (\GuzzleHttp\Exception\ClientException $ex) {
$this->response = $ex->getResponse();
} }
} }
/**
* @Then user :user deletes the last created comment
* @param string $user
* @throws \Exception
*/
public function userDeletesLastComment($user) {
$this->deleteComment($user, $this->lastCommentId);
}
/** /**
* @Then the response should contain a property :key with value :value * @Then the response should contain a property :key with value :value
* @param string $key * @param string $key
......
Feature: comments Feature: Comments
Background: Background:
Given using new dav path 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" And As an "user0"
Given User "user0" uploads file "data/textfile.txt" to "/myFileToComment.txt" And User "user0" uploads file "data/textfile.txt" to "/myFileToComment.txt"
When user "user0" posts a comment with content "My first comment" on file "/myFileToComment.txt" When user "user0" comments with content "My first comment" on file "/myFileToComment.txt"
Then user "user0" should have the following comments on file "/myFileToComment.txt"
Then As "user0" load all the comments of the file named "/myFileToComment.txt" it should return "207" | user0 | My first comment |
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 "My first comment"
And the response should contain a property "oc:actorDisplayName" with value "user0"
And the response should contain only "1" comments
Scenario: Creating a comment on a shared file belonging to another user Scenario: Creating a comment on a shared file belonging to another user
Given user "user0" exists Given user "user0" exists
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"
And user "user1" comments with content "A comment from another user" on file "/myFileToComment.txt" And user "user1" comments with content "A comment from sharee" on file "/myFileToComment.txt"
And user "user1" comments with content "BLABLABLAB" on file "/myFileToComment.txt" And user "user0" comments with content "A comment from sharer" on file "/myFileToComment.txt"
And the HTTP status code should be "201" And the HTTP status code should be "201"
Then user "user1" should have the following comments on file "/myFileToComment.txt" Then user "user1" should have the following comments on file "/myFileToComment.txt"
| user1 | A comment from another user | | user1 | A comment from sharee |
| user1 | BLABLABLAB | | user0 | A comment from sharer |
Scenario: Deleting my own comments on a file belonging to myself
Given user "user0" exists
And As an "user0"
And User "user0" uploads file "data/textfile.txt" to "/myFileToComment.txt"
And user "user0" comments with content "My first comment" on file "/myFileToComment.txt"
When user "user0" deletes the last created comment
Then the HTTP status code should be "204"
And user "user0" should have 0 comments on file "/myFileToComment.txt"
#Then As "user1" load all the comments of the file named "/myFileToComment.txt" it should return "207" Scenario: Deleting a comment on a file belonging to myself having several comments
# And the response should contain a property "oc:parentId" with value "0" Given user "user0" exists
# And the response should contain a property "oc:childrenCount" with value "0" And As an "user0"
And User "user0" uploads file "data/textfile.txt" to "/myFileToComment.txt"
And user "user0" comments with content "My first comment" on file "/myFileToComment.txt"
And user "user0" comments with content "My second comment" on file "/myFileToComment.txt"
And user "user0" comments with content "My third comment" on file "/myFileToComment.txt"
And user "user0" comments with content "My fourth comment" on file "/myFileToComment.txt"
When user "user0" deletes the last created comment
Then the HTTP status code should be "204"
And user "user0" should have 3 comments on file "/myFileToComment.txt"
# When As "user0" load all the comments of the file named "/myFileToComment.txt" it should return "207"
# Then the response should contain a property "oc:parentId" with value "0"
# Then 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:verb" with value "comment"
# And the response should contain a property "oc:actorType" with value "users" # 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: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:message" with value "My first comment"
# And the response should contain a property "oc:actorDisplayName" with value "user1" # And the response should contain a property "oc:actorDisplayName" with value "user0"
# And the response should contain only "1" comments # And the response should contain only "1" comments
# And As "user0" delete the created comment it should return "204"
Scenario: Creating a comment on a non-shared file belonging to another user # And As "user0" load all the comments of the file named "/myFileToComment.txt" it should return "207"
Given user "user0" exists # And the response should contain only "0" comments
Given user "user1" exists
Given User "user0" uploads file "data/textfile.txt" to "/myFileToComment.txt"
Then "user1" posts a comment with content "My first comment" on the file named "/myFileToComment.txt" it should return "404"
Scenario: Reading comments on a non-shared file belonging to another user
Given user "user0" exists
Given user "user1" exists
Given User "user0" uploads file "data/textfile.txt" to "/myFileToComment.txt"
Then As "user1" load all the comments of the file named "/myFileToComment.txt" it should return "404"
Scenario: Deleting my own comments 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"
Given "user0" posts a comment with content "My first comment" on the file named "/myFileToComment.txt" it should return "201"
When As "user0" load all the comments of the file named "/myFileToComment.txt" it should return "207"
Then the response should contain a property "oc:parentId" with value "0"
Then 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 "My first comment"
And the response should contain a property "oc:actorDisplayName" with value "user0"
And the response should contain only "1" comments
And As "user0" delete the created comment it should return "204"
And As "user0" load all the comments of the file named "/myFileToComment.txt" it should return "207"
And the response should contain only "0" comments
Scenario: Deleting my own comments on a file shared by somebody else Scenario: Deleting my own comments on a file shared by somebody else
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