AuthLink = new AuthLinkHelper($view); } /** * tearDown method * * @return void */ public function tearDown() { unset($this->AuthLink); parent::tearDown(); } /** * Test link * * @return void */ public function testLinkFalse() { $link = $this->AuthLink->link('title', ['controller' => 'noaccess']); $this->assertSame(false, $link); } /** * Test link * * @return void */ public function testLinkAuthorized() { $view = new View(); $eventManagerMock = $this->getMockBuilder('Cake\Event\EventManager') ->setMethods(['dispatch']) ->getMock(); $view->eventManager($eventManagerMock); $this->AuthLink = new AuthLinkHelper($view); $result = new Event('dispatch-result'); $result->result = true; $eventManagerMock->expects($this->once()) ->method('dispatch') ->will($this->returnValue($result)); $link = $this->AuthLink->link('title', '/', ['before' => 'before_', 'after' => '_after', 'class' => 'link-class']); $this->assertSame('before_title_after', $link); } /** * Test isAuthorized * * @return void */ public function testIsAuthorized() { $view = new View(); $eventManagerMock = $this->getMockBuilder('Cake\Event\EventManager') ->setMethods(['dispatch']) ->getMock(); $view->eventManager($eventManagerMock); $this->AuthLink = new AuthLinkHelper($view); $result = new Event('dispatch-result'); $result->result = true; $eventManagerMock->expects($this->once()) ->method('dispatch') ->will($this->returnValue($result)); $result = $this->AuthLink->isAuthorized(['controller' => 'MyController', 'action' => 'myAction']); $this->assertTrue($result); } }