MediaWiki REL1_32
MockWebRequest Class Reference

A mock WebRequest. More...

Inheritance diagram for MockWebRequest:
Collaboration diagram for MockWebRequest:

Public Member Functions

 __construct (WebResponse $response)
 
 response ()
 Return a handle to WebResponse style object, for setting cookies, headers and other stuff, for Request being worked on.
 
- Public Member Functions inherited from WebRequest
 __construct ()
 
 appendQueryArray ( $array)
 Appends or replaces value of query variables.
 
 appendQueryValue ( $key, $value)
 
 checkUrlExtension ( $extWhitelist=[])
 Check if Internet Explorer will detect an incorrect cache extension in PATH_INFO or QUERY_STRING.
 
 getAcceptLang ()
 Parse the Accept-Language header sent by the client into an array.
 
 getAllHeaders ()
 Get an array containing all request headers.
 
 getArray ( $name, $default=null)
 Fetch an array from the input or return $default if it's not set.
 
 getBool ( $name, $default=false)
 Fetch a boolean value from the input or return $default if not set.
 
 getCheck ( $name)
 Return true if the named value is set in the input, whatever that value is (even "0").
 
 getCookie ( $key, $prefix=null, $default=null)
 Get a cookie from the $_COOKIE jar.
 
 getElapsedTime ()
 Get the number of seconds to have elapsed since request start, in fractional seconds, with microsecond resolution.
 
 getFileName ( $key)
 Return the original filename of the uploaded file, as reported by the submitting user agent.
 
 getFileTempname ( $key)
 Return the path to the temporary file where PHP has stored the upload.
 
 getFloat ( $name, $default=0.0)
 Fetch a floating point value from the input or return $default if not set.
 
 getFullRequestURL ()
 Return the request URI with the canonical service and hostname, path, and query string.
 
 getFuzzyBool ( $name, $default=false)
 Fetch a boolean value from the input or return $default if not set.
 
 getHeader ( $name, $flags=0)
 Get a request header, or false if it isn't set.
 
 getInt ( $name, $default=0)
 Fetch an integer value from the input or return $default if not set.
 
 getIntArray ( $name, $default=null)
 Fetch an array of integers, or return $default if it's not set.
 
 getIntOrNull ( $name)
 Fetch an integer value from the input or return null if empty.
 
 getIP ()
 Work out the IP address based on various globals For trusted proxies, use the XFF client IP (first of the chain)
 
 getLimitOffset ( $deflimit=50, $optionname='rclimit')
 Check for limit and offset parameters on the input, and return sensible defaults if not given.
 
 getMethod ()
 Get the HTTP method used for this request.
 
 getPostValues ()
 Get the values passed via POST.
 
 getProtocol ()
 Get the current URL protocol (http or https)
 
 getQueryValues ()
 Get the values passed in the query string.
 
 getRawInput ()
 Return the raw request body, with no processing.
 
 getRawPostString ()
 Return the contents of the POST with no decoding.
 
 getRawQueryString ()
 Return the contents of the Query with no decoding.
 
 getRawVal ( $name, $default=null)
 Fetch a scalar from the input without normalization, or return $default if it's not set.
 
 getRequestURL ()
 Return the path and query string portion of the request URI.
 
 getSession ()
 Return the session for this request.
 
 getSessionData ( $key)
 Get data from the session.
 
 getSessionId ()
 Get the session id for this request, if any.
 
 getText ( $name, $default='')
 Fetch a text string from the given array or return $default if it's not set.
 
 getUpload ( $key)
 Return a WebRequestUpload object corresponding to the key.
 
 getUploadError ( $key)
 Return the upload error or 0.
 
 getVal ( $name, $default=null)
 Fetch a scalar from the input or return $default if it's not set.
 
 getValueNames ( $exclude=[])
 Returns the names of all input values excluding those in $exclude.
 
 getValues ()
 Extracts the given named values into an array.
 
 hasSafeMethod ()
 Check if this request uses a "safe" HTTP method.
 
 interpolateTitle ()
 Check for title, action, and/or variant data in the URL and interpolate it into the GET variables.
 
 isSafeRequest ()
 Whether this request should be identified as being "safe".
 
 markAsSafeRequest ()
 Mark this request as identified as being nullipotent even if it is a POST request.
 
 normalizeUnicode ( $data)
 Recursively normalizes UTF-8 strings in the given array.
 
 setIP ( $ip)
 
 setSessionData ( $key, $data)
 Set session data.
 
 setSessionId (SessionId $sessionId)
 Set the session for this request.
 
 setVal ( $key, $value)
 Set an arbitrary value into our get/post data.
 
 unsetVal ( $key)
 Unset an arbitrary value from our get/post data.
 
 wasPosted ()
 Returns true if the present request was reached by a POST operation, false otherwise (GET, HEAD, or command-line).
 

Protected Attributes

WebResponse $response
 
- Protected Attributes inherited from WebRequest
 $data
 
 $headers = []
 
bool $markedAsSafe = false
 Whether this HTTP request is "safe" (even if it is an HTTP post)
 
string $protocol
 Cached URL protocol.
 
float $requestTime
 The timestamp of the start of the request, with microsecond precision.
 
SessionId null $sessionId = null
 Session ID to use for this request.
 

Additional Inherited Members

- Static Public Member Functions inherited from WebRequest
static detectProtocol ()
 Detect the protocol from $_SERVER.
 
static detectServer ()
 Work out an appropriate URL prefix containing scheme and host, based on information detected from $_SERVER.
 
static extractTitle ( $path, $bases, $key=false)
 URL rewriting function; tries to extract page title and, optionally, one other fixed parameter value from a URL path.
 
static getGlobalRequestURL ()
 Return the path and query string portion of the main request URI.
 
static getPathInfo ( $want='all')
 Extract relevant query arguments from the http request uri's path to be merged with the normal php provided query arguments.
 
static getRequestId ()
 Get the unique request ID.
 
static overrideRequestId ( $id)
 Override the unique request ID.
 
- Public Attributes inherited from WebRequest
const GETHEADER_LIST = 1
 Flag to make WebRequest::getHeader return an array of values.
 
- Protected Member Functions inherited from WebRequest
 doSecurityRedirect ( $url)
 Attempt to redirect to a URL with a QUERY_STRING that's not dangerous in IE 6.
 
 getRawIP ()
 Fetch the raw IP from the request.
 
 initHeaders ()
 Initialise the header list.
 

Detailed Description

A mock WebRequest.

If the code under test accesses the response via the request (see WebRequest::response), then you might be able to use this mock to simplify your tests.

Definition at line 10 of file MockWebRequest.php.

Constructor & Destructor Documentation

◆ __construct()

MockWebRequest::__construct ( WebResponse $response)

Definition at line 16 of file MockWebRequest.php.

References $response, and response().

Member Function Documentation

◆ response()

MockWebRequest::response ( )

Return a handle to WebResponse style object, for setting cookies, headers and other stuff, for Request being worked on.

Returns
WebResponse

Reimplemented from WebRequest.

Definition at line 22 of file MockWebRequest.php.

References $response.

Referenced by __construct().

Member Data Documentation

◆ $response

WebResponse MockWebRequest::$response
protected

Definition at line 14 of file MockWebRequest.php.

Referenced by __construct(), and response().


The documentation for this class was generated from the following file: