Skip to content
This repository has been archived by the owner on Nov 26, 2017. It is now read-only.

Add some new tests, clean up some others. #1736

Merged
merged 1 commit into from
Dec 16, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 58 additions & 2 deletions tests/suites/unit/joomla/JFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,10 @@ public function testGetXml()
*
* @return void
*
* @since 11.3
* @since 12.3
* @covers JFactory::getDate
*/
public function testGetDate()
public function testGetDateUnchanged()
{
JFactory::$language = $this->getMockLanguage();

Expand All @@ -246,6 +246,19 @@ public function testGetDate()
$this->equalTo('2001-01-01 01:01:01'),
'Tests that a date passed in comes back unchanged.'
);
}

/**
* Tests the JFactory::getDate method.
*
* @return void
*
* @since 12.3
* @covers JFactory::getDate
*/
public function testGetDateNow()
{
JFactory::$language = $this->getMockLanguage();

$date = JFactory::getDate('now');
sleep(2);
Expand All @@ -256,6 +269,19 @@ public function testGetDate()
$this->equalTo($date),
'Tests that the cache for the same time is working.'
);
}

/**
* Tests the JFactory::getDate method.
*
* @return void
*
* @since 12.3
* @covers JFactory::getDate
*/
public function testGetDateUTC1()
{
JFactory::$language = $this->getMockLanguage();

$tz = 'Etc/GMT+0';
$date = JFactory::getDate('2001-01-01 01:01:01', $tz);
Expand All @@ -265,6 +291,19 @@ public function testGetDate()
$this->equalTo('2001-01-01 01:01:01'),
'Tests that a date passed in with UTC timezone string comes back unchanged.'
);
}

/**
* Tests the JFactory::getDate method.
*
* @return void
*
* @since 12.3
* @covers JFactory::getDate
*/
public function testGetDateUTC2()
{
JFactory::$language = $this->getMockLanguage();

$tz = new DateTimeZone('Etc/GMT+0');
$date = JFactory::getDate('2001-01-01 01:01:01', $tz);
Expand All @@ -275,4 +314,21 @@ public function testGetDate()
'Tests that a date passed in with UTC timezone comes back unchanged.'
);
}

/**
* Tests the JFactory::getUser method.
*
* @return void
*
* @since 12.3
* @covers JFactory::getUser
*/
public function testGetUserInstance()
{
$this->assertInstanceOf(
'JUser',
JFactory::getUser(),
'Line: ' . __LINE__
);
}
}
28 changes: 27 additions & 1 deletion tests/suites/unit/joomla/application/JApplicationBaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function testLoadDispatcher()
* @covers JApplicationBase::loadIdentity
* @covers JApplicationBase::getIdentity
*/
public function testLoadGetIdentity()
public function testLoadGetIdentityCorrectClass()
{
$mock = $this->getMock('JUser', array(), array(), '', false);
$this->class->loadIdentity($mock);
Expand All @@ -103,12 +103,38 @@ public function testLoadGetIdentity()
$this->class,
'Tests that the identity object is the correct class.'
);
}
/**
* Tests the JApplicationBase::loadIdentity and JApplicationBase::getIdentity methods.
*
* @return void
*
* @since 12.3
* @covers JApplicationBase::loadIdentity
* @covers JApplicationBase::getIdentity
*/
public function testLoadGetIdentityGetJUser()
{
$mock = $this->getMock('JUser', array(), array(), '', false);
$this->class->loadIdentity($mock);

$this->assertInstanceOf(
'JUser',
$this->class->getIdentity()
);
}

/**
* Tests the JApplicationBase::loadIdentity and JApplicationBase::getIdentity methods.
*
* @return void
*
* @since 12.3
* @covers JApplicationBase::loadIdentity
* @covers JApplicationBase::getIdentity
*/
public function testLoadGetIdentity99()
{
// Mock the session.
JFactory::$session = $this->getMockSession(array('get.user.id' => 99));

Expand Down
66 changes: 34 additions & 32 deletions tests/suites/unit/joomla/session/JSessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ protected function tearDown()
'first_instance' => array(
'none',
array('expire' => 99),
'Line: ' . __LINE__ . ': ' . 'Should not be a different instance '
'Line: ' . __LINE__ . ': ' . 'Should not be a different instance and options should not change'
),
'second_instance' => array(
'database',
array('expire' => 15),
array(),
'Line: ' . __LINE__ . ': ' . 'Should not be a different instance '
)
);
Expand All @@ -103,38 +103,50 @@ public function testGetInstance($store, $options)
{
$oldSession = $this->object;
$newSession = JSession::getInstance($store, $options);
// The properties and values should be identical to each other.
$this->assertThat(
$oldSession,
$this->identicalTo($newSession)
);

// They should be the same object.
$this->assertSame($oldSession,$newSession);
}

/**
* Test...
* Test getState
*
* @covers JSession::getState
*
* @return void
*/
public function testGetState()
{
$this->assertEquals('active', $this->object->getState(), 'Session should be active');
$this->assertEquals(
TestReflection::getValue($this->object, '_state'),
$this->object->getState(),
'Session state should be the same'
);
}

/**
* Test...
* Test getExpire()
*
* @covers JSession::getExpire
*
* @return void
*/
public function testGetExpire()
{
$this->assertEquals(20, $this->object->getExpire(), 'Session expire should be 20');
$this->assertEquals(
TestReflection::getValue($this->object, '_expire'),
$this->object->getExpire(),
'Session expire time should be the same'
);
}

/**
* Test...
* Test getToken
*
* @covers JSession::getToken
*
Expand All @@ -154,7 +166,7 @@ public function testGetToken()
}

/**
* Test...
* Test hasToken
*
* @covers JSession::hasToken
*
Expand All @@ -173,7 +185,7 @@ public function testHasToken()
}

/**
* Test...
* Test getFormToken
*
* @covers JSession::getFormToken
*
Expand All @@ -189,44 +201,37 @@ public function testGetFormToken()
->with($this->equalTo('secret'))
->will($this->returnValue('abc'));

$this->object->set('secret','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');
$this->assertEquals($expected, $this->object->getFormToken(), 'Form token should be calculated as above.');
}

/**
* Test...
* Test getName
*
* @todo Implement testGetName().
* @covers JSession::hasToken
* @covers JSession::getName
*
* @return void
*/
public function testGetName()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
$this->assertEquals(session_name(), $this->object->getName(), 'Session names should match.');
}

/**
* Test...
* Test getId
*
* @todo Implement testGetId().
* @covers JSession::hasToken
* @covers JSession::getId
*
* @return void
*/
public function testGetId()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
$this->assertEquals(session_id(), $this->object->getId(), 'Session ids should match.');
}

/**
* Test...
* Test getStores
*
* @covers JSession::getStores
*
Expand All @@ -253,18 +258,15 @@ public function testGetStores()
}

/**
* Test...
*
* @todo Implement testIsNew().
* Test isNew
*
* @return void
*/
public function testIsNew()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
$this->object->set('session.counter', 1);

$this->assertEquals(true, $this->object->isNew(), '$isNew should be true.');
}

/**
Expand Down
Loading