Wt: Wt::Test::WTestEnvironment Class Reference

Wt 4.10.4

Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | List of all members
Wt::Test::WTestEnvironment Class Reference

An environment for testing purposes. More...

`#include <Wt/Test/WTestEnvironment.h>`

Inheritance diagram for Wt::Test::WTestEnvironment:
[legend]

## Public Member Functions
| WTestEnvironment (EntryPointType type=EntryPointType::Application)
| Default constructor.
| WTestEnvironment (const std::string &applicationPath, const std::string &configurationFile, EntryPointType type=EntryPointType::Application)
| Constructor with custom configuration.
| ~WTestEnvironment ()
| Destructor.
void | setParameterMap (const Http::ParameterMap &parameters)
| Sets parameters to the application.
void | setCookies (const CookieMap &cookies)
| Sets HTTP cookies.
void | setHeaderValue (const std::string &value)
| Sets a HTTP header value.
void | setSupportsCookies (bool enabled)
| Sets whether cookies are supported.
void | setAjax (bool enabled)
| Sets whether AJAX is supported.
void | setDpiScale (double dpiScale)
| Sets the display's DPI scale.
void | setLocale (const WLocale &locale)
| Sets the locale.
void | setHostName (const std::string &hostName)
| Sets the host name.
void | setUrlScheme (const std::string &scheme)
| Sets the URL scheme.
void | setUserAgent (const std::string &userAgent)
| Sets the user agent.
void | setReferer (const std::string &referer)
| Sets the referer.
void | setAccept (const std::string &accept)
| Sets the accept header.
void | setServerSignature (const std::string &signature)
| Sets the server signature.
void | setServerSoftware (const std::string &software)
| Sets the server software.
void | setServerAdmin (const std::string &serverAdmin)
| Sets the server admin.
void | setClientAddress (const std::string &clientAddress)
| Sets the client address.
void | setInternalPath (const std::string &internalPath)
| Sets the initial internal path.
void | setDeploymentPath (const std::string &deployPath)
| Sets the deployment path.
void | setAppRoot (const std::string &appRoot)
| Sets the server's appRoot.
void | setDocRoot (const std::string &docRoot)
| Sets the docRoot.
virtual Signal< WDialog * > & | dialogExecuted () const override
| Signal used to test a dialog/messagebox reentrant event loop.
virtual Signal< WPopupMenu * > & | popupExecuted () const override
| Signal used to test a popup menu reentrant event loop.
void | endRequest ()
| Simulates the end of a request by the main event loop.
void | startRequest ()
| Simulates the start of a new request by the main event loop.
void | setSessionIdInUrl (bool sessionIdInUrl)
| Simulates the presence of the session ID in the URL.
Public Member Functions inherited from Wt::WEnvironment
const Http::ParameterMap & | getParameterMap () const
| Parameters passed to the application.
const Http::ParameterValues & | getParameterValues (const std::string &name) const
| Returns values for a query parameter.
const std::string * | getParameter (const std::string &name) const
| Returns a single value for a query parameter.
const CookieMap & | cookies () const
| Returns the cookies from the environment.
const std::string * | getCookie (const std::string &cookieName) const
| Returns a cookie value.
const std::string | headerValue (const std::string &field) const
| Returns a header value.
bool | supportsCookies () const
| Returns whether the browser has enabled support for cookies.
bool | javaScript () const
| Returns whether the browser has enabled support for JavaScript.
bool | ajax () const
| Returns whether the browser has enabled support for AJAX.
bool | webGL () const
| Returns whether the browser has support for WebGL.
int | screenWidth () const
| Returns the horizontal resolution of the client's screen.
int | screenHeight () const
| Returns the vertical resolution of the client's screen.
double | dpiScale () const
| Returns the browser-side DPI scaling factor.
const WLocale & | locale () const
| Returns the preferred language indicated in the request header.
std::chrono::minutes | timeZoneOffset () const
| Returns the time zone offset as reported by the client.
std::string | timeZoneName () const
| Returns the time zone name as reported by the client.
const std::string & | hostName () const
| Returns the server host name that is used by the client.
const std::string & | urlScheme () const
| Returns the URL scheme used for the current request (`"http"` or `"https"`).
const std::string & | userAgent () const
| Returns the user agent.
const std::string & | referer () const
| Returns the referer.
const std::string & | accept () const
| Returns the accept header.
bool | agentIsSpiderBot () const
| Returns if the user agent is a (known) indexing spider bot.
const std::string & | serverSignature () const
| Returns the web server signature.
const std::string & | serverSoftware () const
| Returns the web server software.
const std::string & | serverAdmin () const
| Returns the email address of the server admin.
const std::string & | clientAddress () const
| Returns the IP address of the client.
const std::string & | internalPath () const
| Returns the initial internal path.
const std::string & | deploymentPath () const
| Returns the deployment path.
void | libraryVersion (int &series, int &major, int &minor) const
| Returns the version of the Wt library, broken down.
std::string | getCgiValue (const std::string &varName) const
| Returns a raw CGI environment variable.
HtmlContentType | contentType () const
| The type of the content provided to the browser.
UserAgent | agent () const
| Returns the user agent type.
bool | agentIsIE () const
| Returns whether the user agent is Microsoft Internet Explorer.
bool | agentIsIElt (int version) const
| Returns whether the user agent is an older version of IE.
bool | agentIsIEMobile () const
| Returns whether the user agent is Internet Explorer Mobile.
bool | agentIsOpera () const
| Returns whether the user agent is Opera.
bool | agentIsWebKit () const
| Returns whether the user agent is WebKit-based.
bool | agentIsMobileWebKit () const
| Returns whether the user agent is Mobile WebKit-based.
bool | agentIsSafari () const
| Returns whether the user agent is Safari.
bool | agentIsChrome () const
| Returns whether the user agent is Chrome.
bool | agentIsGecko () const
| Returns whether the user agent is Gecko-based.
WServer * | server () const
| Returns the server.
WSslInfo * | sslInfo () const
| Returns information on the SSL client certificate or `nullptr` if no authentication took place.
bool | internalPathUsingFragments () const
| Returns whether internal paths are implemented using URI fragments.
bool | supportsCss3Animations () const
| Returns whether this agent supports CSS3 animations.

