|
0
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
namespace JMS\SecurityExtraBundle\Tests\Mapping\Driver; |
|
|
4 |
|
|
|
5 |
use Doctrine\Common\Annotations\AnnotationReader; |
|
|
6 |
|
|
|
7 |
use JMS\SecurityExtraBundle\Metadata\Driver\AnnotationDriver; |
|
|
8 |
|
|
|
9 |
require_once __DIR__.'/Fixtures/services.php'; |
|
|
10 |
|
|
|
11 |
class AnnotationDriverTest extends \PHPUnit_Framework_TestCase |
|
|
12 |
{ |
|
|
13 |
public function testLoadMetadataFromClass() |
|
|
14 |
{ |
|
|
15 |
$driver = new AnnotationDriver(new AnnotationReader()); |
|
|
16 |
|
|
|
17 |
$metadata = $driver->loadMetadataForClass(new \ReflectionClass('JMS\SecurityExtraBundle\Tests\Mapping\Driver\FooService')); |
|
|
18 |
$this->assertTrue(isset($metadata->methodMetadata['foo'])); |
|
|
19 |
$method = $metadata->methodMetadata['foo']; |
|
|
20 |
$this->assertEquals(array('ROLE_USER', 'ROLE_ADMIN', 'ROLE_SUPERADMIN'), $method->roles); |
|
|
21 |
$this->assertEquals(array(), $method->returnPermissions); |
|
|
22 |
$this->assertEquals(array(0 => array('VIEW')), $method->paramPermissions); |
|
|
23 |
|
|
|
24 |
$metadata = $driver->loadMetadataForClass(new \ReflectionClass('JMS\SecurityExtraBundle\Tests\Mapping\Driver\FooInterface')); |
|
|
25 |
$this->assertTrue(isset($metadata->methodMetadata['foo'])); |
|
|
26 |
$method = $metadata->methodMetadata['foo']; |
|
|
27 |
$this->assertEquals(array(), $method->roles); |
|
|
28 |
$this->assertEquals(array(0 => array('OWNER'), 1 => array('EDIT')), $method->paramPermissions); |
|
|
29 |
$this->assertEquals(array('MASTER'), $method->returnPermissions); |
|
|
30 |
} |
|
|
31 |
|
|
|
32 |
public function testLoadMetadataFromClassWithShortNotation() |
|
|
33 |
{ |
|
|
34 |
$driver = new AnnotationDriver(new AnnotationReader()); |
|
|
35 |
|
|
|
36 |
$metadata = $driver->loadMetadataForClass(new \ReflectionClass('JMS\SecurityExtraBundle\Tests\Mapping\Driver\FooService')); |
|
|
37 |
$this->assertTrue(isset($metadata->methodMetadata['shortNotation'])); |
|
|
38 |
$method = $metadata->methodMetadata['shortNotation']; |
|
|
39 |
$this->assertEquals(array('ROLE_FOO', 'ROLE_BAR'), $method->roles); |
|
|
40 |
} |
|
|
41 |
|
|
|
42 |
public function testLoadMetadataFromClassDoesNotProcessMethodsForWhichNoSecurityMetadataExists() |
|
|
43 |
{ |
|
|
44 |
$driver = new AnnotationDriver(new AnnotationReader()); |
|
|
45 |
|
|
|
46 |
$metadata = $driver->loadMetadataForClass(new \ReflectionClass('JMS\SecurityExtraBundle\Tests\Fixtures\MainService')); |
|
|
47 |
$this->assertTrue(class_exists('JMS\SecurityExtraBundle\Tests\Fixtures\Annotation\NonSecurityAnnotation', false)); |
|
|
48 |
$this->assertFalse(isset($metadata->methodMetadata['foo'])); |
|
|
49 |
} |
|
|
50 |
} |