|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the CCDNForum ForumBundle |
|
5
|
|
|
* |
|
6
|
|
|
* (c) CCDN (c) CodeConsortium <http://www.codeconsortium.com/> |
|
7
|
|
|
* |
|
8
|
|
|
* Available on github <http://www.github.com/codeconsortium/> |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace CCDNForum\ForumBundle\Tests\Manager; |
|
15
|
|
|
|
|
16
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
17
|
|
|
use CCDNForum\ForumBundle\Tests\TestBase; |
|
18
|
|
|
|
|
19
|
|
|
class TopicManagerTest extends TestBase |
|
20
|
|
|
{ |
|
21
|
|
|
public function testSaveTopic() |
|
22
|
|
|
{ |
|
23
|
|
|
$this->purge(); |
|
24
|
|
|
$users = $this->addFixturesForUsers(); |
|
25
|
|
|
$topic = $this->addNewTopic('NewTopicTest', null, false, false); |
|
26
|
|
|
$post = $this->addNewPost('foobar', $topic, $users['tom'], new \DateTime(), false, false); |
|
27
|
|
|
$this->getTopicModel()->saveTopic($topic); |
|
28
|
|
|
$this->getPostModel()->savePost($post); |
|
29
|
|
|
$foundTopic = $this->getTopicModel()->findOneTopicByIdWithBoardAndCategory($topic->getId(), true); |
|
30
|
|
|
|
|
31
|
|
|
$this->assertNotNull($foundTopic); |
|
32
|
|
|
$this->assertInstanceOf('CCDNForum\ForumBundle\Entity\Topic', $foundTopic); |
|
33
|
|
|
$this->assertTrue(is_numeric($foundTopic->getId())); |
|
34
|
|
|
$this->assertSame('NewTopicTest', $foundTopic->getTitle()); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function testUpdateTopic() |
|
38
|
|
|
{ |
|
39
|
|
|
$this->purge(); |
|
40
|
|
|
$users = $this->addFixturesForUsers(); |
|
41
|
|
|
$forums = $this->addFixturesForForums(); |
|
42
|
|
|
$categories = $this->addFixturesForCategories($forums); |
|
43
|
|
|
$boards = $this->addFixturesForBoards($categories); |
|
44
|
|
|
$topics = $this->addFixturesForTopics($boards); |
|
45
|
|
|
$this->addFixturesForPosts($topics, $users['tom']); |
|
46
|
|
|
$topics[0]->setTitle('the_new_title'); |
|
47
|
|
|
$this->getTopicModel()->updateTopic($topics[0]); |
|
48
|
|
|
$this->em->refresh($topics[0]); |
|
49
|
|
|
|
|
50
|
|
|
$this->assertSame('the_new_title', $topics[0]->getTitle()); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function testIncrementViewCounter() |
|
54
|
|
|
{ |
|
55
|
|
|
$this->purge(); |
|
56
|
|
|
$users = $this->addFixturesForUsers(); |
|
57
|
|
|
$topic = $this->addNewTopic('NewTopicTest', null, false, false); |
|
58
|
|
|
$post = $this->addNewPost('foobar', $topic, $users['tom'], new \DateTime(), false, false); |
|
59
|
|
|
$this->getPostModel()->savePost($post); |
|
60
|
|
|
$this->getTopicModel()->saveTopic($topic); |
|
61
|
|
|
$this->getTopicModel()->incrementViewCounter($topic); |
|
62
|
|
|
$foundTopic = $this->getTopicModel()->findOneTopicByIdWithBoardAndCategory($topic->getId(), true); |
|
63
|
|
|
|
|
64
|
|
|
$this->assertTrue(is_numeric($foundTopic->getId())); |
|
65
|
|
|
$this->assertSame(1, $foundTopic->getCachedViewCount()); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function testRestore() |
|
69
|
|
|
{ |
|
70
|
|
|
$this->purge(); |
|
71
|
|
|
$users = $this->addFixturesForUsers(); |
|
72
|
|
|
$forums = $this->addFixturesForForums(); |
|
73
|
|
|
$categories = $this->addFixturesForCategories($forums); |
|
74
|
|
|
$boards = $this->addFixturesForBoards($categories); |
|
75
|
|
|
$topics = $this->addFixturesForTopics($boards); |
|
76
|
|
|
$this->addFixturesForPosts($topics, $users['tom']); |
|
77
|
|
|
$this->getTopicModel()->softDelete($topics[0], $users['tom']); |
|
78
|
|
|
$this->em->refresh($topics[0]); |
|
79
|
|
|
|
|
80
|
|
|
$this->assertTrue($topics[0]->isDeleted()); |
|
81
|
|
|
$this->getTopicModel()->restore($topics[0]); |
|
82
|
|
|
$this->em->refresh($topics[0]); |
|
83
|
|
|
$this->assertFalse($topics[0]->isDeleted()); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function testSoftDelete() |
|
87
|
|
|
{ |
|
88
|
|
|
$this->purge(); |
|
89
|
|
|
$users = $this->addFixturesForUsers(); |
|
90
|
|
|
$forums = $this->addFixturesForForums(); |
|
91
|
|
|
$categories = $this->addFixturesForCategories($forums); |
|
92
|
|
|
$boards = $this->addFixturesForBoards($categories); |
|
93
|
|
|
$topics = $this->addFixturesForTopics($boards); |
|
94
|
|
|
$this->addFixturesForPosts($topics, $users['tom']); |
|
95
|
|
|
$this->getTopicModel()->softDelete($topics[0], $users['tom']); |
|
96
|
|
|
$this->em->refresh($topics[0]); |
|
97
|
|
|
|
|
98
|
|
|
$this->assertTrue($topics[0]->isDeleted()); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
public function testSticky() |
|
102
|
|
|
{ |
|
103
|
|
|
$this->purge(); |
|
104
|
|
|
$users = $this->addFixturesForUsers(); |
|
105
|
|
|
$forums = $this->addFixturesForForums(); |
|
106
|
|
|
$categories = $this->addFixturesForCategories($forums); |
|
107
|
|
|
$boards = $this->addFixturesForBoards($categories); |
|
108
|
|
|
$topics = $this->addFixturesForTopics($boards); |
|
109
|
|
|
$this->addFixturesForPosts($topics, $users['tom']); |
|
110
|
|
|
$this->getTopicModel()->sticky($topics[0], $users['tom']); |
|
111
|
|
|
$this->em->refresh($topics[0]); |
|
112
|
|
|
|
|
113
|
|
|
$this->assertTrue($topics[0]->isSticky()); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
public function testUnsticky() |
|
117
|
|
|
{ |
|
118
|
|
|
$this->purge(); |
|
119
|
|
|
$users = $this->addFixturesForUsers(); |
|
120
|
|
|
$forums = $this->addFixturesForForums(); |
|
121
|
|
|
$categories = $this->addFixturesForCategories($forums); |
|
122
|
|
|
$boards = $this->addFixturesForBoards($categories); |
|
123
|
|
|
$topics = $this->addFixturesForTopics($boards); |
|
124
|
|
|
$this->addFixturesForPosts($topics, $users['tom']); |
|
125
|
|
|
$this->getTopicModel()->unsticky($topics[0]); |
|
126
|
|
|
$this->em->refresh($topics[0]); |
|
127
|
|
|
|
|
128
|
|
|
$this->assertFalse($topics[0]->isSticky()); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
public function testClose() |
|
132
|
|
|
{ |
|
133
|
|
|
$this->purge(); |
|
134
|
|
|
$users = $this->addFixturesForUsers(); |
|
135
|
|
|
$forums = $this->addFixturesForForums(); |
|
136
|
|
|
$categories = $this->addFixturesForCategories($forums); |
|
137
|
|
|
$boards = $this->addFixturesForBoards($categories); |
|
138
|
|
|
$topics = $this->addFixturesForTopics($boards); |
|
139
|
|
|
$this->addFixturesForPosts($topics, $users['tom']); |
|
140
|
|
|
$this->getTopicModel()->close($topics[0], $users['tom']); |
|
141
|
|
|
$this->em->refresh($topics[0]); |
|
142
|
|
|
|
|
143
|
|
|
$this->assertTrue($topics[0]->isClosed()); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
public function testReopen() |
|
147
|
|
|
{ |
|
148
|
|
|
$this->purge(); |
|
149
|
|
|
$users = $this->addFixturesForUsers(); |
|
150
|
|
|
$forums = $this->addFixturesForForums(); |
|
151
|
|
|
$categories = $this->addFixturesForCategories($forums); |
|
152
|
|
|
$boards = $this->addFixturesForBoards($categories); |
|
153
|
|
|
$topics = $this->addFixturesForTopics($boards); |
|
154
|
|
|
$this->addFixturesForPosts($topics, $users['tom']); |
|
155
|
|
|
$this->getTopicModel()->reopen($topics[0]); |
|
156
|
|
|
$this->em->refresh($topics[0]); |
|
157
|
|
|
|
|
158
|
|
|
$this->assertFalse($topics[0]->isClosed()); |
|
159
|
|
|
} |
|
160
|
|
|
} |