1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Symnedi\Security\Tests\EventSubscriber; |
6
|
|
|
|
7
|
|
|
use Nette\Application\Application; |
8
|
|
|
use Nette\Application\ForbiddenRequestException; |
9
|
|
|
use Nette\Application\IPresenter; |
10
|
|
|
use Nette\Application\Request as ApplicationRequest; |
11
|
|
|
use Nette\Http\Request; |
12
|
|
|
use Nette\Http\UrlScript; |
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
use Prophecy\Argument; |
15
|
|
|
use Symnedi\EventDispatcher\Event\ApplicationPresenterEvent; |
16
|
|
|
use Symnedi\EventDispatcher\NetteApplicationEvents; |
17
|
|
|
use Symnedi\Security\Contract\Http\FirewallHandlerInterface; |
18
|
|
|
use Symnedi\Security\Contract\Http\FirewallMapInterface; |
19
|
|
|
use Symnedi\Security\EventSubscriber\FirewallSubscriber; |
20
|
|
|
|
21
|
|
|
final class FirewallSubscriberTest extends TestCase |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var FirewallSubscriber |
25
|
|
|
*/ |
26
|
|
|
private $firewall; |
27
|
|
|
|
28
|
|
|
protected function setUp() |
29
|
|
|
{ |
30
|
|
|
$listenerMock = $this->prophesize(FirewallHandlerInterface::class); |
31
|
|
|
$listenerMock->handle(Argument::cetera())->willReturn(function () { |
32
|
|
|
throw new ForbiddenRequestException(); |
33
|
|
|
}); |
34
|
|
|
|
35
|
|
|
$firewallMapMock = $this->prophesize(FirewallMapInterface::class); |
36
|
|
|
$firewallMapMock->getListeners(Argument::type(Request::class))->willReturn( |
37
|
|
|
[[$listenerMock->reveal()], ''] |
38
|
|
|
); |
39
|
|
|
|
40
|
|
|
$request = new Request((new UrlScript())->setScriptPath('admin/script.php')); |
41
|
|
|
$this->firewall = new FirewallSubscriber($firewallMapMock->reveal(), $request); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testGetSubscribedEvents() |
45
|
|
|
{ |
46
|
|
|
$this->assertSame( |
47
|
|
|
[NetteApplicationEvents::ON_PRESENTER => 'onPresenter'], |
48
|
|
|
$this->firewall->getSubscribedEvents() |
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function testOnPresenter() |
53
|
|
|
{ |
54
|
|
|
$requestMock = $this->prophesize(ApplicationRequest::class); |
55
|
|
|
$requestMock->getParameters()->willReturn(['parameter' => 'value']); |
56
|
|
|
|
57
|
|
|
$applicationPresenterEventMock = new ApplicationPresenterEvent( |
58
|
|
|
$this->prophesize(Application::class)->reveal(), |
59
|
|
|
$this->prophesize(IPresenter::class)->reveal() |
60
|
|
|
); |
61
|
|
|
|
62
|
|
|
$this->firewall->onPresenter($applicationPresenterEventMock); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|