예제 #1
0
 public function getViewHelperConfig()
 {
     return array('factories' => array('isAllowed' => function ($sm) {
         $sm = $sm->getServiceLocator();
         // get the main SM instance
         $helper = new View\Helper\IsAllowed();
         $helper->setAuthorizeService($sm->get('BjyAuthorize\\Service\\Authorize'));
         return $helper;
     }));
 }
예제 #2
0
 /**
  * @covers \BjyAuthorize\View\Helper\IsAllowed
  */
 public function testIsAllowed()
 {
     $authorize = $this->getMock('BjyAuthorize\\Service\\Authorize', array(), array(), '', false);
     $authorize->expects($this->once())->method('isAllowed')->with('test', 'privilege')->will($this->returnValue(true));
     $plugin = new IsAllowed($authorize);
     $this->assertTrue($plugin->__invoke('test', 'privilege'));
     $authorize2 = $this->getMock('BjyAuthorize\\Service\\Authorize', array(), array(), '', false);
     $authorize2->expects($this->once())->method('isAllowed')->with('test2', 'privilege2')->will($this->returnValue(false));
     $plugin = new IsAllowed($authorize2);
     $this->assertFalse($plugin->__invoke('test2', 'privilege2'));
 }