Properties

$client

$client : \Goutte\Client

Type

\Goutte\Client

$cache_dir

$cache_dir : string

Type

string

$wp_original_options

$wp_original_options : array

Type

array

$wp_options

$wp_options : array

Type

array

$post_count

$post_count : integer

Type

integer

$term_count

$term_count : integer

Type

integer

$is_admin

$is_admin : 

Should we test in admin environment?

$wp_version

$wp_version : 

WordPress version.

$plugin

$plugin : 

Methods

setUp()

setUp() 

Prepare the WP environment

This will prepare the environment for the current session as well as any following requests made to the current test installation using a client such as a crawler or a browser

setUpForCurrentRequest()

setUpForCurrentRequest() 

Prepares the WP environment, but for current request only

This means we don't need to prepare config and htaccess stuff

tearDown()

tearDown() 

setUpBeforeClass()

setUpBeforeClass() 

tearDownAfterClass()

tearDownAfterClass() 

commit_transaction()

commit_transaction() 

Commit the queries in a transaction.

This function is provided by WordPress only from version 4.1 onwards, but because we still maintain support for WordPress 3.8 for certain plugins, we add this function to make sure plugin tests that requires commit of transactions can still be built against verrsion 3.8.

get_plugin_under_test()

get_plugin_under_test() 

get_extra_plugins()

get_extra_plugins() : array

Get a list of extra plugins that should be loaded and activated for testing

This can include fxitures if needed.

Returns

array

get_all_plugins()

get_all_plugins() : array

Get a list of all plugins, including the plugin under test and extra ones

Returns

array

prepare_plugin_directories()

prepare_plugin_directories() 

Prepare plugin directories

This should create symlinks to the plugins' folders from wp-content/plugins directory so that they can be activated and used later on

load_plugins_for_current_process()

load_plugins_for_current_process() 

Load all required plugins for current process

This should be called by extending testcases explicitly. This only loads actual plugins, not fixtures.

pre_option_active_plugins()

pre_option_active_plugins() : array

Filter `pre_option_active_plugins` hook.

Returns

array

prepare_wp_config()

prepare_wp_config() 

prepare_htaccess_file()

prepare_htaccess_file() 

prepare_cache_directory()

prepare_cache_directory(string  $cache_dir = null) 

Prepare a blank cache folder for every test

Parameters

string $cache_dir

prepare_asset_directories()

prepare_asset_directories() 

Prepare js and css directories if not existed

set_wp_default_options()

set_wp_default_options() 

Set WP options that are used for all tests

We backup the orignal WP options so we can reset the options in db after every test

set_wp_options()

set_wp_options(array  $options) 

Set WP options that are used for a specific test

Parameters

array $options

an associative array of key => value

set_plugin_default_options()

set_plugin_default_options() 

Set default options that are used for all tests

set_options()

set_options(string  $option_key, array  $options) 

Set options used with a specific testcase

Parameters

string $option_key
array $options

a subset of options to be set

activate_plugins()

activate_plugins(array  $plugins) 

Activate specific plugins

This only affect actual requests made to the test site

Parameters

array $plugins

deactivate_plugins()

deactivate_plugins(array  $plugins = array()) 

Deactivate plugins

This only affect actual requests made to the test site

Parameters

array $plugins

optional, default is to deactivate all plugins

update_option()

update_option(string  $key, mixed  $value) 

Parameters

string $key
mixed $value

delete_option()

delete_option(string  $key) 

Parameters

string $key

reset_users()

reset_users() 

Reset users to installed state

This should not reset the initial 'admin' user

reset_posts()

reset_posts() 

reset_terms()

reset_terms() 

reset_posts_terms()

reset_posts_terms() 

reset_comments()

reset_comments() 

get_client()

get_client(boolean  $use_existing = true, boolean  $use_cache = false) : \Goutte\Client

Parameters

boolean $use_existing

whether to create a new client or use existing if any, default to true

boolean $use_cache

whether to use http cache

Returns

\Goutte\Client

get_client_clone()

get_client_clone() : \Goutte\Client

Returns

\Goutte\Client

get_crawler_from_url()

get_crawler_from_url(string  $url, array  $headers = array()) : \Symfony\Component\DomCrawler\Crawler

Get a Crawler instance from a URL.

Parameters

string $url
array $headers

Returns

\Symfony\Component\DomCrawler\Crawler

get_crawler_from_post()

get_crawler_from_post(\WP_Post  $post) : \Symfony\Component\DomCrawler\Crawler

Parameters

\WP_Post $post

Returns

\Symfony\Component\DomCrawler\Crawler

get_uri_from_client()

get_uri_from_client(\Goutte\Client  $client) : string

Get the requested uri from a Client object.

Parameters

\Goutte\Client $client

Returns

string

create_term_and_get()

create_term_and_get(  $taxonomy = 'category') 

Create a dummy term for testing.

Parameters

$taxonomy

create_many_terms()

create_many_terms(integer  $count, array  $args = array(), array|null  $generation_definitions = null) 

Create many dummy terms for testing.

Since WordPress 4.4 the WP_UnitTest_Generator_Sequence has been using a static counter, which makes the data of created dummy items unpredictable. This method is used to create dummy items in a predictable manner. This is mostly the same as WP_UnitTest_Factory::create_many().

Parameters

integer $count
array $args
array|null $generation_definitions

create_post_and_get()

create_post_and_get(string  $post_type = 'post') 

Create a dummy post for testing.

Parameters

string $post_type

create_many_posts()

create_many_posts(integer  $count, array  $args = array(), array|null  $generation_definitions = null) 

Create many dummy posts for testing.

Parameters

integer $count
array $args
array|null $generation_definitions

set_plugin()

set_plugin() 

Set plugin property.

reset_plugin_options()

reset_plugin_options() 

Reset plugin options to their default values.

Implementing class can then use self::set_plugin_default_options to set default options for the whole test class.

prepare_default_values()

prepare_default_values() 

Prepare default values including options and active plugins

prepare_theme_directories()

prepare_theme_directories() 

WordPress 4.7 started to carrying out tests based on a default blank theme. Since this theme is not copied to `wp-content` folder of the test site, when we try to open the site using a browser, the theme is broken because it does not exist.

load_fixtures()

load_fixtures(  $file_name = null) 

This should be used explicitly by extending testcases

Parameters

$file_name

bootstrap_plugin()

bootstrap_plugin() 

get_wp_version()

get_wp_version(  $version = '') : mixed

Get current WP version

If a WP version is provided as the first parameter, check if the current WP version is greater than or equal to that provided version

Parameters

$version

Returns

mixed

uniqid()

uniqid() : string

Returns

string

create_post()

create_post(  $post_type = 'post') 

Parameters

$post_type

create_posts()

create_posts(  $post_type = 'post',   $count = 5,   $post_date_gmt = null) 

Parameters

$post_type
$count
$post_date_gmt

create_terms()

create_terms(  $taxonomy = 'category',   $count = 5) 

Parameters

$taxonomy
$count