2015-11-24 01:53:55 +03:00
|
|
|
<?php
|
|
|
|
|
2015-12-03 19:23:22 +03:00
|
|
|
namespace Test\Comments;
|
|
|
|
|
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
class Test_Comments_Comment extends TestCase
|
2015-11-24 01:53:55 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
public function testSettersValidInput() {
|
|
|
|
$comment = new \OC\Comments\Comment();
|
|
|
|
|
|
|
|
$id = 'comment23';
|
|
|
|
$parentId = 'comment11.5';
|
|
|
|
$childrenCount = 6;
|
|
|
|
$message = 'I like to comment comment';
|
|
|
|
$verb = 'comment';
|
|
|
|
$actor = ['type' => 'user', 'id' => 'alice'];
|
|
|
|
$creationDT = new \DateTime();
|
|
|
|
$latestChildDT = new \DateTime('yesterday');
|
|
|
|
$object = ['type' => 'file', 'id' => 'file64'];
|
|
|
|
|
|
|
|
$comment
|
|
|
|
->setId($id)
|
|
|
|
->setParentId($parentId)
|
|
|
|
->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($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 18:55:07 +03:00
|
|
|
/**
|
|
|
|
* @expectedException \OCP\Comments\IllegalIDChangeException
|
|
|
|
*/
|
2015-11-24 01:53:55 +03: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 11:29:24 +03:00
|
|
|
|
|
|
|
$this->assertSame('', $comment->getId());
|
2015-11-24 01:53:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function simpleSetterProvider() {
|
|
|
|
return [
|
2015-12-04 13:13:39 +03:00
|
|
|
['Id', true],
|
|
|
|
['ParentId', true],
|
|
|
|
['Message', true],
|
|
|
|
['Verb', true],
|
|
|
|
['Verb', ''],
|
|
|
|
['ChildrenCount', true],
|
2015-11-24 01:53:55 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider simpleSetterProvider
|
2015-12-09 18:55:07 +03:00
|
|
|
* @expectedException \InvalidArgumentException
|
2015-11-24 01:53:55 +03:00
|
|
|
*/
|
2015-12-04 13:13:39 +03:00
|
|
|
public function testSimpleSetterInvalidInput($field, $input) {
|
2015-11-24 01:53:55 +03:00
|
|
|
$comment = new \OC\Comments\Comment();
|
|
|
|
$setter = 'set' . $field;
|
|
|
|
|
2015-12-04 13:13:39 +03:00
|
|
|
$comment->$setter($input);
|
2015-11-24 01:53:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function roleSetterProvider() {
|
|
|
|
return [
|
|
|
|
['Actor', true, true],
|
|
|
|
['Actor', 'user', true],
|
|
|
|
['Actor', true, 'alice'],
|
2015-12-04 13:13:39 +03:00
|
|
|
['Actor', ' ', ' '],
|
2015-11-24 01:53:55 +03:00
|
|
|
['Object', true, true],
|
|
|
|
['Object', 'file', true],
|
|
|
|
['Object', true, 'file64'],
|
2015-12-04 13:13:39 +03:00
|
|
|
['Object', ' ', ' '],
|
2015-11-24 01:53:55 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider roleSetterProvider
|
2015-12-09 18:55:07 +03:00
|
|
|
* @expectedException \InvalidArgumentException
|
2015-11-24 01:53:55 +03:00
|
|
|
*/
|
|
|
|
public function testSetRoleInvalidInput($role, $type, $id){
|
|
|
|
$comment = new \OC\Comments\Comment();
|
|
|
|
$setter = 'set' . $role;
|
|
|
|
$comment->$setter($type, $id);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|