示例#1
0
 /**
  * Creates an instance of the mock JSession object.
  *
  * @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
  *
  * @since   11.3
  */
 public static function create($test, $options = array())
 {
     if (is_array($options)) {
         self::$options = $options;
     }
     // Mock all the public methods.
     $methods = array('clear', 'close', 'destroy', 'fork', 'get', 'getExpire', 'getFormToken', 'getId', 'getInstance', 'getName', 'getState', 'getStores', 'getToken', 'has', 'hasToken', 'getPrefix', 'isNew', 'restart', 'set');
     // Create the mock.
     $mockObject = $test->getMock('JSession', $methods, array(), '', false);
     // Mock selected methods.
     $test->assignMockReturns($mockObject, array('getId' => self::getOption('getId')));
     $test->assignMockCallbacks($mockObject, array('get' => array(get_called_class(), 'mockGet')));
     return $mockObject;
 }
示例#2
0
 /**
  * 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.
  *
  * @return  object
  *
  * @since   11.3
  */
 public static function create($test, $options = array())
 {
     // Set expected server variables.
     if (!isset($_SERVER['HTTP_HOST'])) {
         $_SERVER['HTTP_HOST'] = 'localhost';
     }
     // Collect all the relevant methods in JApplicationWeb (work in progress).
     $methods = array('get', 'getDocument', 'getLanguage', 'getSession');
     // Create the mock.
     $mockObject = $test->getMock('JApplicationWeb', $methods, array(), '', true);
     // Mock calls to JApplicationWeb::getDocument().
     $mockObject->expects($test->any())->method('getDocument')->will($test->returnValue(JDocumentGlobalMock::create($test)));
     // Mock calls to JApplicationWeb::getLanguage().
     $mockObject->expects($test->any())->method('getLanguage')->will($test->returnValue(JLanguageGlobalMock::create($test)));
     // Mock a call to JApplicationWeb::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;
 }
 /**
  * Gets a mock session object.
  *
  * @return  object
  *
  * @since   11.3
  */
 protected function getMockSession()
 {
     require_once JPATH_TESTS . '/suite/joomla/session/JSessionMock.php';
     return JSessionGlobalMock::create($this);
 }
示例#4
0
 /**
  * Gets a mock session object.
  *
  * @param   array  $options  An array of key-value options for the JSession mock.
  *                           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  JSession
  *
  * @since   11.3
  */
 public function getMockSession($options = array())
 {
     // Load the real class first otherwise the mock will be used if jimport is called again.
     require_once JPATH_PLATFORM . '/joomla/session/session.php';
     // Load the mock class builder.
     require_once JPATH_TESTS . '/includes/mocks/JSessionMock.php';
     return JSessionGlobalMock::create($this, $options);
 }
 /**
  * Gets a mock session object.
  *
  * @param   array  $options  An array of key-value options for the JSession mock.
  *                           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
  *
  * @since   11.3
  */
 protected function getMockSession($options = array())
 {
     // Load the real class first otherwise the mock will be used if jimport is called again.
     require_once JPATH_PLATFORM . '/joomla/session/session.php';
     require_once JPATH_TESTS . '/suite/joomla/session/JSessionMock.php';
     return JSessionGlobalMock::create($this, $options);
 }