|
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 BoardManagerTest extends TestBase |
|
20
|
|
|
{ |
|
21
|
|
|
public function testSaveBoard() |
|
22
|
|
|
{ |
|
23
|
|
|
$this->purge(); |
|
24
|
|
|
$board = $this->addNewBoard('NewBoardTest', 'Generic description', 1, null, false, false); |
|
25
|
|
|
$this->getBoardModel()->saveBoard($board); |
|
26
|
|
|
|
|
27
|
|
|
$this->assertTrue(is_numeric($board->getId())); |
|
28
|
|
|
$this->assertSame('NewBoardTest', $board->getName()); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function testUpdateBoard() |
|
32
|
|
|
{ |
|
33
|
|
|
$this->purge(); |
|
34
|
|
|
$board = $this->addNewBoard('UpdateBoardTest', 'Generic Description', 1, null, true, true); |
|
35
|
|
|
$board->setName('BoardTestUpdated'); |
|
36
|
|
|
$this->getBoardModel()->updateBoard($board); |
|
37
|
|
|
|
|
38
|
|
|
$this->assertTrue(is_numeric($board->getId())); |
|
39
|
|
|
$this->assertEquals('BoardTestUpdated', $board->getName()); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function testDeleteBoard() |
|
43
|
|
|
{ |
|
44
|
|
|
$this->purge(); |
|
45
|
|
|
$board = $this->addNewBoard('DeleteBoardTest', 'Generic Description', 1, null, true, true); |
|
46
|
|
|
$boardId = $board->getId(); |
|
47
|
|
|
$this->getBoardModel()->deleteBoard($board); |
|
48
|
|
|
$foundBoard = $this->getBoardModel()->findOneBoardById($boardId); |
|
49
|
|
|
|
|
50
|
|
|
$this->assertNull($foundBoard); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function testReassignTopicsToBoard() |
|
54
|
|
|
{ |
|
55
|
|
|
$this->purge(); |
|
56
|
|
|
$forum = $this->addNewForum('testReassignTopicsToBoard'); |
|
57
|
|
|
$categories = $this->addFixturesForCategories(array($forum)); |
|
58
|
|
|
$boards = $this->addFixturesForBoards($categories); |
|
59
|
|
|
$topics = $this->addFixturesForTopics($boards); |
|
|
|
|
|
|
60
|
|
|
$board1 = $boards[0]; |
|
61
|
|
|
$board2 = $boards[1]; |
|
62
|
|
|
$topics = new ArrayCollection($board1->getTopics()->toArray()); |
|
63
|
|
|
|
|
64
|
|
|
$this->assertCount(3, $board1->getTopics()); |
|
65
|
|
|
$this->getBoardModel()->reassignTopicsToBoard($topics, null); |
|
66
|
|
|
$this->em->refresh($board1); |
|
67
|
|
|
$this->assertCount(0, $board1->getTopics()); |
|
68
|
|
|
|
|
69
|
|
|
$this->getBoardModel()->reassignTopicsToBoard($topics, $board2); |
|
70
|
|
|
$this->em->refresh($board2); |
|
71
|
|
|
$this->assertCount(6, $board2->getTopics()); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
const REORDER_UP = 0; |
|
75
|
|
|
const REORDER_DOWN = 1; |
|
76
|
|
|
|
|
77
|
|
|
public function testReorderBoards() |
|
78
|
|
|
{ |
|
79
|
|
|
$this->purge(); |
|
80
|
|
|
$forum = $this->addNewForum('testReorderBoards'); |
|
81
|
|
|
$categories = $this->addFixturesForCategories(array($forum)); |
|
82
|
|
|
$this->addFixturesForBoards($categories); |
|
83
|
|
|
|
|
84
|
|
|
$category = $categories[count($categories) - 1]; |
|
85
|
|
|
$this->em->refresh($category); |
|
86
|
|
|
$boards = $category->getBoards(); |
|
87
|
|
|
$this->assertCount(3, $boards); |
|
88
|
|
|
|
|
89
|
|
|
// 123 - Initial order. |
|
90
|
|
|
$this->assertSame('test_board_1', $boards[0]->getName()); |
|
91
|
|
|
$this->assertSame('test_board_2', $boards[1]->getName()); |
|
92
|
|
|
$this->assertSame('test_board_3', $boards[2]->getName()); |
|
93
|
|
|
|
|
94
|
|
|
// 123 -> 213 |
|
95
|
|
|
$this->getBoardModel()->reorderBoards($boards, $boards[0], $this::REORDER_DOWN); |
|
96
|
|
|
$boards = $this->getBoardModel()->findAllBoardsForCategoryById($category->getId()); |
|
97
|
|
|
$this->assertSame('test_board_2', $boards[0]->getName()); |
|
98
|
|
|
$this->assertSame('test_board_1', $boards[1]->getName()); |
|
99
|
|
|
$this->assertSame('test_board_3', $boards[2]->getName()); |
|
100
|
|
|
|
|
101
|
|
|
// 213 -> 231 |
|
102
|
|
|
$this->getBoardModel()->reorderBoards($boards, $boards[1], $this::REORDER_DOWN); |
|
|
|
|
|
|
103
|
|
|
$boards = $this->getBoardModel()->findAllBoardsForCategoryById($category->getId()); |
|
104
|
|
|
$this->assertSame('test_board_2', $boards[0]->getName()); |
|
105
|
|
|
$this->assertSame('test_board_3', $boards[1]->getName()); |
|
106
|
|
|
$this->assertSame('test_board_1', $boards[2]->getName()); |
|
107
|
|
|
|
|
108
|
|
|
// 231 -> 123 |
|
109
|
|
|
$this->getBoardModel()->reorderBoards($boards, $boards[2], $this::REORDER_DOWN); |
|
|
|
|
|
|
110
|
|
|
$boards = $this->getBoardModel()->findAllBoardsForCategoryById($category->getId()); |
|
111
|
|
|
$this->assertSame('test_board_1', $boards[0]->getName()); |
|
112
|
|
|
$this->assertSame('test_board_2', $boards[1]->getName()); |
|
113
|
|
|
$this->assertSame('test_board_3', $boards[2]->getName()); |
|
114
|
|
|
|
|
115
|
|
|
// 123 <- 231 |
|
116
|
|
|
$this->getBoardModel()->reorderBoards($boards, $boards[0], $this::REORDER_UP); |
|
|
|
|
|
|
117
|
|
|
$boards = $this->getBoardModel()->findAllBoardsForCategoryById($category->getId()); |
|
118
|
|
|
$this->assertSame('test_board_2', $boards[0]->getName()); |
|
119
|
|
|
$this->assertSame('test_board_3', $boards[1]->getName()); |
|
120
|
|
|
$this->assertSame('test_board_1', $boards[2]->getName()); |
|
121
|
|
|
|
|
122
|
|
|
// 231 <- 213 |
|
123
|
|
|
$this->getBoardModel()->reorderBoards($boards, $boards[2], $this::REORDER_UP); |
|
|
|
|
|
|
124
|
|
|
$boards = $this->getBoardModel()->findAllBoardsForCategoryById($category->getId()); |
|
125
|
|
|
$this->assertSame('test_board_2', $boards[0]->getName()); |
|
126
|
|
|
$this->assertSame('test_board_1', $boards[1]->getName()); |
|
127
|
|
|
$this->assertSame('test_board_3', $boards[2]->getName()); |
|
128
|
|
|
|
|
129
|
|
|
// 213 <- 123 |
|
130
|
|
|
$this->getBoardModel()->reorderBoards($boards, $boards[1], $this::REORDER_UP); |
|
|
|
|
|
|
131
|
|
|
$boards = $this->getBoardModel()->findAllBoardsForCategoryById($category->getId()); |
|
132
|
|
|
$this->assertSame('test_board_1', $boards[0]->getName()); |
|
133
|
|
|
$this->assertSame('test_board_2', $boards[1]->getName()); |
|
134
|
|
|
$this->assertSame('test_board_3', $boards[2]->getName()); |
|
135
|
|
|
} |
|
136
|
|
|
} |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.