diff --git a/.gitignore b/.gitignore index 17a68b2..926288d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,25 @@ files/ repo/ vendor/ + +# Dev tools +.buildpath +*.iml +.project +.idea/ +.vscode/ + +# Third party dependencies +vendor/ + +# Tests +codeception.yml +tests/_output/* +tests/*.suite.yml +!tests/_data/dump.sql +!tests/_data/pue.sql +!tests/_data/pue-files +!tests/_pue-files/*.zip +tests/*.pem +tests/*.cert +tests/*.key diff --git a/tests/_support/Helper/Integration.php b/tests/_support/Helper/Integration.php new file mode 100644 index 0000000..5f17c15 --- /dev/null +++ b/tests/_support/Helper/Integration.php @@ -0,0 +1,10 @@ +getPluginsFolder(); + * $hello = $this->getPluginsFolder('hello.php'); + * ``` + * + * @param string $path A relative path to append to te plugins directory absolute path. + * + * @return string The absolute path to the `pluginsFolder` path or the same with a relative path appended if `$path` + * is provided. + * + * @throws ModuleConfigException If the path to the plugins folder does not exist. + * @see \Codeception\Module\WPLoader::getPluginsFolder() + */ + public function getPluginsFolder($path = "") { + return $this->getScenario()->runStep(new \Codeception\Step\Action('getPluginsFolder', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Accessor method to get the object storing the factories for things. + * This methods gives access to the same factories provided by the + * [Core test suite](https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/). + * + * @return FactoryStore A factory store, proxy to get hold of the Core suite object + * factories. + * + * @example + * ```php + * $postId = $I->factory()->post->create(); + * $userId = $I->factory()->user->create(['role' => 'administrator']); + * ``` + * + * @link https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/ + * @see \Codeception\Module\WPLoader::factory() + */ + public function factory() { + return $this->getScenario()->runStep(new \Codeception\Step\Action('factory', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Returns the absolute path to the WordPress content directory. + * + * @example + * ```php + * $content = $this->getContentFolder(); + * $themes = $this->getContentFolder('themes'); + * $twentytwenty = $this->getContentFolder('themes/twentytwenty'); + * ``` + * + * @param string $path An optional path to append to the content directory absolute path. + * + * @return string The content directory absolute path, or a path in it. + * + * @throws ModuleConfigException If the path to the content directory cannot be resolved. + * @see \Codeception\Module\WPLoader::getContentFolder() + */ + public function getContentFolder($path = "") { + return $this->getScenario()->runStep(new \Codeception\Step\Action('getContentFolder', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Starts the debug of all WordPress filters and actions. + * + * The method hook on `all` filters and actions to debug their value. + * + * @example + * ```php + * // Start debugging all WordPress filters and action final and initial values. + * $this->startWpFiltersDebug(); + * + * // Run some code firing filters and debug them. + * + * // Stop debugging all WordPress filters and action final and initial values. + * $this->stopWpFiltersDebug(); + * ``` + * + * @param callable|null $format A callback function to format the arguments debug output; the callback will receive + * the array of arguments as input. + * + * @return void + * @see \Codeception\Module\WPLoader::startWpFiltersDebug() + */ + public function startWpFiltersDebug(?callable $format = NULL) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('startWpFiltersDebug', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Stops the debug of all WordPress filters and actions. + * + * @example + * ```php + * // Start debugging all WordPress filters and action final and initial values. + * $this->startWpFiltersDebug(); + * + * // Run some code firing filters and debug them. + * + * // Stop debugging all WordPress filters and action final and initial values. + * $this->stopWpFiltersDebug(); + * ``` + * + * @return void + * @see \Codeception\Module\WPLoader::stopWpFiltersDebug() + */ + public function stopWpFiltersDebug() { + return $this->getScenario()->runStep(new \Codeception\Step\Action('stopWpFiltersDebug', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Debugs a single WordPress filter initial call using Codeception debug functions. + * + * The output will show following the selected output verbosity (`--debug` and `-vvv` CLI options). + * + * @example + * ```php + * // Start debugging all WordPress filters initial value. + * add_filter('all', [$this,'debugWpFilterInitial']); + * + * // Run some code firing filters and debug them. + * + * // Stop debugging all WordPress filters initial value. + * remove_filter('all', [$this,'debugWpFilterInitial']); + * ``` + * + * @param mixed ...$args The filter call arguments. + * + * @return mixed The filter input value, unchanged. + * @see \Codeception\Module\WPLoader::debugWpFilterInitial() + */ + public function debugWpFilterInitial($args = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('debugWpFilterInitial', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Debugs a single WordPress filter final call using Codeception debug functions. + * + * The output will show following the selected output verbosity (`--debug` and `-vvv` CLI options). + * + * @example + * ```php + * // Start debugging all WordPress filters final value. + * add_filter('all', [$this,'debugWpFilterFinal']); + * + * // Run some code firing filters and debug them. + * + * // Stop debugging all WordPress filters final value. + * remove_filter('all', [$this,'debugWpFilterFinal']); + * ``` + * + * @param mixed ...$args The filter call arguments. + * + * @return mixed The filter input value, unchanged. + * @see \Codeception\Module\WPLoader::debugWpFilterFinal() + */ + public function debugWpFilterFinal($args = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('debugWpFilterFinal', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Debugs a single WordPress action initial call using Codeception debug functions. + * + * The output will show following the selected output verbosity (`--debug` and `-vvv` CLI options). + * + * @example + * ```php + * // Start debugging all WordPress actions initial value. + * add_action('all', [$this,'debugWpActionInitial']); + * + * // Run some code firing actions and debug them. + * + * // Stop debugging all WordPress actions initial value. + * remove_action('all', [$this,'debugWpActionInitial']); + * ``` + * + * @param mixed ...$args The action call arguments. + * + * @return void + * @see \Codeception\Module\WPLoader::debugWpActionInitial() + */ + public function debugWpActionInitial($args = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('debugWpActionInitial', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Debugs a single WordPress action final call using Codeception debug functions. + * + * The output will show following the selected output verbosity (`--debug` and `-vvv` CLI options). + * + * @example + * ```php + * // Start debugging all WordPress actions final value. + * add_action('all', [$this,'debugWpActionFinal']); + * + * // Run some code firing actions and debug them. + * + * // Stop debugging all WordPress actions final value. + * remove_action('all', [$this,'debugWpActionFinal']); + * ``` + * + * @param mixed ...$args The action call arguments. + * + * @return void + * @see \Codeception\Module\WPLoader::debugWpActionFinal() + */ + public function debugWpActionFinal($args = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('debugWpActionFinal', func_get_args())); + } +} diff --git a/tests/config.php b/tests/config.php new file mode 100644 index 0000000..16d7d1a --- /dev/null +++ b/tests/config.php @@ -0,0 +1,32 @@ + getenv( 'WP_ROOT_FOLDER' ) . '/wp-content', + 'ABSPATH' => getenv( 'WP_ROOT_FOLDER' ) . '/', + ]; +} else { + // Paths + $constants = [ + 'WP_CONTENT_DIR' => dirname( __FILE__ ) . '/../../../../wp-content', + 'ABSPATH' => dirname( __FILE__ ) . '/../../../../wp', + ]; +} + +foreach ( $constants as $key => $value ) { + if ( defined( $key ) ) { + continue; + } + + define( $key, $value ); +} diff --git a/tests/wpunit.suite.dist.yml b/tests/wpunit.suite.dist.yml index c1b264b..74f4ec5 100644 --- a/tests/wpunit.suite.dist.yml +++ b/tests/wpunit.suite.dist.yml @@ -6,12 +6,16 @@ class_name: WpunitTester bootstrap: _bootstrap.php modules: enabled: + - \Helper\Integration - WPLoader - - WPQueries config: WPLoader: - wpRootFolder: %WP_ROOT_FOLDER% - dbName: %WP_TEST_DB_NAME% - dbHost: %WP_TEST_DB_HOST% - dbUser: %WP_TEST_DB_USER% - dbPassword: %WP_TEST_DB_PASSWORD% + wpRootFolder: "%WP_ROOT_FOLDER%" + dbName: "%WP_TEST_DB_NAME%" + dbHost: "%WP_TEST_DB_HOST%" + dbUser: "%WP_TEST_DB_USER%" + dbPassword: "%WP_TEST_DB_PASSWORD%" + tablePrefix: "%WP_TABLE_PREFIX%" + domain: "%WP_DOMAIN%" + title: stellarwp/db tests + configFile: tests/config.php