/** * Test... * * @covers JSession::getFormToken * * @return void */ public function testGetFormToken() { $user = JFactory::getUser(); JFactory::$application = $this->getMock('JInputCookie', array('set', 'get')); JFactory::$application->expects($this->once())->method('get')->with($this->equalTo('secret'))->will($this->returnValue('abc')); $expected = md5('abc' . $user->get('id', 0) . $this->object->getToken(false)); $this->assertEquals($expected, $this->object->getFormToken(), 'Form token should be calculated as above'); }
/** * Test getFormToken * * @covers JSession::getFormToken * * @return void */ public function testGetFormToken() { // Set the factory session object for getting the token JFactory::$session = $this->object; $user = JFactory::getUser(); $expected = md5($user->get('id', 0) . $this->object->getToken(false)); $this->assertEquals($expected, $this->object->getFormToken(false), 'Form token should be calculated as above.'); }
/** * Test hasToken * * @covers JSession::hasToken * * @return void */ public function testHasToken() { $token = $this->object->getToken(); $this->assertTrue($this->object->hasToken($token), 'Line: ' . __LINE__ . ' Correct token should be true'); $this->assertFalse($this->object->hasToken('abc', false), 'Line: ' . __LINE__ . ' Should return false with wrong token'); $this->assertEquals('active', $this->object->getState(), 'Line: ' . __LINE__ . ' State should not be set to expired'); $this->assertFalse($this->object->hasToken('abc'), 'Line: ' . __LINE__ . ' Should return false with wrong token'); $this->assertEquals('expired', $this->object->getState(), 'Line: ' . __LINE__ . ' State should be set to expired by default'); }