## Private Member Functions
virtual bool | isTest () const override
| Returns whether this is a mocked test environment.

## Additional Inherited Members
Public Types inherited from Wt::WEnvironment
typedef std::map< std::string, std::string > | CookieMap
| Cookie map.
Static Public Member Functions inherited from Wt::WEnvironment
static std::string | libraryVersion ()
| Returns the version of the Wt library.
Protected Member Functions inherited from Wt::WEnvironment
Protected Attributes inherited from Wt::WEnvironment

## Detailed Description

An environment for testing purposes.

This environment is useful for use in automated (integration/unit) tests: you may configure its properties and pass it to the constructor of an application.

This is useful for automated test-cases:

void testX() {
Test::WTestEnvironment environment;
MyApplication app(environment);
...
}
Wt::Test::WTestEnvironment
An environment for testing purposes.
Definition WTestEnvironment.h:56

See also
  WEnvironment, WApplication::WApplication(const WEnvironment&)

## Constructor & Destructor Documentation

## ◆ WTestEnvironment() [1/2]

Wt::Test::WTestEnvironment::WTestEnvironment | ( | EntryPointType | type = EntryPointType::Application | ) |

Default constructor.

Constructs a test environment that resembles FireFox 3.0 with default settings.

After construction, but before passing it to the constructor of a WApplication, you can change any of the environment properties using the setter methods.

## ◆ WTestEnvironment() [2/2]

Wt::Test::WTestEnvironment::WTestEnvironment | ( | const std::string & | applicationPath,
|  | const std::string & | configurationFile,
|  | EntryPointType | type = EntryPointType::Application )

Constructor with custom configuration.

Constructs a test environment that resembles FireFox 3.0 with default settings.

The applicationPath is the simulated application path used to match `<application-settings>` in the configuration file. The configuration file points to a wt_config.xml configuration file. The type indicates the application type.

After construction, but before passing it to the constructor of a WApplication, you can change any of the environment properties using the setter methods.

## Member Function Documentation

## ◆ dialogExecuted()

virtual Signal< WDialog * > & Wt::Test::WTestEnvironment::dialogExecuted | ( |  | ) | const
| overridevirtual

Signal used to test a dialog/messagebox reentrant event loop.

This signal is emitted when a dialog or message box is being executed using WDialog::exec() or WMessageBox::exec(), and allows you to interact with the dialog contents.

In the end, the dialog should be closed while executing this signal, (calling done() directly or indirectly) so that the main event loop can continue.

Reimplemented from Wt::WEnvironment.

## ◆ endRequest()

void Wt::Test::WTestEnvironment::endRequest | ( |  | ) |

Simulates the end of a request by the main event loop.

The environemnt (and application is) started from within the main event loop. To simulate the delivery of events posted to the application-under-test, by WServer::post(), you need to simulate the release of the session lock.

See also
  startRequest()

## ◆ popupExecuted()

virtual Signal< WPopupMenu * > & Wt::Test::WTestEnvironment::popupExecuted | ( |  | ) | const
| overridevirtual

Signal used to test a popup menu reentrant event loop.

This signal is emitted when a popup menu is being executed using WPopupMenu::exec(), and allows you to interact with the popup menu (i.e. to select an option).

See also
  dialogExecuted()

Reimplemented from Wt::WEnvironment.

## ◆ setAccept()

