|
15 | 15 | use Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\PublishableReadInterface;
|
16 | 16 | use Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\PublishWorkflowChecker;
|
17 | 17 | use Symfony\Component\DependencyInjection\ContainerInterface;
|
| 18 | +use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; |
18 | 19 | use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
|
19 | 20 | use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
|
20 | 21 | use Symfony\Component\Security\Core\SecurityContextInterface;
|
@@ -54,14 +55,22 @@ class PublishWorkflowCheckerTest extends \PHPUnit_Framework_Testcase
|
54 | 55 | public function setUp()
|
55 | 56 | {
|
56 | 57 | $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(); |
58 | 61 | $this->sc = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
|
59 | 62 | $this->container
|
60 | 63 | ->expects($this->any())
|
61 | 64 | ->method('get')
|
62 | 65 | ->with('security.context')
|
63 | 66 | ->will($this->returnValue($this->sc))
|
64 | 67 | ;
|
| 68 | + $this->container |
| 69 | + ->expects($this->any()) |
| 70 | + ->method('has') |
| 71 | + ->with('security.context') |
| 72 | + ->will($this->returnValue(true)) |
| 73 | + ; |
65 | 74 | $this->doc = $this->getMock('Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\PublishableReadInterface');
|
66 | 75 | $this->adm = $this->getMock('Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface');
|
67 | 76 | $this->stdClass = new \stdClass;
|
@@ -150,6 +159,31 @@ public function testNoFirewall()
|
150 | 159 | $this->assertTrue($this->pwfc->isGranted(PublishWorkflowChecker::VIEW_ATTRIBUTE, $this->doc));
|
151 | 160 | }
|
152 | 161 |
|
| 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 | + |
153 | 187 | public function testSetToken()
|
154 | 188 | {
|
155 | 189 | $token = new AnonymousToken('x', 'y');
|
|
0 commit comments