Miliooo /
MilioooMessageBundle
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | /* |
||
| 4 | * This file is part of the MilioooMessageBundle package. |
||
| 5 | * |
||
| 6 | * (c) Michiel boeckaert <[email protected]> |
||
| 7 | * This source file is subject to the MIT license that is bundled |
||
| 8 | * with this source code in the file LICENSE. |
||
| 9 | */ |
||
| 10 | |||
| 11 | namespace Miliooo\MessagingBundle\Tests\Controller; |
||
| 12 | |||
| 13 | use Miliooo\MessagingBundle\Controller\ThreadActionsController; |
||
| 14 | use Miliooo\Messaging\TestHelpers\ParticipantTestHelper; |
||
| 15 | use Miliooo\Messaging\User\ParticipantInterface; |
||
| 16 | use Symfony\Component\HttpFoundation\Request; |
||
| 17 | use Miliooo\Messaging\ValueObjects\ThreadStatus; |
||
| 18 | use Miliooo\Messaging\Model\ThreadMetaInterface; |
||
| 19 | use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
||
| 20 | use Miliooo\Messaging\Helpers\FlashMessages\FlashMessageProviderInterface; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Test file for ThreadActionsControllerTest |
||
| 24 | * @author Michiel Boeckaert <[email protected]> |
||
| 25 | */ |
||
| 26 | class ThreadActionsControllerTest extends \PHPUnit_Framework_TestCase |
||
| 27 | { |
||
| 28 | /** |
||
| 29 | * @var ThreadActionsController |
||
| 30 | */ |
||
| 31 | private $controller; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var \PHPUnit_Framework_MockObject_MockObject |
||
| 35 | */ |
||
| 36 | private $threadStatusManager; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var \PHPUnit_Framework_MockObject_MockObject |
||
| 40 | */ |
||
| 41 | private $participantProvider; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var \PHPUnit_Framework_MockObject_MockObject |
||
| 45 | */ |
||
| 46 | private $threadProvider; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @var ParticipantInterface |
||
| 50 | */ |
||
| 51 | private $loggedInUser; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @var \PHPUnit_Framework_MockObject_MockObject |
||
| 55 | */ |
||
| 56 | private $request; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @var \PHPUnit_Framework_MockObject_MockObject |
||
| 60 | */ |
||
| 61 | private $parameterBag; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @var \PHPUnit_Framework_MockObject_MockObject |
||
| 65 | */ |
||
| 66 | private $flashProvider; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @var \PHPUnit_Framework_MockObject_MockObject |
||
| 70 | */ |
||
| 71 | private $router; |
||
| 72 | |||
| 73 | public function setUp() |
||
| 74 | { |
||
| 75 | $this->loggedInUser = new ParticipantTestHelper('1'); |
||
| 76 | |||
| 77 | $this->request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request') |
||
| 78 | ->disableOriginalConstructor() |
||
| 79 | ->getMock(); |
||
| 80 | |||
| 81 | $this->parameterBag = $this->getMockBuilder('Symfony\Component\HttpFoundation\ParameterBag') |
||
| 82 | ->disableOriginalConstructor()->getMock(); |
||
| 83 | |||
| 84 | $this->threadStatusManager = $this->getMock('Miliooo\Messaging\Manager\ThreadStatusManagerInterface'); |
||
| 85 | $this->threadProvider = $this->getMock('Miliooo\Messaging\ThreadProvider\SecureThreadProviderInterface'); |
||
| 86 | $this->participantProvider = $this->getMock('Miliooo\Messaging\User\ParticipantProviderInterface'); |
||
| 87 | $this->flashProvider = $this->getMock('Miliooo\Messaging\Helpers\FlashMessages\FlashMessageProviderInterface'); |
||
| 88 | $this->router = $this->getMock('Symfony\Component\Routing\RouterInterface'); |
||
| 89 | |||
| 90 | $this->controller = new ThreadActionsController( |
||
| 91 | $this->threadStatusManager, |
||
| 92 | $this->threadProvider, |
||
| 93 | $this->participantProvider, |
||
| 94 | $this->flashProvider, |
||
| 95 | $this->router |
||
| 96 | ); |
||
| 97 | } |
||
| 98 | |||
| 99 | public function testNoThreadsSelectedWithReferrerSet() |
||
| 100 | { |
||
| 101 | //setup a request object with action archive_thread and one thread selected |
||
| 102 | $postArray = ['thread_action' => 'archive_thread', 'folder' => 'outbox']; |
||
| 103 | $this->request = new Request([], $postArray, [], [], [], ['HTTP_REFERER' => 'http://test.com']); |
||
|
0 ignored issues
–
show
|
|||
| 104 | |||
| 105 | $this->flashProvider->expects($this->once())->method('addFlash') |
||
| 106 | ->with(FlashMessageProviderInterface::TYPE_ERROR, 'flash.thread_updates.no_threads_selected'); |
||
| 107 | |||
| 108 | $this->router->expects($this->never())->method('generate'); |
||
| 109 | |||
| 110 | $this->controller->threadAction($this->request); |
||
| 111 | } |
||
| 112 | |||
| 113 | public function testNoThreadsSelectedWithNoRefererSet() |
||
| 114 | { |
||
| 115 | //setup a request object with action archive_thread and one thread selected |
||
| 116 | $postArray = ['thread_action' => 'archive_thread', 'folder' => 'outbox']; |
||
| 117 | $this->request = new Request([], $postArray, [], [], []); |
||
|
0 ignored issues
–
show
It seems like
new \Symfony\Component\H...ay(), array(), array()) of type object<Symfony\Component\HttpFoundation\Request> is incompatible with the declared type object<PHPUnit_Framework_MockObject_MockObject> of property $request.
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property. Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.. Loading history...
|
|||
| 118 | |||
| 119 | $this->flashProvider->expects($this->once())->method('addFlash') |
||
| 120 | ->with(FlashMessageProviderInterface::TYPE_ERROR, 'flash.thread_updates.no_threads_selected'); |
||
| 121 | |||
| 122 | $this->expectsRouterCallWith('miliooo_message_outbox'); |
||
| 123 | |||
| 124 | $this->controller->threadAction($this->request); |
||
| 125 | } |
||
| 126 | |||
| 127 | public function testUnknownThreadAction() |
||
| 128 | { |
||
| 129 | //setup a request object with action archive_thread and one thread selected |
||
| 130 | $postArray = ['thread_action' => 'foo', 'selected_threads' => ['1'], 'folder' => 'outbox']; |
||
| 131 | $this->request = new Request([], $postArray, [], [], [], ['HTTP_REFERER' => 'http://test.com']); |
||
|
0 ignored issues
–
show
It seems like
new \Symfony\Component\H... => 'http://test.com')) of type object<Symfony\Component\HttpFoundation\Request> is incompatible with the declared type object<PHPUnit_Framework_MockObject_MockObject> of property $request.
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property. Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.. Loading history...
|
|||
| 132 | |||
| 133 | $this->flashProvider->expects($this->once())->method('addFlash') |
||
| 134 | ->with(FlashMessageProviderInterface::TYPE_ERROR, 'flash.thread_updates.unknown_action'); |
||
| 135 | $this->expectsNoThreadStatusManagerUpdate(); |
||
| 136 | |||
| 137 | $this->controller->threadAction($this->request); |
||
| 138 | } |
||
| 139 | |||
| 140 | public function testThreadActionArchiveThreadWhenThreadsFound() |
||
| 141 | { |
||
| 142 | //setup a request object with action archive_thread and one thread selected |
||
| 143 | $postArray = ['thread_action' => 'archive_thread', 'selected_threads' => ['1'], 'folder' => 'outbox']; |
||
| 144 | $this->request = new Request([], $postArray); |
||
|
0 ignored issues
–
show
It seems like
new \Symfony\Component\H...st(array(), $postArray) of type object<Symfony\Component\HttpFoundation\Request> is incompatible with the declared type object<PHPUnit_Framework_MockObject_MockObject> of property $request.
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property. Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.. Loading history...
|
|||
| 145 | |||
| 146 | $this->expectsLoggedInUser(); |
||
| 147 | |||
| 148 | $thread = $this->getMock('Miliooo\Messaging\Model\ThreadInterface'); |
||
| 149 | $this->threadProvider->expects($this->once()) |
||
| 150 | ->method('findThreadForParticipant') |
||
| 151 | ->with($this->loggedInUser, 1) |
||
| 152 | ->will($this->returnValue($thread)); |
||
| 153 | |||
| 154 | $threadStatusObject = new ThreadStatus(ThreadMetaInterface::STATUS_ARCHIVED); |
||
| 155 | $this->threadStatusManager->expects($this->once())->method('updateThreadStatusForParticipant') |
||
| 156 | ->with($threadStatusObject, $thread, $this->loggedInUser); |
||
| 157 | |||
| 158 | $this->flashProvider->expects($this->once())->method('addFlash') |
||
| 159 | ->with(FlashMessageProviderInterface::TYPE_SUCCESS, 'flash.thread_updates.archived_success'); |
||
| 160 | |||
| 161 | $this->expectsRouterCallWith('miliooo_message_outbox'); |
||
| 162 | |||
| 163 | $this->controller->threadAction($this->request); |
||
| 164 | } |
||
| 165 | |||
| 166 | public function testThreadActionArchiveThreadWhenNoThreadsFound() |
||
| 167 | { |
||
| 168 | $this->expectsLoggedInUser(); |
||
| 169 | |||
| 170 | //setup a request object with action archive_thread and one thread selected |
||
| 171 | $postArray = ['thread_action' => 'archive_thread', 'selected_threads' => ['1']]; |
||
| 172 | $this->request = new Request([], $postArray); |
||
|
0 ignored issues
–
show
It seems like
new \Symfony\Component\H...st(array(), $postArray) of type object<Symfony\Component\HttpFoundation\Request> is incompatible with the declared type object<PHPUnit_Framework_MockObject_MockObject> of property $request.
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property. Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.. Loading history...
|
|||
| 173 | |||
| 174 | $this->threadProvider->expects($this->once()) |
||
| 175 | ->method('findThreadForParticipant') |
||
| 176 | ->with($this->loggedInUser, 1) |
||
| 177 | ->will($this->returnValue(null)); |
||
| 178 | |||
| 179 | $this->expectsNoThreadStatusManagerUpdate(); |
||
| 180 | |||
| 181 | $this->flashProvider->expects($this->once())->method('addFlash') |
||
| 182 | ->with(FlashMessageProviderInterface::TYPE_ERROR, 'flash.thread_updates.archived_no_threads'); |
||
| 183 | |||
| 184 | $this->expectsRouterCallWith('miliooo_message_inbox'); |
||
| 185 | $this->controller->threadAction($this->request); |
||
| 186 | } |
||
| 187 | |||
| 188 | public function testThreadActionWhenNotAllowedToViewThread() |
||
| 189 | { |
||
| 190 | $this->expectsLoggedInUser(); |
||
| 191 | |||
| 192 | //setup a request object with action archive_thread and one thread selected |
||
| 193 | $postArray = ['thread_action' => 'archive_thread', 'selected_threads' => ['1']]; |
||
| 194 | $this->request = new Request([], $postArray); |
||
|
0 ignored issues
–
show
It seems like
new \Symfony\Component\H...st(array(), $postArray) of type object<Symfony\Component\HttpFoundation\Request> is incompatible with the declared type object<PHPUnit_Framework_MockObject_MockObject> of property $request.
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property. Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.. Loading history...
|
|||
| 195 | |||
| 196 | $this->threadProvider->expects($this->once()) |
||
| 197 | ->method('findThreadForParticipant') |
||
| 198 | ->with($this->loggedInUser, 1) |
||
| 199 | ->will($this->throwException(new AccessDeniedException())); |
||
| 200 | |||
| 201 | $this->expectsNoThreadStatusManagerUpdate(); |
||
| 202 | |||
| 203 | $this->flashProvider->expects($this->once())->method('addFlash') |
||
| 204 | ->with(FlashMessageProviderInterface::TYPE_ERROR, 'flash.thread_updates.archived_no_threads'); |
||
| 205 | |||
| 206 | $this->expectsRouterCallWith('miliooo_message_inbox'); |
||
| 207 | $this->controller->threadAction($this->request); |
||
| 208 | } |
||
| 209 | |||
| 210 | protected function expectsLoggedInUser() |
||
| 211 | { |
||
| 212 | $this->participantProvider->expects($this->once())->method('getAuthenticatedParticipant') |
||
| 213 | ->will($this->returnValue($this->loggedInUser)); |
||
| 214 | } |
||
| 215 | |||
| 216 | /** |
||
| 217 | * @param string $routingName |
||
| 218 | */ |
||
| 219 | protected function expectsRouterCallWith($routingName) |
||
| 220 | { |
||
| 221 | $this->router->expects($this->once())->method('generate')->with($routingName) |
||
| 222 | ->will($this->returnValue('http://test.com')); |
||
| 223 | } |
||
| 224 | |||
| 225 | protected function expectsNoThreadStatusManagerUpdate() |
||
| 226 | { |
||
| 227 | $this->threadStatusManager->expects($this->never())->method('updateThreadStatusForParticipant'); |
||
| 228 | } |
||
| 229 | } |
||
| 230 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..