Support module for browser-based test sessions, e.g. for Behat behaviour testing
IMPORTANT: This module is intended for development and testing, it poses a security risk if used on production servers.
It's completely possible to allow any user to become an admin, or do other nefarious things, if this is installed on a live site.
This module starts a testing session in a browser,
in order to test a SilverStripe application in a clean state.
Usually the session is started on a fresh database with only default records loaded.
Further data can be loaded from YAML fixtures or database dumps.
The session is persisted in a file which is generated upon starting the session.
As long as this file exists, the test session is considered in progress,
both in web browsers and command-line execution. By default, the file
is stored in the webroot under
is a random token stored in the browser session, in order to make the
test session specific to the executing browser, and allow multiple
people using their own test session in the same webroot.
The module also serves as an initializer for the
SilverStripe Behat Extension.
It is required for Behat because the Behat CLI test runner needs to persist
test configuration just for the tested browser connection,
available on arbitary URL endpoints. For example,
we're setting up a test mailer which writes every email
into a temporary database table for inspection by the CLI-based process.
Simply require the module in a SilverStripe webroot (3.0 or newer):
composer require --dev silverstripe/behat-extension
You start a test session by manually requesting a certain URL,
and interact with it through other URL endpoints.
dev/testsession: Shows options for starting a test session
dev/testsession/start: Sets up test state, most commonly a test database will be constructed,
dev/testsession/end: Removes the test state, and resets to the original database.
dev/testsession/loadfixture?fixture=<path>: Loads a fixture into an existing test state.
dev/testsession/clear: Empties the test state.
dev/testsession/browsersessionstate: Set or unset browser session state (different from test session state).
While you can use the interface to set the test session state,
it can be useful to set them programmatically through query parameters
fixture: Loads a YAML fixture in the format generally accepted by
createDatabase: Create a temporary database.
importDatabasePath: Absolute path to a database dump to load into a newly created temporary database.
importDatabaseFilename: File name for a database dump to load, relative to
requireDefaultRecords: Include default records as defined on the model classes (in PHP)
database: Set an alternative database name in the current
mailer: Subclass of
Mailer, typically used to record emails instead of actually sending them.
datetime: Sets a simulated date used for all framework operations.
globalTestSession: Activate test session independently of the current browser session,
Example usage with parameters:
Module rating system helping users find modules that are well supported. For more on how the rating system works visit Module standards
Score not correct? Let us know there is a problem