AnnotationDriverTest.php 2.3KB

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