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.
Afficher le fichier Open project: versionpress/versionpress Class Usage Examples

Méthodes publiques

Méthode 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

Méthode 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 méthode

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

activateVersionPress() public méthode

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

addMenuItem() public méthode

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
Résultat integer

approveComment() public méthode

public approveComment ( $id )

copyVersionPressFiles() public méthode

See \gulpfile.js.

createComment() public méthode

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

createCommentMeta() public méthode

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

createMenu() public méthode

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

createOption() public méthode

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

createPost() public méthode

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)
Résultat integer

createUser() public méthode

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

deleteComment() public méthode

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

deleteCommentMeta() public méthode

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

deleteMenu() public méthode

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

deleteOption() public méthode

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

deletePost() public méthode

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

deleteUser() public méthode

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

deleteWidgets() public méthode

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

disableDebugger() public méthode

public disableDebugger ( )

editComment() public méthode

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

editMenu() public méthode

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

editMenuItem() public méthode

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

editOption() public méthode

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

editPost() public méthode

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

editUser() public méthode

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

editUserMeta() public méthode

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

getAbspath() public méthode

public getAbspath ( )

getComments() public méthode

public getComments ( )

getCurrentTheme() public méthode

Returns stylesheet of current theme.
public getCurrentTheme ( ) : string
Résultat string

getPluginsDir() public méthode

public getPluginsDir ( )

getSidebars() public méthode

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

getUploadsDir() public méthode

public getUploadsDir ( )

getVpdbDir() public méthode

public getVpdbDir ( )

getWebRoot() public méthode

public getWebRoot ( )

getWidgets() public méthode

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

getWpCli() public méthode

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
Résultat string The path to the custom WP-CLI PHAR.

importMedia() public méthode

public importMedia ( $files )

initializeVersionPress() public méthode

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

installWordPress() public méthode

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 méthode

Returns true if the site is installed and working
public isSiteSetUp ( ) : boolean
Résultat boolean

isVersionPressInitialized() public méthode

Returns true if VersionPress is active and tracking the site
public isVersionPressInitialized ( ) : boolean
Résultat boolean

populateSite() public méthode

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 méthode

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

runWpCliCommand() public méthode

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
Résultat string

setUpSite() public méthode

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 méthode

public spamComment ( $id )

switchTheme() public méthode

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

trashComment() public méthode

public trashComment ( $id )

unapproveComment() public méthode

public unapproveComment ( $id )

uninstallVersionPress() public méthode

unspamComment() public méthode

public unspamComment ( $id )

untrashComment() public méthode

public untrashComment ( $id )