void Wt::Test::WTestEnvironment::setAccept | ( | const std::string & | accept | ) |

Sets the accept header.

The default value is "text/html,application/xhtml+xml,application/xml;q=0.9,*<span>/</span>*;q=0.8".

See also
  accept()

## ◆ setAjax()

void Wt::Test::WTestEnvironment::setAjax | ( | bool | enabled | ) |

Sets whether AJAX is supported.

The default value is true.

See also
  ajax()

## ◆ setAppRoot()

void Wt::Test::WTestEnvironment::setAppRoot | ( | const std::string & | appRoot | ) |

Sets the server's appRoot.

See also
  WServer::appRoot()

## ◆ setClientAddress()

void Wt::Test::WTestEnvironment::setClientAddress | ( | const std::string & | clientAddress | ) |

Sets the client address.

The default value is "127.0.0.1".

See also
  clientAddress()

## ◆ setCookies()

void Wt::Test::WTestEnvironment::setCookies | ( | const CookieMap & | cookies | ) |

Sets HTTP cookies.

The default value is an empty map.

See also
  cookies()

## ◆ setDeploymentPath()

void Wt::Test::WTestEnvironment::setDeploymentPath | ( | const std::string & | deployPath | ) |

Sets the deployment path.

The default value is "".

See also
  deploymentPath()

## ◆ setDocRoot()

void Wt::Test::WTestEnvironment::setDocRoot | ( | const std::string & | docRoot | ) |

Sets the docRoot.

See also
  WApplication::docRoot()

## ◆ setDpiScale()

void Wt::Test::WTestEnvironment::setDpiScale | ( | double | dpiScale | ) |

Sets the display's DPI scale.

The default value is 1.

See also
  dpiScale()

## ◆ setHeaderValue()

void Wt::Test::WTestEnvironment::setHeaderValue | ( | const std::string & | value | ) |

Sets a HTTP header value.

The default value is no headers.

See also
  headerValue()

## ◆ setHostName()

void Wt::Test::WTestEnvironment::setHostName | ( | const std::string & | hostName | ) |

Sets the host name.

The default value is "localhost".

See also
  hostName()

## ◆ setInternalPath()

void Wt::Test::WTestEnvironment::setInternalPath | ( | const std::string & | internalPath | ) |

Sets the initial internal path.

The default value is "".

See also
  internalPath()

## ◆ setLocale()

void Wt::Test::WTestEnvironment::setLocale | ( | const WLocale & | locale | ) |

Sets the locale.

The default value is WLocale("en").

See also
  locale()

## ◆ setParameterMap()

void Wt::Test::WTestEnvironment::setParameterMap | ( | const Http::ParameterMap & | parameters | ) |

Sets parameters to the application.

The default value is an empty map.

See also
  getParameterMap()

## ◆ setReferer()

void Wt::Test::WTestEnvironment::setReferer | ( | const std::string & | referer | ) |

Sets the referer.

The default value is "".

See also
  referer()

## ◆ setServerAdmin()

void Wt::Test::WTestEnvironment::setServerAdmin | ( | const std::string & | serverAdmin | ) |

Sets the server admin.

The default value is "your@onyourown.here".

See also
  serverAdmin()

## ◆ setServerSignature()

void Wt::Test::WTestEnvironment::setServerSignature | ( | const std::string & | signature | ) |

Sets the server signature.

The default value is "None (WTestEnvironment)".

See also
  serverSignature()

## ◆ setServerSoftware()

void Wt::Test::WTestEnvironment::setServerSoftware | ( | const std::string & | software | ) |

Sets the server software.

The default value is "None (WTestEnvironment)".

See also
  serverSoftware()

## ◆ setSessionIdInUrl()

void Wt::Test::WTestEnvironment::setSessionIdInUrl | ( | bool | sessionIdInUrl | ) |

Simulates the presence of the session ID in the URL.

A session ID in the URL should cause a trampoline to be used for references to external servers.

The default value is `false`.

## ◆ setSupportsCookies()

void Wt::Test::WTestEnvironment::setSupportsCookies | ( | bool | enabled | ) |

Sets whether cookies are supported.

The default value is true.

See also
  supportsCookies()

## ◆ setUrlScheme()

void Wt::Test::WTestEnvironment::setUrlScheme | ( | const std::string & | scheme | ) |

Sets the URL scheme.

The default value is "http".

See also
  urlScheme()

## ◆ setUserAgent()

void Wt::Test::WTestEnvironment::setUserAgent | ( | const std::string & | userAgent | ) |

Sets the user agent.

The default value is no "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.11) Gecko/2009060309 Ubuntu/9.04 (jaunty) Firefox/3.0.11".

See also
  userAgent()

## ◆ startRequest()

void Wt::Test::WTestEnvironment::startRequest | ( |  | ) |

Simulates the start of a new request by the main event loop.

See also
  endRequest()