User = new UserHelper($view); $this->request = new \Cake\Network\Request(); } /** * tearDown method * * @return void */ public function tearDown() { unset($this->User); parent::tearDown(); } /** * Test facebookLogin * * @return void */ public function testFacebookLogin() { $result = $this->User->facebookLogin(); $expected = 'Sign in with Facebook'; $this->assertEquals($expected, $result); } /** * Test twitterLogin * * @return void */ public function testTwitterLoginEnabled() { $result = $this->User->twitterLogin(); $expected = 'Sign in with Twitter'; $this->assertEquals($expected, $result); } /** * Test twitterLogin * * @return void */ public function testLogout() { $result = $this->User->logout(); $expected = 'Logout'; $this->assertEquals($expected, $result); } /** * Test twitterLogin * * @return void */ public function testLogoutDifferentMessage() { $result = $this->User->logout('Sign Out'); $expected = 'Sign Out'; $this->assertEquals($expected, $result); } /** * Test twitterLogin * * @return void */ public function testLogoutWithOptions() { $result = $this->User->logout('Sign Out', ['class' => 'logout']); $expected = 'Sign Out'; $this->assertEquals($expected, $result); } /** * Test link * * @return void */ public function testLinkFalse() { $link = $this->User->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->User = new UserHelper($view); $result = new Event('dispatch-result'); $result->result = true; $eventManagerMock->expects($this->once()) ->method('dispatch') ->will($this->returnValue($result)); $link = $this->User->link('title', '/', ['before' => 'before_', 'after' => '_after', 'class' => 'link-class']); $this->assertSame('before_title_after', $link); } /** * Test link * * @return void */ public function testWelcome() { $session = $this->getMock('Cake\Network\Session', ['read']); $session->expects($this->at(0)) ->method('read') ->with('Auth.User.id') ->will($this->returnValue(2)); $session->expects($this->at(1)) ->method('read') ->with('Auth.User.first_name') ->will($this->returnValue('david')); $this->User->request = $this->getMock('Cake\Network\Request', ['session']); $this->User->request->expects($this->any()) ->method('session') ->will($this->returnValue($session)); $expected = 'Welcome, david'; $result = $this->User->welcome(); $this->assertEquals($expected, $result); } /** * Test link * * @return void */ public function testWelcomeNotLoggedInUser() { $session = $this->getMock('Cake\Network\Session', ['read']); $session->expects($this->at(0)) ->method('read') ->with('Auth.User.id') ->will($this->returnValue(null)); $this->User->request = $this->getMock('Cake\Network\Request', ['session']); $this->User->request->expects($this->any()) ->method('session') ->will($this->returnValue($session)); $result = $this->User->welcome(); $this->assertEmpty($result); } }