|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of Sulu. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) MASSIVE ART WebServices GmbH |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the MIT license that is bundled |
|
9
|
|
|
* with this source code in the file LICENSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Functional\Controller; |
|
13
|
|
|
|
|
14
|
|
|
use Sulu\Bundle\CommentBundle\Entity\CommentInterface; |
|
15
|
|
|
use Sulu\Bundle\TestBundle\Testing\SuluTestCase; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Functional test-cases for website api. |
|
19
|
|
|
*/ |
|
20
|
|
|
class WebsiteCommentControllerTest extends SuluTestCase |
|
21
|
|
|
{ |
|
22
|
|
|
protected function setUp() |
|
23
|
|
|
{ |
|
24
|
|
|
$this->purgeDatabase(); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function providePostData() |
|
28
|
|
|
{ |
|
29
|
|
|
return [ |
|
30
|
|
|
[], |
|
31
|
|
|
['article', '123-123-123'], |
|
32
|
|
|
]; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @dataProvider providePostData |
|
37
|
|
|
*/ |
|
38
|
|
|
public function testPostComment( |
|
39
|
|
|
$type = 'blog', |
|
40
|
|
|
$entityId = '1', |
|
41
|
|
|
$message = 'Sulu is awesome', |
|
42
|
|
|
$threadTitle = 'Test Thread' |
|
43
|
|
|
) { |
|
44
|
|
|
$client = $this->createWebsiteClient(); |
|
45
|
|
|
$client->request( |
|
46
|
|
|
'POST', |
|
47
|
|
|
'_api/threads/' . $type . '-' . $entityId . '/comments.json', |
|
48
|
|
|
['message' => $message, 'threadTitle' => $threadTitle] |
|
49
|
|
|
); |
|
50
|
|
|
|
|
51
|
|
|
$this->assertHttpStatusCode(200, $client->getResponse()); |
|
52
|
|
|
|
|
53
|
|
|
$response = json_decode($client->getResponse()->getContent(), true); |
|
54
|
|
|
|
|
55
|
|
|
$this->assertEquals(CommentInterface::STATE_PUBLISHED, $response['state']); |
|
56
|
|
|
$this->assertEquals($message, $response['message']); |
|
57
|
|
|
$this->assertEquals($threadTitle, $response['thread']['title']); |
|
58
|
|
|
|
|
59
|
|
|
$thread = $this->getContainer()->get('sulu.repository.thread')->findThread($type, $entityId); |
|
60
|
|
|
$this->assertEquals($type, $thread->getType()); |
|
61
|
|
|
$this->assertEquals($entityId, $thread->getEntityId()); |
|
62
|
|
|
$this->assertEquals(1, $thread->getCommentCount()); |
|
63
|
|
|
$this->assertCount(1, $thread->getComments()); |
|
64
|
|
|
|
|
65
|
|
|
return $thread; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function providePostAuditableData() |
|
69
|
|
|
{ |
|
70
|
|
|
return [ |
|
71
|
|
|
['created'], |
|
72
|
|
|
['creator'], |
|
73
|
|
|
['changed'], |
|
74
|
|
|
['changer'], |
|
75
|
|
|
]; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @dataProvider providePostAuditableData |
|
80
|
|
|
*/ |
|
81
|
|
|
public function testPostAuditable($field, $type = 'blog', $entityId = '1') |
|
82
|
|
|
{ |
|
83
|
|
|
$client = $this->createWebsiteClient(); |
|
84
|
|
|
$client->request( |
|
85
|
|
|
'POST', |
|
86
|
|
|
'_api/threads/' . $type . '-' . $entityId . '/comments.json', |
|
87
|
|
|
['message' => 'Sulu is awesome', 'threadTitle' => 'Test Thread', $field => 1] |
|
88
|
|
|
); |
|
89
|
|
|
|
|
90
|
|
|
$this->assertHttpStatusCode(400, $client->getResponse()); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function testPostCommentMultiple($type = 'blog', $entityId = '1') |
|
94
|
|
|
{ |
|
95
|
|
|
$thread1 = $this->testPostComment($type, $entityId); |
|
96
|
|
|
$thread2 = $this->testPostComment($type, $entityId); |
|
97
|
|
|
|
|
98
|
|
|
$this->assertEquals($thread1->getId(), $thread2->getId()); |
|
99
|
|
|
|
|
100
|
|
|
return $thread1; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function testPostCommentDifferent($type = 'blog', $entityId = '1') |
|
104
|
|
|
{ |
|
105
|
|
|
$thread1 = $this->testPostComment($type, $entityId); |
|
106
|
|
|
$thread2 = $this->testPostComment('article', '123-123-123'); |
|
107
|
|
|
|
|
108
|
|
|
$this->assertNotEquals($thread1->getId(), $thread2->getId()); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
public function testGetComments($type = 'blog', $entityId = '1') |
|
112
|
|
|
{ |
|
113
|
|
|
$this->testPostComment($type, $entityId); |
|
114
|
|
|
sleep(1); |
|
115
|
|
|
$this->testPostComment($type, $entityId, 'My new Comment'); |
|
116
|
|
|
$this->testPostComment('article', '123-123-123'); |
|
117
|
|
|
|
|
118
|
|
|
$client = $this->createWebsiteClient(); |
|
119
|
|
|
$client->request( |
|
120
|
|
|
'GET', |
|
121
|
|
|
'_api/threads/' . $type . '-' . $entityId . '/comments.json' |
|
122
|
|
|
); |
|
123
|
|
|
|
|
124
|
|
|
$this->assertHttpStatusCode(200, $client->getResponse()); |
|
125
|
|
|
|
|
126
|
|
|
$response = json_decode($client->getResponse()->getContent(), true); |
|
127
|
|
|
$this->assertCount(2, $response); |
|
128
|
|
|
$this->assertEquals(CommentInterface::STATE_PUBLISHED, $response[0]['state']); |
|
129
|
|
|
$this->assertEquals('My new Comment', $response[0]['message']); |
|
130
|
|
|
$this->assertEquals(CommentInterface::STATE_PUBLISHED, $response[1]['state']); |
|
131
|
|
|
$this->assertEquals('Sulu is awesome', $response[1]['message']); |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|