|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the login-cidadao project or it's bundles. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Guilherme Donato <guilhermednt on github> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace LoginCidadao\BadgesControlBundle\Tests\Model; |
|
12
|
|
|
|
|
13
|
|
|
use LoginCidadao\BadgesControlBundle\BadgesEvents; |
|
14
|
|
|
use LoginCidadao\BadgesControlBundle\Event\ListBadgesEvent; |
|
15
|
|
|
use LoginCidadao\BadgesControlBundle\Event\ListBearersEvent; |
|
16
|
|
|
use LoginCidadao\BadgesControlBundle\Exception\BadgesNameCollisionException; |
|
17
|
|
|
use LoginCidadao\BadgesControlBundle\Model\AbstractBadgesEventSubscriber; |
|
18
|
|
|
|
|
19
|
|
|
class AbstractBadgesEventSubscriberTest extends \PHPUnit_Framework_TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
public function testAbstractSubscriber() |
|
22
|
|
|
{ |
|
23
|
|
|
$this->assertSame([ |
|
24
|
|
|
BadgesEvents::BADGES_EVALUATE => ['onBadgeEvaluate', 0], |
|
25
|
|
|
BadgesEvents::BADGES_LIST_AVAILABLE => ['onBadgeListAvailable', 0], |
|
26
|
|
|
BadgesEvents::BADGES_LIST_BEARERS => ['onListBearersPreFilter', 0], |
|
27
|
|
|
], AbstractBadgesEventSubscriber::getSubscribedEvents()); |
|
28
|
|
|
|
|
29
|
|
|
/** @var AbstractBadgesEventSubscriber|\PHPUnit_Framework_MockObject_MockObject $stub */ |
|
30
|
|
|
$stub = $this->getMockForAbstractClass('LoginCidadao\BadgesControlBundle\Model\AbstractBadgesEventSubscriber'); |
|
31
|
|
|
$stub->expects($this->once())->method('onListBearers') |
|
32
|
|
|
->with($this->isInstanceOf('LoginCidadao\BadgesControlBundle\Event\ListBearersEvent')); |
|
33
|
|
|
|
|
34
|
|
|
$stub->setName('namespace'); |
|
35
|
|
|
|
|
36
|
|
|
/** @var ListBadgesEvent|\PHPUnit_Framework_MockObject_MockObject $event */ |
|
37
|
|
|
$event = $this->getMockBuilder('LoginCidadao\BadgesControlBundle\Event\ListBadgesEvent') |
|
38
|
|
|
->disableOriginalConstructor()->getMock(); |
|
39
|
|
|
$event->expects($this->once())->method('registerBadges')->with($stub); |
|
40
|
|
|
|
|
41
|
|
|
try { |
|
42
|
|
|
$stub->onBadgeListAvailable($event); |
|
43
|
|
|
} catch (BadgesNameCollisionException $e) { |
|
44
|
|
|
$this->fail("Unexpected exception"); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
$filterBadge = $this->getMock('LoginCidadao\BadgesControlBundle\Model\BadgeInterface'); |
|
48
|
|
|
$filterBadge->expects($this->once())->method('getNamespace')->willReturn('namespace'); |
|
49
|
|
|
|
|
50
|
|
|
/** @var ListBearersEvent|\PHPUnit_Framework_MockObject_MockObject $bearersEvent */ |
|
51
|
|
|
$bearersEvent = $this->getMockBuilder('LoginCidadao\BadgesControlBundle\Event\ListBearersEvent') |
|
52
|
|
|
->disableOriginalConstructor()->getMock(); |
|
53
|
|
|
$bearersEvent->expects($this->once())->method('getBadge')->willReturn($filterBadge); |
|
54
|
|
|
|
|
55
|
|
|
$stub->onListBearersPreFilter($bearersEvent); |
|
56
|
|
|
|
|
57
|
|
|
$this->assertEmpty($stub->getAvailableBadges()); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|