|
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 SubscriptionManagerTest extends TestBase |
|
20
|
|
|
{ |
|
21
|
|
|
public function testSubscribe() |
|
22
|
|
|
{ |
|
23
|
|
|
$this->purge(); |
|
24
|
|
|
$users = $this->addFixturesForUsers(); |
|
25
|
|
|
$forums = $this->addFixturesForForums(); |
|
26
|
|
|
$categories = $this->addFixturesForCategories($forums); |
|
27
|
|
|
$boards = $this->addFixturesForBoards($categories); |
|
28
|
|
|
$topics = $this->addFixturesForTopics($boards); |
|
29
|
|
|
$this->addFixturesForPosts($topics, $users['tom']); |
|
30
|
|
|
$this->getSubscriptionModel()->subscribe($topics[0], $users['tom']); |
|
31
|
|
|
$subscriptionFound = $this->getSubscriptionModel()->findOneSubscriptionForTopicByIdAndUserById($topics[0]->getId(), $users['tom']->getId()); |
|
32
|
|
|
|
|
33
|
|
|
$this->assertTrue($subscriptionFound->isSubscribed()); |
|
34
|
|
|
$this->assertInternalType('integer', $subscriptionFound->getId()); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function testUnsubscribe() |
|
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
|
|
|
$this->getSubscriptionModel()->subscribe($topics[0], $users['tom']); |
|
47
|
|
|
$this->getSubscriptionModel()->unsubscribe($topics[0], $users['tom']->getId()); |
|
48
|
|
|
$subscriptionFound = $this->getSubscriptionModel()->findOneSubscriptionForTopicByIdAndUserById($topics[0]->getId(), $users['tom']->getId()); |
|
49
|
|
|
|
|
50
|
|
|
$this->assertFalse($subscriptionFound->isSubscribed()); |
|
51
|
|
|
$this->assertInternalType('integer', $subscriptionFound->getId()); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function testMarkAsRead() |
|
55
|
|
|
{ |
|
56
|
|
|
$this->purge(); |
|
57
|
|
|
$users = $this->addFixturesForUsers(); |
|
58
|
|
|
$forums = $this->addFixturesForForums(); |
|
59
|
|
|
$categories = $this->addFixturesForCategories($forums); |
|
60
|
|
|
$boards = $this->addFixturesForBoards($categories); |
|
61
|
|
|
$topics = $this->addFixturesForTopics($boards); |
|
62
|
|
|
$this->addFixturesForPosts($topics, $users['tom']); |
|
63
|
|
|
$this->getSubscriptionModel()->subscribe($topics[0], $users['tom']); |
|
64
|
|
|
$subscriptionFound = $this->getSubscriptionModel()->findOneSubscriptionForTopicByIdAndUserById($topics[0]->getId(), $users['tom']->getId()); |
|
65
|
|
|
$this->getSubscriptionModel()->markAsRead($subscriptionFound); |
|
66
|
|
|
$subscriptionsFound = $this->getSubscriptionModel()->findAllSubscriptionsForUserById($users['tom']->getId(), true); |
|
67
|
|
|
|
|
68
|
|
|
foreach ($subscriptionsFound as $subscription) { |
|
69
|
|
|
if ($subscription->getTopic()->getId() == $topics[0]->getId()) { |
|
70
|
|
|
$this->assertTrue($subscription->isSubscribed()); |
|
71
|
|
|
$this->assertTrue($subscription->isRead()); |
|
72
|
|
|
$this->assertInternalType('integer', $subscription->getId()); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function testMarkAsUnread() |
|
78
|
|
|
{ |
|
79
|
|
|
$this->purge(); |
|
80
|
|
|
$users = $this->addFixturesForUsers(); |
|
81
|
|
|
$forums = $this->addFixturesForForums(); |
|
82
|
|
|
$categories = $this->addFixturesForCategories($forums); |
|
83
|
|
|
$boards = $this->addFixturesForBoards($categories); |
|
84
|
|
|
$topics = $this->addFixturesForTopics($boards); |
|
85
|
|
|
$this->addFixturesForPosts($topics, $users['tom']); |
|
86
|
|
|
$this->getSubscriptionModel()->subscribe($topics[0], $users['tom']); |
|
87
|
|
|
$subscriptionFound = $this->getSubscriptionModel()->findOneSubscriptionForTopicByIdAndUserById($topics[0]->getId(), $users['tom']->getId()); |
|
88
|
|
|
$this->getSubscriptionModel()->markAsUnread($subscriptionFound); |
|
89
|
|
|
$subscriptionsFound = $this->getSubscriptionModel()->findAllSubscriptionsForUserById($users['tom']->getId(), true); |
|
90
|
|
|
|
|
91
|
|
|
foreach ($subscriptionsFound as $subscription) { |
|
92
|
|
|
if ($subscription->getTopic()->getId() == $topics[0]->getId()) { |
|
93
|
|
|
$this->assertTrue($subscription->isSubscribed()); |
|
94
|
|
|
$this->assertFalse($subscription->isRead()); |
|
95
|
|
|
$this->assertInternalType('integer', $subscription->getId()); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public function testMarkTheseAsUnread() |
|
101
|
|
|
{ |
|
102
|
|
|
$this->purge(); |
|
103
|
|
|
$users = $this->addFixturesForUsers(); |
|
104
|
|
|
$forums = $this->addFixturesForForums(); |
|
105
|
|
|
$categories = $this->addFixturesForCategories($forums); |
|
106
|
|
|
$boards = $this->addFixturesForBoards($categories); |
|
107
|
|
|
$topics = $this->addFixturesForTopics($boards); |
|
108
|
|
|
$this->addFixturesForPosts($topics, $users['tom']); |
|
109
|
|
|
$this->getSubscriptionModel()->subscribe($topics[0], $users['tom']); |
|
110
|
|
|
$this->getSubscriptionModel()->subscribe($topics[0], $users['dick']); |
|
111
|
|
|
$this->getSubscriptionModel()->subscribe($topics[0], $users['harry']); |
|
112
|
|
|
$subscriptions = array(); |
|
113
|
|
|
$subscriptions[0] = $this->getSubscriptionModel()->findOneSubscriptionForTopicByIdAndUserById($topics[0]->getId(), $users['tom']->getId()); |
|
114
|
|
|
$subscriptions[1] = $this->getSubscriptionModel()->findOneSubscriptionForTopicByIdAndUserById($topics[0]->getId(), $users['dick']->getId()); |
|
115
|
|
|
$subscriptions[2] = $this->getSubscriptionModel()->findOneSubscriptionForTopicByIdAndUserById($topics[0]->getId(), $users['harry']->getId()); |
|
116
|
|
|
$this->getSubscriptionModel()->markTheseAsUnread($subscriptions, $users['dick']); |
|
|
|
|
|
|
117
|
|
|
$subscriptionsFound = $this->getSubscriptionModel()->findAllSubscriptionsForTopicById($topics[0]->getId(), true); |
|
|
|
|
|
|
118
|
|
|
|
|
119
|
|
|
foreach ($subscriptionsFound as $subscription) { |
|
120
|
|
|
if ($subscription->getTopic()->getId() == $topics[0]->getId()) { |
|
121
|
|
|
$this->assertTrue($subscription->isSubscribed()); |
|
122
|
|
|
$this->assertInternalType('integer', $subscription->getId()); |
|
123
|
|
|
|
|
124
|
|
|
if ($subscription->getOwnedBy()->getId() == $users['dick']->getId()) { |
|
125
|
|
|
$this->assertTrue($subscription->isRead()); |
|
126
|
|
|
} else { |
|
127
|
|
|
$this->assertFalse($subscription->isRead()); |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
} |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: