This is the documentation for version 3 of the project.The current version is version 4 and the documentation can be found here.
WPFilesystem module
This module should be used in acceptance and functional tests, see levels of testing for more information.
This module extends the Filesystem module adding WordPress-specific configuration parameters and methods.
The module provides methods to read, write and update the WordPress filesystem directly, without relying on WordPress methods, using WordPress functions or triggering WordPress filters.
This module also provides methods to scaffold plugins and themes on the fly in the context of tests and auto-remove them after each test.
Module requirements for Codeception 4.0+
This module requires the codeception/module-filesystem Composer package to work when wp-browser is used with Codeception 4.0.
wpRootFolderrequired The absolute, or relative to the project root folder, path to the root WordPress installation folder. The WordPress installation root folder is the one that contains the wp-load.php file.
themes - defaults to /wp-content/themes; the path, relative to the the WordPress installation root folder, to the themes folder.
plugins - defaults to /wp-content/plugins; the path, relative to the WordPress installation root folder, to the plugins folder.
mu-plugins - defaults to wp-content/mu-plugins; the path, relative to the WordPress installation root folder, to the must-use plugins folder.
uploads - defaults to /wp-content/uploads; the path, relative to the WordPress installation root folder, to the uploads folder.
string$path - The path, relative to the site uploads folder.
cleanMuPluginDir
Cleans, emptying it, a folder in a mu-plugin folder.
$I->cleanMuPluginDir('mu-plugin1/foo');
Parameters
string$dir - The path to the directory, relative to the mu-plugins root folder.
cleanPluginDir
Cleans, emptying it, a folder in a plugin folder.
$I->cleanPluginDir('my-plugin/foo');
Parameters
string$dir - The path to the folder, relative to the plugins root folder.
cleanThemeDir
Clears, emptying it, a folder in a theme folder.
$I->cleanThemeDir('my-theme/foo');
Parameters
string$dir - The path to the folder, relative to the themese root folder.
cleanUploadsDir
Clears a folder in the uploads folder. The date argument can be a string compatible with strtotime or a Unix timestamp that will be used to build the Y/m uploads subfolder path.
string$themeDst - The path to the destination folder, relative to the themes root folder.
copyDirToUploads
Copies a folder to the uploads folder. The date argument can be a string compatible with strtotime or a Unix timestamp that will be used to build the Y/m uploads subfolder path.
string$file - The path to the file, relative to the mu-plugins root folder.
deletePluginFile
Deletes a file in a plugin folder.
$I->deletePluginFile('my-plugin/some-file.txt');
Parameters
string$file - The folder path, relative to the plugins root folder.
deleteThemeFile
Deletes a file in a theme folder.
$I->deleteThemeFile('my-theme/some-file.txt');
Parameters
string$file - The path to the file to delete, relative to the themes root folder.
deleteUploadedDir
Deletes a dir in the uploads folder. The date argument can be a string compatible with strtotime or a Unix timestamp that will be used to build the Y/m uploads subfolder path.
string$dir - The path to the directory to delete, relative to the uploads folder.
string/int/[\DateTime](http://php.net/manual/en/class.datetime.php)$date - The date of the uploads to delete, will default to now.
deleteUploadedFile
Deletes a file in the uploads folder. The date argument can be a string compatible with strtotime or a Unix timestamp that will be used to build the Y/m uploads subfolder path.
string$file - The path to the file, relative to the themes root folder.
string$contents - The contents to check the file for.
dontSeeInUploadedFile
Checks that a file in the uploads folder does contain a string. The date argument can be a string compatible with strtotime or a Unix timestamp that will be used to build the Y/m uploads subfolder path.
string$file - The path to the file, relative to the themes root folder.
dontSeeUploadedFileFound
Checks thata a file does not exist in the uploads folder. The date argument can be a string compatible with strtotime or a Unix timestamp that will be used to build the Y/m uploads subfolder path.
string$file - The file path, relative to the uploads folder or the current folder.
string/int$date - A string compatible with strtotime or a Unix timestamp.
getBlogUploadsPath
Returns the absolute path to a blog uploads folder or file.
$blogId = $I->haveBlogInDatabase('test'); $testTodayUploads = $I->getBlogUploadsPath($blogId); $testLastMonthLogs = $I->getBlogUploadsPath($blogId, '/logs', '-1 month'); file or folder. sub-folders in the year/month format; a UNIX timestamp or a string supported by the `strtotime` function; defaults to `now`.
Parameters
int$blogId - The blog ID to get the path for.
string$file - The path, relatitve to the blog uploads folder, to the
null/string/[\DateTime](http://php.net/manual/en/class.datetime.php)/[\DateTime](http://php.net/manual/en/class.datetime.php)Immutable$date - The date that should be used to build the uploads
getUploadsPath
Returns the path to the specified uploads file of folder. Not providing a value for $file and $date will return the uploads folder path.
Creates a mu-plugin file, including plugin header, in the mu-plugins folder. The code can not contain the opening '<?php' tag.
$code = 'echo "Hello world!"'; $I->haveMuPlugin('foo-mu-plugin.php', $code); // Load the code from a file. $code = file_get_contents(codecept_data_dir('code/mu-plugin.php')); $I->haveMuPlugin('foo-mu-plugin.php', $code);
Parameters
string$filename - The path to the file to create, relative to the plugins root folder.
string$code - The content of the plugin file with or without the opening PHP tag.
havePlugin
Creates a plugin file, including plugin header, in the plugins folder. The plugin is just created and not activated; the code can not contain the opening '<?php' tag.
$code = 'echo "Hello world!"'; $I->havePlugin('foo/plugin.php', $code); // Load the code from a file. $code = file_get_contents(codecept_data_dir('code/plugin.php')); $I->havePlugin('foo/plugin.php', $code);
Parameters
string$path - The path to the file to create, relative to the plugins folder.
string$code - The content of the plugin file with or without the opening PHP tag.
haveTheme
Creates a theme file structure, including theme style file and index, in the themes folder. The theme is just created and not activated; the code can not contain the opening '<?php' tag.
$code = 'sayHi();'; $functionsCode = 'function sayHi(){echo "Hello world";};'; $I->haveTheme('foo', $indexCode, $functionsCode); // Load the code from a file. $indexCode = file_get_contents(codecept_data_dir('code/index.php')); $functionsCode = file_get_contents(codecept_data_dir('code/functions.php')); $I->haveTheme('foo', $indexCode, $functionsCode);
Parameters
string$folder - The path to the theme to create, relative to the themes root folder.
string$indexFileCode - The content of the theme index.php file with or without the opening PHP tag.
string$functionsFileCode - The content of the theme functions.php file with or without the opening PHP tag.
makeUploadsDir
Creates an empty folder in the WordPress installation uploads folder.
$logsDir = $I->makeUploadsDir('logs/acme'); to create.
Parameters
string$path - The path, relative to the WordPress installation uploads folder, of the folder
openUploadedFile
Opens a file in the the uploads folder. The date argument can be a string compatible with strtotime or a Unix timestamp that will be used to build the Y/m uploads subfolder path.
string$file - The path to the file, relative to the themes root folder.
string$contents - The contents to check the file for.
seeInUploadedFile
Checks that a file in the uploads folder contains a string. The date argument can be a string compatible with strtotime or a Unix timestamp that will be used to build the Y/m uploads subfolder path.
string$file - The path to the file, relative to thep plugins root folder.
seeThemeFileFound
Checks that a file is found in a theme folder.
$I->seeThemeFileFound('my-theme/some-file.txt');
Parameters
string$file - The path to the file, relative to the themes root folder.
seeUploadedFileFound
Checks if file exists in the uploads folder. The date argument can be a string compatible with strtotime or a Unix timestamp that will be used to build the Y/m uploads subfolder path.
string$file - The path to the file, relative to the themese root folder.
string$data - The data to write to the file.
writeToUploadedFile
Writes a string to a file in the the uploads folder. The date argument can be a string compatible with strtotime or a Unix timestamp that will be used to build the Y/m uploads subfolder path.