AuthLink = $this->getMockBuilder(AuthLinkHelper::class) ->setMethods(['isAuthorized']) ->setConstructorArgs([$view]) ->getMock(); } /** * tearDown method * * @return void */ public function tearDown() { unset($this->AuthLink); parent::tearDown(); } /** * Test link * * @return void */ public function testLinkFalseWithMock() { $this->AuthLink->expects($this->once()) ->method('isAuthorized') ->with( $this->equalTo(['plugin' => 'CakeDC/Users', 'controller' => 'Users', 'action' => 'profile']) ) ->will($this->returnValue(false)); $result = $this->AuthLink->link( 'title', ['plugin' => 'CakeDC/Users', 'controller' => 'Users', 'action' => 'profile'], ['before' => 'before_', 'after' => '_after', 'class' => 'link-class'] ); $this->assertFalse($result); } /** * Test link * * @return void */ public function testLinkAuthorizedHappy() { $this->AuthLink->expects($this->once()) ->method('isAuthorized') ->with( $this->equalTo(['plugin' => 'CakeDC/Users', 'controller' => 'Users', 'action' => 'profile']) ) ->will($this->returnValue(true)); $link = $this->AuthLink->link( 'title', ['plugin' => 'CakeDC/Users', 'controller' => 'Users', 'action' => 'profile'], ['before' => 'before_', 'after' => '_after', 'class' => 'link-class'] ); $this->assertSame('before_title_after', $link); } /** * Test link * * @return void */ public function testLinkAuthorizedAllowedTrue() { $link = $this->AuthLink->link('title', '/', ['allowed' => true, 'before' => 'before_', 'after' => '_after', 'class' => 'link-class']); $this->assertSame('before_title_after', $link); } /** * Test link * * @return void */ public function testLinkAuthorizedAllowedFalse() { $link = $this->AuthLink->link('title', '/', ['allowed' => false, 'before' => 'before_', 'after' => '_after', 'class' => 'link-class']); $this->assertFalse($link); } /** * Test getRequest method * * @retunr void */ public function testGetRequest() { $actual = $this->AuthLink->getRequest(); $this->assertInstanceOf(ServerRequest::class, $actual); } }