CommentTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace Test\Comments;
  3. use OCP\Comments\IComment;
  4. use Test\TestCase;
  5. class CommentTest extends TestCase {
  6. public function testSettersValidInput() {
  7. $comment = new \OC\Comments\Comment();
  8. $id = 'comment23';
  9. $parentId = 'comment11.5';
  10. $childrenCount = 6;
  11. $message = 'I like to comment comment';
  12. $verb = 'comment';
  13. $actor = ['type' => 'users', 'id' => 'alice'];
  14. $creationDT = new \DateTime();
  15. $latestChildDT = new \DateTime('yesterday');
  16. $object = ['type' => 'files', 'id' => 'file64'];
  17. $comment
  18. ->setId($id)
  19. ->setParentId($parentId)
  20. ->setChildrenCount($childrenCount)
  21. ->setMessage($message)
  22. ->setVerb($verb)
  23. ->setActor($actor['type'], $actor['id'])
  24. ->setCreationDateTime($creationDT)
  25. ->setLatestChildDateTime($latestChildDT)
  26. ->setObject($object['type'], $object['id']);
  27. $this->assertSame($id, $comment->getId());
  28. $this->assertSame($parentId, $comment->getParentId());
  29. $this->assertSame($childrenCount, $comment->getChildrenCount());
  30. $this->assertSame($message, $comment->getMessage());
  31. $this->assertSame($verb, $comment->getVerb());
  32. $this->assertSame($actor['type'], $comment->getActorType());
  33. $this->assertSame($actor['id'], $comment->getActorId());
  34. $this->assertSame($creationDT, $comment->getCreationDateTime());
  35. $this->assertSame($latestChildDT, $comment->getLatestChildDateTime());
  36. $this->assertSame($object['type'], $comment->getObjectType());
  37. $this->assertSame($object['id'], $comment->getObjectId());
  38. }
  39. /**
  40. * @expectedException \OCP\Comments\IllegalIDChangeException
  41. */
  42. public function testSetIdIllegalInput() {
  43. $comment = new \OC\Comments\Comment();
  44. $comment->setId('c23');
  45. $comment->setId('c17');
  46. }
  47. public function testResetId() {
  48. $comment = new \OC\Comments\Comment();
  49. $comment->setId('c23');
  50. $comment->setId('');
  51. $this->assertSame('', $comment->getId());
  52. }
  53. public function simpleSetterProvider() {
  54. return [
  55. ['Id', true],
  56. ['ParentId', true],
  57. ['Message', true],
  58. ['Verb', true],
  59. ['Verb', ''],
  60. ['ChildrenCount', true],
  61. ];
  62. }
  63. /**
  64. * @dataProvider simpleSetterProvider
  65. * @expectedException \InvalidArgumentException
  66. */
  67. public function testSimpleSetterInvalidInput($field, $input) {
  68. $comment = new \OC\Comments\Comment();
  69. $setter = 'set' . $field;
  70. $comment->$setter($input);
  71. }
  72. public function roleSetterProvider() {
  73. return [
  74. ['Actor', true, true],
  75. ['Actor', 'users', true],
  76. ['Actor', true, 'alice'],
  77. ['Actor', ' ', ' '],
  78. ['Object', true, true],
  79. ['Object', 'files', true],
  80. ['Object', true, 'file64'],
  81. ['Object', ' ', ' '],
  82. ];
  83. }
  84. /**
  85. * @dataProvider roleSetterProvider
  86. * @expectedException \InvalidArgumentException
  87. */
  88. public function testSetRoleInvalidInput($role, $type, $id){
  89. $comment = new \OC\Comments\Comment();
  90. $setter = 'set' . $role;
  91. $comment->$setter($type, $id);
  92. }
  93. /**
  94. * @expectedException \OCP\Comments\MessageTooLongException
  95. */
  96. public function testSetUberlongMessage() {
  97. $comment = new \OC\Comments\Comment();
  98. $msg = str_pad('', IComment::MAX_MESSAGE_LENGTH + 1, 'x');
  99. $comment->setMessage($msg);
  100. }
  101. }