2015-11-23 22:53:55 +00:00
|
|
|
<?php
|
|
|
|
|
2015-12-03 16:23:22 +00:00
|
|
|
namespace Test\Comments;
|
|
|
|
|
2016-02-09 02:14:30 +00:00
|
|
|
use OCP\Comments\IComment;
|
2015-12-03 16:23:22 +00:00
|
|
|
use Test\TestCase;
|
|
|
|
|
2016-05-18 16:55:44 +00:00
|
|
|
class CommentTest extends TestCase {
|
2015-11-23 22:53:55 +00:00
|
|
|
|
|
|
|
public function testSettersValidInput() {
|
|
|
|
$comment = new \OC\Comments\Comment();
|
|
|
|
|
|
|
|
$id = 'comment23';
|
|
|
|
$parentId = 'comment11.5';
|
2016-09-29 20:41:37 +00:00
|
|
|
$topMostParentId = 'comment11.0';
|
2015-11-23 22:53:55 +00:00
|
|
|
$childrenCount = 6;
|
|
|
|
$message = 'I like to comment comment';
|
|
|
|
$verb = 'comment';
|
2016-02-03 18:28:15 +00:00
|
|
|
$actor = ['type' => 'users', 'id' => 'alice'];
|
2015-11-23 22:53:55 +00:00
|
|
|
$creationDT = new \DateTime();
|
|
|
|
$latestChildDT = new \DateTime('yesterday');
|
2016-02-03 18:28:15 +00:00
|
|
|
$object = ['type' => 'files', 'id' => 'file64'];
|
2015-11-23 22:53:55 +00:00
|
|
|
|
|
|
|
$comment
|
|
|
|
->setId($id)
|
|
|
|
->setParentId($parentId)
|
2016-09-29 20:41:37 +00:00
|
|
|
->setTopmostParentId($topMostParentId)
|
2015-11-23 22:53:55 +00:00
|
|
|
->setChildrenCount($childrenCount)
|
|
|
|
->setMessage($message)
|
|
|
|
->setVerb($verb)
|
|
|
|
->setActor($actor['type'], $actor['id'])
|
|
|
|
->setCreationDateTime($creationDT)
|
|
|
|
->setLatestChildDateTime($latestChildDT)
|
|
|
|
->setObject($object['type'], $object['id']);
|
|
|
|
|
|
|
|
$this->assertSame($id, $comment->getId());
|
|
|
|
$this->assertSame($parentId, $comment->getParentId());
|
2016-09-29 20:41:37 +00:00
|
|
|
$this->assertSame($topMostParentId, $comment->getTopmostParentId());
|
2015-11-23 22:53:55 +00:00
|
|
|
$this->assertSame($childrenCount, $comment->getChildrenCount());
|
|
|
|
$this->assertSame($message, $comment->getMessage());
|
|
|
|
$this->assertSame($verb, $comment->getVerb());
|
|
|
|
$this->assertSame($actor['type'], $comment->getActorType());
|
|
|
|
$this->assertSame($actor['id'], $comment->getActorId());
|
|
|
|
$this->assertSame($creationDT, $comment->getCreationDateTime());
|
|
|
|
$this->assertSame($latestChildDT, $comment->getLatestChildDateTime());
|
|
|
|
$this->assertSame($object['type'], $comment->getObjectType());
|
|
|
|
$this->assertSame($object['id'], $comment->getObjectId());
|
|
|
|
}
|
|
|
|
|
2015-12-09 15:55:07 +00:00
|
|
|
/**
|
|
|
|
* @expectedException \OCP\Comments\IllegalIDChangeException
|
|
|
|
*/
|
2015-11-23 22:53:55 +00:00
|
|
|
public function testSetIdIllegalInput() {
|
|
|
|
$comment = new \OC\Comments\Comment();
|
|
|
|
|
|
|
|
$comment->setId('c23');
|
|
|
|
$comment->setId('c17');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testResetId() {
|
|
|
|
$comment = new \OC\Comments\Comment();
|
|
|
|
$comment->setId('c23');
|
|
|
|
$comment->setId('');
|
2015-12-10 08:29:24 +00:00
|
|
|
|
|
|
|
$this->assertSame('', $comment->getId());
|
2015-11-23 22:53:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function simpleSetterProvider() {
|
|
|
|
return [
|
2015-12-04 10:13:39 +00:00
|
|
|
['Id', true],
|
2016-09-29 20:41:37 +00:00
|
|
|
['TopmostParentId', true],
|
2015-12-04 10:13:39 +00:00
|
|
|
['ParentId', true],
|
|
|
|
['Message', true],
|
|
|
|
['Verb', true],
|
|
|
|
['Verb', ''],
|
|
|
|
['ChildrenCount', true],
|
2015-11-23 22:53:55 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider simpleSetterProvider
|
2015-12-09 15:55:07 +00:00
|
|
|
* @expectedException \InvalidArgumentException
|
2015-11-23 22:53:55 +00:00
|
|
|
*/
|
2015-12-04 10:13:39 +00:00
|
|
|
public function testSimpleSetterInvalidInput($field, $input) {
|
2015-11-23 22:53:55 +00:00
|
|
|
$comment = new \OC\Comments\Comment();
|
|
|
|
$setter = 'set' . $field;
|
|
|
|
|
2015-12-04 10:13:39 +00:00
|
|
|
$comment->$setter($input);
|
2015-11-23 22:53:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function roleSetterProvider() {
|
|
|
|
return [
|
|
|
|
['Actor', true, true],
|
2016-02-03 18:28:15 +00:00
|
|
|
['Actor', 'users', true],
|
2015-11-23 22:53:55 +00:00
|
|
|
['Actor', true, 'alice'],
|
2015-12-04 10:13:39 +00:00
|
|
|
['Actor', ' ', ' '],
|
2015-11-23 22:53:55 +00:00
|
|
|
['Object', true, true],
|
2016-02-03 18:28:15 +00:00
|
|
|
['Object', 'files', true],
|
2015-11-23 22:53:55 +00:00
|
|
|
['Object', true, 'file64'],
|
2015-12-04 10:13:39 +00:00
|
|
|
['Object', ' ', ' '],
|
2015-11-23 22:53:55 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider roleSetterProvider
|
2015-12-09 15:55:07 +00:00
|
|
|
* @expectedException \InvalidArgumentException
|
2015-11-23 22:53:55 +00:00
|
|
|
*/
|
|
|
|
public function testSetRoleInvalidInput($role, $type, $id){
|
|
|
|
$comment = new \OC\Comments\Comment();
|
|
|
|
$setter = 'set' . $role;
|
|
|
|
$comment->$setter($type, $id);
|
|
|
|
}
|
|
|
|
|
2016-02-09 02:14:30 +00:00
|
|
|
/**
|
|
|
|
* @expectedException \OCP\Comments\MessageTooLongException
|
|
|
|
*/
|
|
|
|
public function testSetUberlongMessage() {
|
|
|
|
$comment = new \OC\Comments\Comment();
|
|
|
|
$msg = str_pad('', IComment::MAX_MESSAGE_LENGTH + 1, 'x');
|
|
|
|
$comment->setMessage($msg);
|
|
|
|
}
|
|
|
|
|
2015-11-23 22:53:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
}
|