server/tests/lib/Comments/CommentTest.php

126 lines
3.2 KiB
PHP
Raw Normal View History

<?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;
class CommentTest extends TestCase {
public function testSettersValidInput() {
$comment = new \OC\Comments\Comment();
$id = 'comment23';
$parentId = 'comment11.5';
$topMostParentId = 'comment11.0';
$childrenCount = 6;
$message = 'I like to comment comment';
$verb = 'comment';
2016-02-03 18:28:15 +00:00
$actor = ['type' => 'users', 'id' => 'alice'];
$creationDT = new \DateTime();
$latestChildDT = new \DateTime('yesterday');
2016-02-03 18:28:15 +00:00
$object = ['type' => 'files', 'id' => 'file64'];
$comment
->setId($id)
->setParentId($parentId)
->setTopmostParentId($topMostParentId)
->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());
$this->assertSame($topMostParentId, $comment->getTopmostParentId());
$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());
}
/**
* @expectedException \OCP\Comments\IllegalIDChangeException
*/
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('');
$this->assertSame('', $comment->getId());
}
public function simpleSetterProvider() {
return [
['Id', true],
['TopmostParentId', true],
['ParentId', true],
['Message', true],
['Verb', true],
['Verb', ''],
['ChildrenCount', true],
];
}
/**
* @dataProvider simpleSetterProvider
* @expectedException \InvalidArgumentException
*/
public function testSimpleSetterInvalidInput($field, $input) {
$comment = new \OC\Comments\Comment();
$setter = 'set' . $field;
$comment->$setter($input);
}
public function roleSetterProvider() {
return [
['Actor', true, true],
2016-02-03 18:28:15 +00:00
['Actor', 'users', true],
['Actor', true, 'alice'],
['Actor', ' ', ' '],
['Object', true, true],
2016-02-03 18:28:15 +00:00
['Object', 'files', true],
['Object', true, 'file64'],
['Object', ' ', ' '],
];
}
/**
* @dataProvider roleSetterProvider
* @expectedException \InvalidArgumentException
*/
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);
}
}