summaryrefslogtreecommitdiffstats
path: root/tests/lib/comments/comment.php
blob: 02adea8729ef31ae4c38f2b4ee544c489bd78c30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php

namespace Test\Comments;

use Test\TestCase;

class Test_Comments_Comment extends TestCase
{

	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());
	}

	/**
	 * @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],
			['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],
			['Actor', 'user', true],
			['Actor', true, 'alice'],
			['Actor', ' ', ' '],
			['Object', true, true],
			['Object', 'file', 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);
	}



}