PHP Class VersionPress\Tests\Automation\WpAutomation

You should have the whole development environment set up as described on our wiki. Specifically, these are required: - WP-CLI (wp --info works in console) - NPM packages installed in - Gulp (gulp -v works in console) - test-config.yml file created in versionpress/tests Currently, WpAutomation is a set of static functions as of v1; other options will be considered for v2, see WP-56. Note: Currently, the intention is to add supported tasks as public methods to this class. If this gets unwieldy it will probably be split into multiple files / classes.
Mostra file Open project: versionpress/versionpress Class Usage Examples

Public Methods

Method Description
__construct ( SiteConfig $siteConfig, string $wpCliVersion )
activateVersionPress ( ) Activates VersionPress as a plugin (does not start tracking the site; use initializeVersionPress() for that).
addMenuItem ( integer | string $menu, string $type, array $item ) : integer Adds menu item using WP-CLI. Returns ID of created menu item.
approveComment ( $id )
copyVersionPressFiles ( ) Copies VP files to the test site and possibly removes all old files from there. It does so using a Gulp script which specifies which paths to include and which ones to ignore.
createComment ( array $comment ) : integer Creates new comment using WP-CLI. Returns ID of created comment.
createCommentMeta ( $id, $name, $value ) Creates new commentmeta using WP-CLI for given comment.
createMenu ( string $name ) : integer Creates new menu using WP-CLI. Returns ID of created menu.
createOption ( string $name, mixed $value ) Creates new option using WP-CLI.
createPost ( array $post ) : integer Creates new post using WP-CLI. Returns ID of created post.
createUser ( array $user ) : integer Creates new user using WP-CLI. Returns ID of created user.
deleteComment ( $id ) Deletes the comment using WP-CLI.
deleteCommentMeta ( $id, $name ) Deletes commentmeta using WP-CLI for given comment.
deleteMenu ( integer | string $menu ) Deletes menu item using WP-CLI.
deleteOption ( string $name ) Deletes option with given name using WP-CLI.
deletePost ( $id ) Deletes the post using WP-CLI.
deleteUser ( $id ) Deletes the user using WP-CLI.
deleteWidgets ( string[] | string $widgets ) Deletes widget(s)
disableDebugger ( )
editComment ( $id, $changes ) Changes the comment using WP-CLI.
editMenu ( $id, $name ) Changes the menu using WP-CLI.
editMenuItem ( integer $id, array $changes ) : integer Updates menu item using WP-CLI.
editOption ( string $name, mixed $value ) Changes option with given name using WP-CLI.
editPost ( $id, $changes ) Changes the post using WP-CLI.
editUser ( $id, $changes ) Changes the user using WP-CLI.
editUserMeta ( $id, $name, $value ) Changes the user using WP-CLI.
getAbspath ( )
getComments ( )
getCurrentTheme ( ) : string Returns stylesheet of current theme.
getPluginsDir ( )
getSidebars ( ) : array Returns list of sidebar IDs defined by current template (without wp_inactive_widgets).
getUploadsDir ( )
getVpdbDir ( )
getWebRoot ( )
getWidgets ( string $sidebar ) : array Returns list of widgets in given sidebar.
getWpCli ( ) : string Checks whether a WP-CLI binary is available, possibly downloads it and returns the path to it.
importMedia ( $files )
initializeVersionPress ( ) Activates VersionPress plugin and runs the Initializer. For just activation, use activateVersionPress().
installWordPress ( ) Installs WordPress. Assumes that files have been prepared on the file system, database is clean and wp-config.php has been created.
isSiteSetUp ( ) : boolean Returns true if the site is installed and working
isVersionPressInitialized ( ) : boolean Returns true if VersionPress is active and tracking the site
populateSite ( $entityCounts ) Populates the site with random entities. Their counts are specified by parameter $entityCounts: array( 'posts' => 100, 'comments => 500, 'options' => 50, 'users' => 10, 'terms' => 20 )
removeMenuItem ( integer $id ) Removes menu item using WP-CLI.
runWpCliCommand ( string $command, string $subcommand, array $args = [], boolean $debug = false ) : string Executes a WP-CLI command http://wp-Cli.org/commands/
setUpSite ( array $entityCounts = [] ) Does a full setup of a WP site including removing the old site, downloading files from wp.org, setting up a fresh database, executing the install script etc.
spamComment ( $id )
switchTheme ( string $theme )
trashComment ( $id )
unapproveComment ( $id )
uninstallVersionPress ( )
unspamComment ( $id )
untrashComment ( $id )

Private Methods

Method Description
checkLatestStableChecksum ( $wpCliTmpPath )
clearDatabase ( ) Deletes all tables from the database.
createConfigFile ( ) Creates wp-config.php
createPedestalBasedSite ( ) Creates project structure similar to Bedrock.
disableAutoUpdate ( )
ensureCleanInstallationIsAvailable ( ) Ensures that the clean installation of WordPress is available locally. If not, downloads it from wp.org and stores it as /.
exec ( string $command, string $executionPath = null, boolean $debug = false, null | array $env = null ) : string Executes a command. If the command is WP-CLI command (starts with "wp .
fileIsOlderThanDays ( $filePath, $days )
getCleanInstallationPath ( ) : string Returns a path where a clean installation of the configured WP version is stored and cached.
getWpCliDownloadUrl ( )
isCorrectlyDownloaded ( string $cleanInstallationPath ) : boolean Checks that clean WP installation is available and downloaded correctly. (Simple implementation for now, just checking some basic paths.)
prepareStandardWpInstallation ( ) Puts WP directory to a default state, as if one manually downloaded the WordPress ZIP and extracted it there. Removes all old files if necessary.
rewriteWpCliCommand ( string $command ) : string Rewrites WP-CLI command to use a well-known binary and to possibly rewrite it for remote execution over SSH. If the command is not a WP-CLI command (doesn't start with "wp .
updateConfigConstant ( $constant, $value, $variable = false )

Method Details

__construct() public method

public __construct ( SiteConfig $siteConfig, string $wpCliVersion )
$siteConfig VersionPress\Tests\Utils\SiteConfig
$wpCliVersion string

activateVersionPress() public method

Activates VersionPress as a plugin (does not start tracking the site; use initializeVersionPress() for that).

addMenuItem() public method

Adds menu item using WP-CLI. Returns ID of created menu item.
public addMenuItem ( integer | string $menu, string $type, array $item ) : integer
$menu integer | string
$type string post|custom|term
$item array
return integer

approveComment() public method

public approveComment ( $id )

copyVersionPressFiles() public method

See \gulpfile.js.

createComment() public method

Creates new comment using WP-CLI. Returns ID of created comment.
public createComment ( array $comment ) : integer
$comment array (as wp_insert_comment)
return integer

createCommentMeta() public method

Creates new commentmeta using WP-CLI for given comment.
public createCommentMeta ( $id, $name, $value )
$id
$name
$value

createMenu() public method

Creates new menu using WP-CLI. Returns ID of created menu.
public createMenu ( string $name ) : integer
$name string
return integer

createOption() public method

Creates new option using WP-CLI.
public createOption ( string $name, mixed $value )
$name string
$value mixed

createPost() public method

Creates new post using WP-CLI. Returns ID of created post.
See also: wp_insert_post()
public createPost ( array $post ) : integer
$post array (as wp_insert_post)
return integer

createUser() public method

Creates new user using WP-CLI. Returns ID of created user.
public createUser ( array $user ) : integer
$user array (as wp_insert_comment)
return integer

deleteComment() public method

Deletes the comment using WP-CLI.
public deleteComment ( $id )
$id

deleteCommentMeta() public method

Deletes commentmeta using WP-CLI for given comment.
public deleteCommentMeta ( $id, $name )
$id
$name

deleteMenu() public method

Deletes menu item using WP-CLI.
public deleteMenu ( integer | string $menu )
$menu integer | string

deleteOption() public method

Deletes option with given name using WP-CLI.
public deleteOption ( string $name )
$name string

deletePost() public method

Deletes the post using WP-CLI.
public deletePost ( $id )
$id

deleteUser() public method

Deletes the user using WP-CLI.
public deleteUser ( $id )
$id

deleteWidgets() public method

Deletes widget(s)
public deleteWidgets ( string[] | string $widgets )
$widgets string[] | string Name of widget or list of widgets

disableDebugger() public method

public disableDebugger ( )

editComment() public method

Changes the comment using WP-CLI.
public editComment ( $id, $changes )
$id
$changes

editMenu() public method

Changes the menu using WP-CLI.
public editMenu ( $id, $name )
$id
$name

editMenuItem() public method

Updates menu item using WP-CLI.
public editMenuItem ( integer $id, array $changes ) : integer
$id integer
$changes array
return integer

editOption() public method

Changes option with given name using WP-CLI.
public editOption ( string $name, mixed $value )
$name string
$value mixed

editPost() public method

Changes the post using WP-CLI.
public editPost ( $id, $changes )
$id
$changes

editUser() public method

Changes the user using WP-CLI.
public editUser ( $id, $changes )
$id
$changes

editUserMeta() public method

Changes the user using WP-CLI.
public editUserMeta ( $id, $name, $value )
$id
$name
$value

getAbspath() public method

public getAbspath ( )

getComments() public method

public getComments ( )

getCurrentTheme() public method

Returns stylesheet of current theme.
public getCurrentTheme ( ) : string
return string

getPluginsDir() public method

public getPluginsDir ( )

getSidebars() public method

Returns list of sidebar IDs defined by current template (without wp_inactive_widgets).
public getSidebars ( ) : array
return array

getUploadsDir() public method

public getUploadsDir ( )

getVpdbDir() public method

public getVpdbDir ( )

getWebRoot() public method

public getWebRoot ( )

getWidgets() public method

Returns list of widgets in given sidebar.
public getWidgets ( string $sidebar ) : array
$sidebar string sidebar id
return array

getWpCli() public method

We use a custom WP-CLI PHAR (latest stable). The local custom binary is re-downloaded every day to keep it fresh (stable WP-CLI releases go out every couple of months).
public getWpCli ( ) : string
return string The path to the custom WP-CLI PHAR.

importMedia() public method

public importMedia ( $files )

initializeVersionPress() public method

Activates VersionPress plugin and runs the Initializer. For just activation, use activateVersionPress().

installWordPress() public method

Installs WordPress. Assumes that files have been prepared on the file system, database is clean and wp-config.php has been created.
public installWordPress ( )

isSiteSetUp() public method

Returns true if the site is installed and working
public isSiteSetUp ( ) : boolean
return boolean

isVersionPressInitialized() public method

Returns true if VersionPress is active and tracking the site

populateSite() public method

Populates the site with random entities. Their counts are specified by parameter $entityCounts: array( 'posts' => 100, 'comments => 500, 'options' => 50, 'users' => 10, 'terms' => 20 )
public populateSite ( $entityCounts )
$entityCounts

removeMenuItem() public method

Removes menu item using WP-CLI.
public removeMenuItem ( integer $id )
$id integer

runWpCliCommand() public method

Executes a WP-CLI command http://wp-Cli.org/commands/
public runWpCliCommand ( string $command, string $subcommand, array $args = [], boolean $debug = false ) : string
$command string Like "core"
$subcommand string Like "config". Might be null, e.g. if the main command is "eval" there is no subcommand
$args array Like array("dbname" => "wordpress", "dbuser" => "wpuser", "positionalargument") which will produce something like `--dbname='wordpress' --dbuser='wpuser' 'positionalargument'`
$debug boolean
return string

setUpSite() public method

Database as specified in the config file must exist and be accessible. It takes optional parameter entityCounts, that is an array containing an amount of generated entities - {@see \populateSite}.
public setUpSite ( array $entityCounts = [] )
$entityCounts array

spamComment() public method

public spamComment ( $id )

switchTheme() public method

public switchTheme ( string $theme )
$theme string Theme stylesheet

trashComment() public method

public trashComment ( $id )

unapproveComment() public method

public unapproveComment ( $id )

uninstallVersionPress() public method

unspamComment() public method

public unspamComment ( $id )

untrashComment() public method

public untrashComment ( $id )