Exemplo n.º 1
0
 /**
  * Creates and instance of the mock JApplicationWeb object.
  *
  * The test can implement the following overrides:
  * - mockAppendBody
  * - mockGetBody
  * - mockPrepentBody
  * - mockSetBody
  *
  * If any *Body methods are implemented in the test class, all should be implemented otherwise behaviour will be unreliable.
  *
  * @param   TestCase  $test     A test object.
  * @param   array     $options  A set of options to configure the mock.
  *
  * @return  PHPUnit_Framework_MockObject_MockObject
  *
  * @since   3.2
  */
 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 JApplicationCms (work in progress).
     $methods = array('allowCache', 'appendBody', 'clearHeaders', 'close', 'execute', 'get', 'getBody', 'getDocument', 'getHeaders', 'getIdentity', 'getLanguage', 'getMenu', 'getPathway', 'getSession', 'getTemplate', 'initialiseApp', 'isAdmin', 'loadConfiguration', 'loadDispatcher', 'loadDocument', 'loadIdentity', 'loadLanguage', 'loadSession', 'prependBody', 'redirect', 'registerEvent', 'sendHeaders', 'set', 'setBody', 'setHeader', 'triggerEvent');
     // Create the mock.
     $mockObject = $test->getMock('JApplicationCms', $methods, array(), '', true);
     // Mock calls to JApplicationWeb::getDocument().
     $mockObject->expects($test->any())->method('getDocument')->will($test->returnValue(TestMockDocument::create($test)));
     // Mock calls to JApplicationWeb::getLanguage().
     $mockObject->expects($test->any())->method('getLanguage')->will($test->returnValue(TestMockLanguage::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(TestMockSession::create($test)));
     }
     $test->assignMockCallbacks($mockObject, array('appendBody' => array(is_callable(array($test, 'mockAppendBody')) ? $test : get_called_class(), 'mockAppendBody'), 'getBody' => array(is_callable(array($test, 'mockGetBody')) ? $test : get_called_class(), 'mockGetBody'), 'prependBody' => array(is_callable(array($test, 'mockPrependBody')) ? $test : get_called_class(), 'mockPrependBody'), 'setBody' => array(is_callable(array($test, 'mockSetBody')) ? $test : get_called_class(), 'mockSetBody'), 'getHeaders' => array(is_callable(array($test, 'mockGetHeaders')) ? $test : get_called_class(), 'mockGetHeaders'), 'setHeader' => array(is_callable(array($test, 'mockSetHeader')) ? $test : get_called_class(), 'mockSetHeader'), 'clearHeaders' => array(is_callable(array($test, 'mockClearHeaders')) ? $test : get_called_class(), 'mockClearHeaders'), 'allowCache' => array(is_callable(array($test, 'mockAllowCache')) ? $test : get_called_class(), 'mockAllowCache')));
     // Reset the body storage.
     static::$body = array();
     // Reset the headers storage.
     static::$headers = array();
     // Reset the cache storage.
     static::$cachable = array();
     return $mockObject;
 }
 public function setUp()
 {
     parent::setUp();
     static::$userData = ['username' => 'test', 'password' => base64_encode('123'), 'language_id' => 1, 'country_id' => 1];
     $user = \App\User::withTrashed()->where('username', '=', 'test')->first();
     if (!$user) {
         $user = factory(\App\User::class)->create(static::$userData);
     }
     if ($user->trashed()) {
         $user->restore();
     }
     static::$idUser = $user->id;
     static::$headers = array('Content-Type' => 'application/json', 'Authorization' => 'Bearer ' . Token::createToken($user));
     $this->taskData['user_id'] = $user->id;
 }
Exemplo n.º 3
0
 /**
  * Safer and better access to HTTP Request Headers.
  *
  * @param  string   $key
  * @static static method
  *
  * @return mixed
  */
 public static function headers($key = null)
 {
     if (static::$headers === null) {
         // Cache the Request Headers, avoiding to process them every time.
         $headers = apache_request_headers();
         if ($headers !== false) {
             static::$headers = array_change_key_case($headers);
         } else {
             // Error on retrieving the Request Headers; use a empty array.
             static::$headers = array();
         }
     }
     if ($key === null) {
         return !empty(static::$headers) ? static::$headers : null;
     }
     return array_key_exists($key, static::$headers) ? static::$headers[$key] : null;
 }
Exemplo n.º 4
0
 public static function getHeader($header)
 {
     $nginx_header = 'HTTP_' . strtoupper(preg_replace('/-/', '_', $header));
     if (isset($_SERVER[$nginx_header])) {
         return $_SERVER[$nginx_header];
     } else {
         if (function_exists('apache_request_headers')) {
             if (empty(static::$headers)) {
                 static::$headers = apache_request_headers();
                 if (!empty(static::$headers[$header])) {
                     return static::$headers[$header];
                 }
             }
         }
     }
     return false;
 }
Exemplo n.º 5
0
 /**
  * Mock JApplicationWeb->clearHeaders method.
  *
  * @return  void
  *
  * @since   3.2
  */
 public static function mockClearHeaders()
 {
     static::$headers = array();
 }
Exemplo n.º 6
0
 /**
  * Reset the class variables to null.
  */
 public static function reset()
 {
     static::$query = null;
     static::$post = null;
     static::$properties = null;
     static::$server = null;
     static::$cookies = null;
     static::$files = null;
     static::$headers = null;
     static::$method = null;
     static::$pathInfo = null;
     static::$requestUri = null;
     static::$requestPath = null;
     static::$basePath = null;
     static::$baseUrl = null;
 }
Exemplo n.º 7
0
 public function __construct()
 {
     static::$instance = $this;
     static::$request = $_REQUEST;
     static::$get = $_GET;
     static::$post = $_POST;
     static::$server = $_SERVER;
     static::$headers = static::getAllHeaders();
     static::$requestUri = static::prepareRequestUri();
     static::$baseUrl = static::prepareBaseUrl();
     static::$basePath = static::prepareBasePath();
     static::$pathInfo = static::preparePathInfo();
     static::$method = static::$server['REQUEST_METHOD'];
 }
Exemplo n.º 8
0
 /**
  * set headers
  *
  * @param $headers
  */
 public static function setHeaders($headers)
 {
     is_array($headers) and static::$headers = $headers;
 }
Exemplo n.º 9
0
 /**
  * Sets up the request.
  */
 public static function init()
 {
     static::$query = new ParameterBag($_GET);
     static::$post = new ParameterBag($_POST);
     static::$properties = new ParameterBag();
     static::$server = new ParameterBag($_SERVER);
     static::$headers = static::buildHeaderBag();
     static::$method = isset($_POST['_method']) ? $_POST['_method'] : $_SERVER['REQUEST_METHOD'];
     static::$requestUri = $_SERVER['REQUEST_URI'];
     static::$scriptName = $_SERVER['SCRIPT_NAME'];
     static::$basePath = rtrim(str_replace(basename(static::$scriptName), '', static::$scriptName), '/');
     static::$pathInfo = str_replace(static::$scriptName, '', static::$requestUri);
     static::$pathInfo = static::preparePathInfo();
     static::$segments = explode('/', trim(static::$pathInfo, '/'));
 }
Exemplo n.º 10
0
 public static function headers($setHeaders = null)
 {
     if ($setHeaders) {
         static::$headers = $setHeaders;
     }
     return static::$headers;
 }
Exemplo n.º 11
0
 public static function headers($headers)
 {
     static::$headers = $headers;
     return new static();
 }