Author: Marco Pivetta (ocramius@gmail.com)
コード例 #1
0
ファイル: IsGrantedTest.php プロジェクト: adamh114/zfc-rbac
 public function testHelperIsRegistered()
 {
     $serviceManager = ServiceManagerFactory::getServiceManager();
     $config = $serviceManager->get('Config');
     $this->assertArrayHasKey('view_helpers', $config);
     $viewHelpersConfig = $config['view_helpers'];
     $this->assertEquals('ZfcRbac\\View\\Helper\\IsGranted', $viewHelpersConfig['aliases']['isGranted']);
     $this->assertEquals('ZfcRbac\\Factory\\IsGrantedViewHelperFactory', $viewHelpersConfig['factories']['ZfcRbac\\View\\Helper\\IsGranted']);
 }
コード例 #2
0
 public function testAssertModuleDefaultOptions()
 {
     /** @var \ZfcRbac\Options\ModuleOptions $moduleOptions */
     $moduleOptions = ServiceManagerFactory::getServiceManager()->get('ZfcRbac\\Options\\ModuleOptions');
     $this->assertEquals('ZfcRbac\\Identity\\AuthenticationIdentityProvider', $moduleOptions->getIdentityProvider());
     $this->assertEquals('guest', $moduleOptions->getGuestRole());
     $this->assertEquals('allow', $moduleOptions->getProtectionPolicy());
     $this->assertInternalType('array', $moduleOptions->getGuards());
     $this->assertInternalType('array', $moduleOptions->getRoleProvider());
     $this->assertInternalType('array', $moduleOptions->getAssertionMap());
     $this->assertInstanceOf('ZfcRbac\\Options\\UnauthorizedStrategyOptions', $moduleOptions->getUnauthorizedStrategy());
     $this->assertInstanceOf('ZfcRbac\\Options\\RedirectStrategyOptions', $moduleOptions->getRedirectStrategy());
 }
コード例 #3
0
 public function testDelegatorThrowExceptionWhenBadInterface()
 {
     $serviceManager = ServiceManagerFactory::getServiceManager();
     $serviceManager->setAllowOverride(true);
     $authorizationService = $this->getMock('ZfcRbac\\Service\\AuthorizationService', [], [], '', false);
     $serviceManager->setService('ZfcRbac\\Service\\AuthorizationService', $authorizationService);
     $serviceManager->setAllowOverride(false);
     $serviceManager->setFactory('ZfcRbacTest\\AuthorizationAware', function () {
         return new \StdClass();
     });
     $serviceManager->addDelegator('ZfcRbacTest\\AuthorizationAware', 'ZfcRbac\\Factory\\AuthorizationServiceDelegatorFactory');
     $this->setExpectedException('ZfcRbac\\Exception\\RuntimeException', 'The service ZfcRbacTest\\AuthorizationAware must implement AuthorizationServiceAwareInterface.');
     $serviceManager->get('ZfcRbacTest\\AuthorizationAware');
 }
コード例 #4
0
 public function testThrowExceptionIfAskedRoleIsNotFound()
 {
     $this->serviceManager = ServiceManagerFactory::getServiceManager();
     $objectManager = $this->getObjectManager();
     $objectRepository = $objectManager->getRepository('ZfcRbacTest\\Asset\\FlatRole');
     $objectRepositoryRoleProvider = new ObjectRepositoryRoleProvider($objectRepository, 'name');
     $this->setExpectedException('ZfcRbac\\Exception\\RoleNotFoundException', 'Some roles were asked but could not be loaded from database: guest, admin');
     $objectRepositoryRoleProvider->getRoles(['guest', 'admin']);
 }
コード例 #5
0
 public function testDelegatorThrowExceptionWhenBadInterface()
 {
     $serviceManager = ServiceManagerFactory::getServiceManager();
     $serviceManager->setAllowOverride(true);
     $authorizationService = $this->getMock('ZfcRbac\\Service\\AuthorizationService', [], [], '', false);
     $serviceManager->setService('ZfcRbac\\Service\\AuthorizationService', $authorizationService);
     $serviceManager->setAllowOverride(false);
     $serviceManager->setFactory('ZfcRbacTest\\AuthorizationAware', function () {
         return new \StdClass();
     });
     $serviceManager->addDelegator('ZfcRbacTest\\AuthorizationAware', 'ZfcRbac\\Factory\\AuthorizationServiceDelegatorFactory');
     $thrown = false;
     try {
         $serviceManager->get('ZfcRbacTest\\AuthorizationAware');
     } catch (\Exception $e) {
         $thrown = true;
         $this->assertStringEndsWith('The service ZfcRbacTest\\AuthorizationAware must implement AuthorizationServiceAwareInterface.', $e->getMessage());
         if ($e->getPrevious()) {
             $this->assertInstanceOf('ZfcRbac\\Exception\\RuntimeException', $e->getPrevious());
         }
     }
     $this->assertTrue($thrown);
 }
コード例 #6
0
ファイル: Bootstrap.php プロジェクト: adamh114/zfc-rbac
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * This software consists of voluntary contributions made by many individuals
 * and is licensed under the MIT license.
 */
use ZfcRbacTest\Util\ServiceManagerFactory;
ini_set('error_reporting', E_ALL);
$files = [__DIR__ . '/../vendor/autoload.php', __DIR__ . '/../../../autoload.php'];
foreach ($files as $file) {
    if (file_exists($file)) {
        $loader = (require $file);
        break;
    }
}
if (!isset($loader)) {
    throw new RuntimeException('vendor/autoload.php could not be found. Did you install via composer?');
}
$loader->add('ZfcRbacTest\\', __DIR__);
$configFiles = [__DIR__ . '/TestConfiguration.php', __DIR__ . '/TestConfiguration.php.dist'];
foreach ($configFiles as $configFile) {
    if (file_exists($configFile)) {
        $config = (require $configFile);
        break;
    }
}
ServiceManagerFactory::setApplicationConfig($config);
unset($files, $file, $loader, $configFiles, $configFile, $config);