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

Commit

Permalink
Pulling in some changes from the eBay content branch to improve testing
Browse files Browse the repository at this point in the history
  • Loading branch information
pasamio committed Jan 6, 2012
1 parent 6d3ad50 commit 234e56f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 26 deletions.
12 changes: 7 additions & 5 deletions tests/includes/JoomlaDatabaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -510,22 +510,24 @@ public function getMockSession($options = array())

return JSessionGlobalMock::create($this, $options);
}

/**
* Gets a mock web object.
*
* @param array $options A set of options to configure the mock.
*
* @return JWeb
*
* @since 12.1
*/
public function getMockWeb()
public function getMockWeb($options = array())
{
// Load the real class first otherwise the mock will be used if jimport is called again.
require_once JPATH_PLATFORM . '/joomla/application/web.php';

// Load the mock class builder.
require_once JPATH_TESTS . '/includes/mocks/JWebMock.php';
return JWebGlobalMock::create($this);

return JWebGlobalMock::create($this, $options);
}
}
12 changes: 7 additions & 5 deletions tests/includes/JoomlaTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -451,22 +451,24 @@ public function getMockSession($options = array())

return JSessionGlobalMock::create($this, $options);
}

/**
* Gets a mock web object.
*
* @param array $options A set of options to configure the mock.
*
* @return JWeb
*
* @since 12.1
*/
public function getMockWeb()
public function getMockWeb($options = array())
{
// Load the real class first otherwise the mock will be used if jimport is called again.
require_once JPATH_PLATFORM . '/joomla/application/web.php';

// Load the mock class builder.
require_once JPATH_TESTS . '/includes/mocks/JWebMock.php';
return JWebGlobalMock::create($this);

return JWebGlobalMock::create($this, $options);
}
}
17 changes: 9 additions & 8 deletions tests/includes/mocks/JSessionMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ public function getOption($name, $default = null)
}

/**
* Creates an instance of the mock JDatabase object.
* Creates an instance of the mock JSession object.
*
* @param object $test A test object.
* @param array $config An array of optional configuration values.
* getId : the value to be returned by the mock getId method
* get.user.id : the value to assign to the user object id returned by get('user')
* get.user.name : the value to assign to the user object name returned by get('user')
* get.user.username : the value to assign to the user object username returned by get('user')
* @param object $test A test object.
* @param array $options An array of optional configuration values.
* getId : the value to be returned by the mock getId method
* get.user.id : the value to assign to the user object id returned by get('user')
* get.user.name : the value to assign to the user object name returned by get('user')
* get.user.username : the value to assign to the user object username returned by get('user')
*
* @return object
*
Expand Down Expand Up @@ -110,7 +110,7 @@ public static function create($test, $options = array())
}

/**
* Mocking the quote method.
* Mocking the get method.
*
* @param string $key The key to get.
*
Expand All @@ -130,6 +130,7 @@ public function mockGet($key)
$user->id = (int) self::getOption('get.user.id', 0);
$user->name = self::getOption('get.user.name');
$user->username = self::getOption('get.user.username');
$user->guest = (int) self::getOption('get.user.guest', 1);

return $user;
}
Expand Down
24 changes: 16 additions & 8 deletions tests/includes/mocks/JWebMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ class JWebGlobalMock
/**
* Creates and instance of the mock JWeb object.
*
* @param object $test A test object.
* @param object $test A test object.
* @param array $options A set of options to configure the mock.
*
* @return object
*
* @since 11.3
*/
public static function create($test)
public static function create($test, $options = array())
{
// Set expected server variables.
if (!isset($_SERVER['HTTP_HOST']))
Expand Down Expand Up @@ -57,13 +58,20 @@ public static function create($test)

// Mock calls to JWeb::getDocument().
$mockObject->expects($test->any())->method('getDocument')->will($test->returnValue(JDocumentGlobalMock::create($test)));
// Mock calls to JWeb::getDocument().

// Mock calls to JWeb::getLanguage().
$mockObject->expects($test->any())->method('getLanguage')->will($test->returnValue(JLanguageGlobalMock::create($test)));

// Mock calls to JWeb::getSession().
$mockObject->expects($test->any())->method('getSession')->will($test->returnValue(JSessionGlobalMock::create($test)));

// Mock a call to JWeb::getSession().
if (isset($options['session']))
{
$mockObject->expects($test->any())->method('getSession')->will($test->returnValue($options['session']));
}
else
{
$mockObject->expects($test->any())->method('getSession')->will($test->returnValue(JSessionGlobalMock::create($test)));
}

return $mockObject;
}
}
}

0 comments on commit 234e56f

Please sign in to comment.