Skip to content

Commit c7ebd16

Browse files
committed
fix tests and add missing tests for when security context is missing
1 parent 5b298ad commit c7ebd16

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

Tests/Unit/PublishWorkflow/PublishWorkflowCheckerTest.php

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\PublishableReadInterface;
1616
use Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\PublishWorkflowChecker;
1717
use Symfony\Component\DependencyInjection\ContainerInterface;
18+
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
1819
use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
1920
use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
2021
use Symfony\Component\Security\Core\SecurityContextInterface;
@@ -54,14 +55,22 @@ class PublishWorkflowCheckerTest extends \PHPUnit_Framework_Testcase
5455
public function setUp()
5556
{
5657
$this->role = 'IS_FOOBAR';
57-
$this->container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
58+
$this->container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')
59+
->setMockClassName('Container')
60+
->getMock();
5861
$this->sc = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
5962
$this->container
6063
->expects($this->any())
6164
->method('get')
6265
->with('security.context')
6366
->will($this->returnValue($this->sc))
6467
;
68+
$this->container
69+
->expects($this->any())
70+
->method('has')
71+
->with('security.context')
72+
->will($this->returnValue(true))
73+
;
6574
$this->doc = $this->getMock('Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\PublishableReadInterface');
6675
$this->adm = $this->getMock('Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface');
6776
$this->stdClass = new \stdClass;
@@ -150,6 +159,31 @@ public function testNoFirewall()
150159
$this->assertTrue($this->pwfc->isGranted(PublishWorkflowChecker::VIEW_ATTRIBUTE, $this->doc));
151160
}
152161

162+
public function testNoSecurityContext()
163+
{
164+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
165+
$container
166+
->expects($this->any())
167+
->method('get')
168+
->with('security.context')
169+
->will($this->throwException(new ServiceNotFoundException('Service not defined')))
170+
;
171+
$container
172+
->expects($this->any())
173+
->method('has')
174+
->with('security.context')
175+
->will($this->returnValue(false))
176+
;
177+
$this->pwfc = new PublishWorkflowChecker($container, $this->adm, $this->role);
178+
179+
$this->adm->expects($this->once())
180+
->method('decide')
181+
->will($this->returnValue(false))
182+
;
183+
184+
$this->assertFalse($this->pwfc->isGranted(PublishWorkflowChecker::VIEW_ATTRIBUTE, $this->doc));
185+
}
186+
153187
public function testSetToken()
154188
{
155189
$token = new AnonymousToken('x', 'y');

0 commit comments

Comments
 (0)