From 234e56f47923ee6e9d582cead1d60a07e8ab5c5c Mon Sep 17 00:00:00 2001 From: Sam Moffatt Date: Fri, 6 Jan 2012 14:08:59 -0800 Subject: [PATCH 1/2] Pulling in some changes from the eBay content branch to improve testing --- tests/includes/JoomlaDatabaseTestCase.php | 12 +++++++----- tests/includes/JoomlaTestCase.php | 12 +++++++----- tests/includes/mocks/JSessionMock.php | 17 ++++++++-------- tests/includes/mocks/JWebMock.php | 24 +++++++++++++++-------- 4 files changed, 39 insertions(+), 26 deletions(-) diff --git a/tests/includes/JoomlaDatabaseTestCase.php b/tests/includes/JoomlaDatabaseTestCase.php index 918792a8eb..ca4666d7f3 100644 --- a/tests/includes/JoomlaDatabaseTestCase.php +++ b/tests/includes/JoomlaDatabaseTestCase.php @@ -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); } } diff --git a/tests/includes/JoomlaTestCase.php b/tests/includes/JoomlaTestCase.php index c8befd7870..1e289caed8 100644 --- a/tests/includes/JoomlaTestCase.php +++ b/tests/includes/JoomlaTestCase.php @@ -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); } } diff --git a/tests/includes/mocks/JSessionMock.php b/tests/includes/mocks/JSessionMock.php index ec41cd9973..cb972d8ec4 100644 --- a/tests/includes/mocks/JSessionMock.php +++ b/tests/includes/mocks/JSessionMock.php @@ -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 * @@ -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. * @@ -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; } diff --git a/tests/includes/mocks/JWebMock.php b/tests/includes/mocks/JWebMock.php index 358287a965..3a6fa06efe 100644 --- a/tests/includes/mocks/JWebMock.php +++ b/tests/includes/mocks/JWebMock.php @@ -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'])) @@ -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; } -} \ No newline at end of file +} From 26955ef2a8fedbd3265397042afe4666f9dd4769 Mon Sep 17 00:00:00 2001 From: Sam Moffatt Date: Fri, 6 Jan 2012 16:28:53 -0800 Subject: [PATCH 2/2] Renaming JWebMock to JApplicationWebMock --- tests/includes/JoomlaDatabaseTestCase.php | 6 +++--- tests/includes/JoomlaTestCase.php | 6 +++--- .../{JWebMock.php => JApplicationWebMock.php} | 16 ++++++++-------- 3 files changed, 14 insertions(+), 14 deletions(-) rename tests/includes/mocks/{JWebMock.php => JApplicationWebMock.php} (80%) diff --git a/tests/includes/JoomlaDatabaseTestCase.php b/tests/includes/JoomlaDatabaseTestCase.php index ca4666d7f3..e0b76d504b 100644 --- a/tests/includes/JoomlaDatabaseTestCase.php +++ b/tests/includes/JoomlaDatabaseTestCase.php @@ -516,7 +516,7 @@ public function getMockSession($options = array()) * * @param array $options A set of options to configure the mock. * - * @return JWeb + * @return JApplicationWeb * * @since 12.1 */ @@ -526,8 +526,8 @@ public function getMockWeb($options = array()) require_once JPATH_PLATFORM . '/joomla/application/web.php'; // Load the mock class builder. - require_once JPATH_TESTS . '/includes/mocks/JWebMock.php'; + require_once JPATH_TESTS . '/includes/mocks/JApplicationWebMock.php'; - return JWebGlobalMock::create($this, $options); + return JApplicationWebGlobalMock::create($this, $options); } } diff --git a/tests/includes/JoomlaTestCase.php b/tests/includes/JoomlaTestCase.php index 1e289caed8..d3e4d17e65 100644 --- a/tests/includes/JoomlaTestCase.php +++ b/tests/includes/JoomlaTestCase.php @@ -457,7 +457,7 @@ public function getMockSession($options = array()) * * @param array $options A set of options to configure the mock. * - * @return JWeb + * @return JApplicationWeb * * @since 12.1 */ @@ -467,8 +467,8 @@ public function getMockWeb($options = array()) require_once JPATH_PLATFORM . '/joomla/application/web.php'; // Load the mock class builder. - require_once JPATH_TESTS . '/includes/mocks/JWebMock.php'; + require_once JPATH_TESTS . '/includes/mocks/JApplicationWebMock.php'; - return JWebGlobalMock::create($this, $options); + return JApplicationWebGlobalMock::create($this, $options); } } diff --git a/tests/includes/mocks/JWebMock.php b/tests/includes/mocks/JApplicationWebMock.php similarity index 80% rename from tests/includes/mocks/JWebMock.php rename to tests/includes/mocks/JApplicationWebMock.php index 3a6fa06efe..93bbc02a11 100644 --- a/tests/includes/mocks/JWebMock.php +++ b/tests/includes/mocks/JApplicationWebMock.php @@ -11,15 +11,15 @@ require_once __DIR__ . '/JSessionMock.php'; /** - * Mock class for JWeb. + * Mock class for JApplicationWeb. * * @package Joomla.UnitTest * @since 12.1 */ -class JWebGlobalMock +class JApplicationWebGlobalMock { /** - * Creates and instance of the mock JWeb object. + * Creates and instance of the mock JApplicationWeb object. * * @param object $test A test object. * @param array $options A set of options to configure the mock. @@ -36,7 +36,7 @@ public static function create($test, $options = array()) $_SERVER['HTTP_HOST'] = 'localhost'; } - // Collect all the relevant methods in JWeb (work in progress). + // Collect all the relevant methods in JApplicationWeb (work in progress). $methods = array( 'get', 'getDocument', @@ -46,7 +46,7 @@ public static function create($test, $options = array()) // Create the mock. $mockObject = $test->getMock( - 'JWeb', + 'JApplicationWeb', $methods, // Constructor arguments. array(), @@ -56,13 +56,13 @@ public static function create($test, $options = array()) true ); - // Mock calls to JWeb::getDocument(). + // Mock calls to JApplicationWeb::getDocument(). $mockObject->expects($test->any())->method('getDocument')->will($test->returnValue(JDocumentGlobalMock::create($test))); - // Mock calls to JWeb::getLanguage(). + // Mock calls to JApplicationWeb::getLanguage(). $mockObject->expects($test->any())->method('getLanguage')->will($test->returnValue(JLanguageGlobalMock::create($test))); - // Mock a call to JWeb::getSession(). + // Mock a call to JApplicationWeb::getSession(). if (isset($options['session'])) { $mockObject->expects($test->any())->method('getSession')->will($test->returnValue($options['session']));