*/ namespace oat\tao\test\unit\model\routing; use oat\generis\test\TestCase; use oat\tao\model\routing\AnnotationReaderService; use oat\tao\model\routing\RouteAnnotationService; use Prophecy\Argument; use Psr\Log\LoggerInterface; use Zend\ServiceManager\ServiceLocatorInterface; class RouteAnnotationServiceTest extends TestCase { /** * @var RouteAnnotationService */ private $service; protected function setUp(): void { parent::setUp(); $this->service = new RouteAnnotationService(); $logger = $this->prophesize(LoggerInterface::class); $this->service->setLogger($logger->reveal()); $annotationReaderService = $this->prophesize(AnnotationReaderService::class); $annotationReaderService->getAnnotations(Argument::type('string'), Argument::type('string'))->will(function ($args) { if ($args[0] === 'class') { switch ($args[1]) { case 'notFoundAnnotation': return ['security' => [RouteAnnotationService::SECURITY_HIDE, RouteAnnotationService::SECURITY_ALLOW]]; break; case 'requiresRightRead': return [ 'required_rights' => [ [ 'key' => 'id', 'permission' => 'READ', ], [ 'key' => 'uri', 'permission' => 'WRITE', ], ], ]; break; case 'withoutAnnotation': return []; break; } } }); /** @var ServiceLocatorInterface $serviceLocator */ $serviceLocator = $this->prophesize(ServiceLocatorInterface::class); $serviceLocator->get(Argument::type('string'))->will(function ($args) use ($annotationReaderService) { if ($args[0] === AnnotationReaderService::SERVICE_ID) { return $annotationReaderService->reveal(); } }); $this->service->setServiceLocator($serviceLocator->reveal()); } public function testIncorrectClassName() { self::assertFalse($this->service->hasAccess('', '')); } public function testIsHidden() { self::assertTrue($this->service->isHidden('class', 'notFoundAnnotation')); } public function testValidatePassed() { self::assertTrue($this->service->hasAccess('class', 'withoutAnnotation')); } public function testHasAccessHidden() { self::assertFalse($this->service->hasAccess('class', 'notFoundAnnotation')); } public function testHasAccessRights() { self::assertTrue($this->service->hasAccess('class', 'requiresRightRead')); } }