diff --git a/codeception.dist.yml b/codeception.dist.yml index 2ade96668..7fc117f9d 100644 --- a/codeception.dist.yml +++ b/codeception.dist.yml @@ -29,6 +29,9 @@ extensions: 'tests/_data/themes/dummy': '%WORDPRESS_ROOT_DIR%/wp-content/themes/dummy' 'tests/_data/themes/isolated': '%WORDPRESS_ROOT_DIR%/wp-content/themes/isolated' 'tests/_data/plugins/mu-plugin-1': '%WORDPRESS_ROOT_DIR%/wp-content/plugins/mu-plugin-1' + 'tests/_data/plugins/doing-it-right': '%WORDPRESS_ROOT_DIR%/wp-content/plugins/doing-it-right' + 'tests/_data/plugins/doing-it-wrong-1': '%WORDPRESS_ROOT_DIR%/wp-content/plugins/doing-it-wrong-1' + 'tests/_data/plugins/doing-it-wrong-2': '%WORDPRESS_ROOT_DIR%/wp-content/plugins/doing-it-wrong-2' 'tests/_data/plugins/test': '%WORDPRESS_ROOT_DIR%/wp-content/plugins/test' 'tests/_data/plugins/isolated-test-plugin': '%WORDPRESS_ROOT_DIR%/wp-content/plugins/isolated-test-plugin' 'tests/_data/plugins/isolated-test-plugin-two': '%WORDPRESS_ROOT_DIR%/wp-content/plugins/isolated-test-plugin-two' diff --git a/src/Codeception/Module/WPLoader.php b/src/Codeception/Module/WPLoader.php index 13566b098..e78128787 100644 --- a/src/Codeception/Module/WPLoader.php +++ b/src/Codeception/Module/WPLoader.php @@ -138,6 +138,10 @@ class WPLoader extends Module * activated calling the `activate_{$plugin}` before any test case runs and * after mu-plugins have been loaded; these should be defined in the * `folder/plugin-file.php` format. + * activatePlugins - array, def. `[]`, a list of plugins that should be + * silently activated calling the `activate_{$plugin}` before any test case runs and + * after mu-plugins have been loaded; these should be defined in the + * `folder/plugin-file.php` format. * bootstrapActions - array, def. `[]`, a list of actions that should be * called after before any test case runs. * skipPluggables - bool, def. `false`, if set to `true` will skip the @@ -165,8 +169,9 @@ class WPLoader extends Module 'configFile' => '', 'contentFolder' => '', 'pluginsFolder' => '', - 'plugins' => '', - 'activatePlugins' => '', + 'plugins' => [], + 'activatePlugins' => [], + 'activatePluginsSilently' => [], 'bootstrapActions' => '', 'theme' => '', ]; @@ -1117,9 +1122,12 @@ public function getContentFolder($path = '') protected function getInstallationConfiguration() { return new Configuration([ - 'tablesHandling' => isset($this->config['installationTableHandling']) ? + 'tablesHandling' => isset($this->config['installationTableHandling']) ? $this->config['installationTableHandling'] - : 'empty' + : 'empty', + 'activatePluginsSilently' => isset($this->config['activatePluginsSilently']) ? + (array) $this->config['activatePluginsSilently'] + : [] ]); } } diff --git a/src/includes/bootstrap.php b/src/includes/bootstrap.php index e9b8ab2fa..58646812e 100644 --- a/src/includes/bootstrap.php +++ b/src/includes/bootstrap.php @@ -114,6 +114,7 @@ 'WPLANG' => WPLANG, ], 'tablesHandling' => $installationConfiguration->get('tablesHandling','empty'), + 'activatePluginsSilently' => $installationConfiguration->get('activatePluginsSilently', []), ]; $dirConstants = [ diff --git a/src/includes/isolated-install.php b/src/includes/isolated-install.php index aa9ab553d..0d4d7c070 100644 --- a/src/includes/isolated-install.php +++ b/src/includes/isolated-install.php @@ -192,9 +192,13 @@ $current_site->blog_id = 1; } +$activatePluginsSilently = isset( $configuration['activatePluginsSilently'] ) ? + $configuration['activatePluginsSilently'] + : []; + // finally activate the plugins that should be activated if (!empty($activePlugins)) { - $activePlugins = array_unique($activePlugins); + $activePlugins = array_values( array_unique( array_merge( $activePlugins, $activatePluginsSilently ) ) ); if ($multisite) { require(ABSPATH . WPINC . '/class-wp-site-query.php'); @@ -204,8 +208,9 @@ } foreach ($activePlugins as $plugin) { + $silent = in_array($plugin, $activatePluginsSilently,true); printf("\n%sctivating plugin [%s]...", $multisite ? 'Network a' : 'A', $plugin); - $activated = activate_plugin($plugin, null, $multisite, false); + $activated = activate_plugin($plugin, null, $multisite, $silent); if (is_wp_error($activated)) { echo $activated->get_error_message(); diff --git a/tests/_bootstrap.php b/tests/_bootstrap.php index 0e7e3ed85..1fe618560 100644 --- a/tests/_bootstrap.php +++ b/tests/_bootstrap.php @@ -1,7 +1,9 @@ getSuite()->getName(); +// +// if ( $suiteName !== 'wploader_plugin_silent_activation' ) { +// return; +// } +// +// $wpRootDir = realpath( getenv( 'WORDPRESS_ROOT_DIR' ) ); +// +// if ( ! is_dir( $wpRootDir ) ) { +// throw new \RuntimeException( "The WORDPRESS_ROOT_DIR is not a valid directory." ); +// } +// +// $wpRootDir = rtrim( $wpRootDir, '/\\' ); +// +// foreach ( +// [ +// codecept_data_dir( 'plugins/doing-it-wrong-1' ) => $wpRootDir . '/wp-content/plugins/doing-it-wrong-1', +// codecept_data_dir( 'plugins/doing-it-wrong-2' ) => $wpRootDir . '/wp-content/plugins/doing-it-wrong-2', +// ] as $source => $destination +// ) { +// if ( ! copy( +// $source, +// $destination +// ) ) { +// throw new \RuntimeException( "Could not copy the plugin to the WordPress plugins directory." ); +// } +// } +//} ); diff --git a/tests/_data/plugins/doing-it-right/plugin.php b/tests/_data/plugins/doing-it-right/plugin.php new file mode 100644 index 000000000..8467cfd1c --- /dev/null +++ b/tests/_data/plugins/doing-it-right/plugin.php @@ -0,0 +1,13 @@ +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($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/acceptance/AjaxCest.php b/tests/acceptance/AjaxCest.php index 3569adefc..88e41dc46 100644 --- a/tests/acceptance/AjaxCest.php +++ b/tests/acceptance/AjaxCest.php @@ -1,8 +1,10 @@ haveMuPlugin( 'test-ajax-plugin', $code ); - } + $I->haveMuPlugin('test-ajax-plugin', $code); + } - public function test_invalid_action_returns_400( AcceptanceTester $I ) { - $I->amOnAdminAjaxPage( [ - 'action' => 'invalid_action' - ] ); - $I->seeResponseCodeIs( 400 ); - } + public function test_invalid_action_returns_400(AcceptanceTester $I) + { + $I->amOnAdminAjaxPage([ + 'action' => 'invalid_action' + ]); + $I->seeResponseCodeIs(400); + } - public function test_missing_nonce_returns_403( AcceptanceTester $I ) { - $I->amOnAdminAjaxPage( [ - 'action' => 'test_ajax_action' - ] ); - $I->seeResponseCodeIs( 403 ); - } + public function test_missing_nonce_returns_403(AcceptanceTester $I) + { + $I->amOnAdminAjaxPage([ + 'action' => 'test_ajax_action' + ]); + $I->seeResponseCodeIs(403); + } - public function test_wrong_nonce_returns_403( AcceptanceTester $I ) { - $I->amOnAdminAjaxPage( [ - 'action' => 'test_ajax_action', - '_ajax_nonce' => 'wrong_nonce' - ] ); - $I->seeResponseCodeIs( 403 ); - } + public function test_wrong_nonce_returns_403(AcceptanceTester $I) + { + $I->amOnAdminAjaxPage([ + 'action' => 'test_ajax_action', + '_ajax_nonce' => 'wrong_nonce' + ]); + $I->seeResponseCodeIs(403); + } - public function test_valid_nonce_returns_200_for_visitor( AcceptanceTester $I ) { - $I->amOnPage( '/' ); - $nonce = $I->grabValueFrom( '#test-ajax-nonce' ); + public function test_valid_nonce_returns_200_for_visitor(AcceptanceTester $I) + { + $I->amOnPage('/'); + $nonce = $I->grabValueFrom('#test-ajax-nonce'); - $I->amOnAdminAjaxPage( [ - 'action' => 'test_ajax_action', - '_ajax_nonce' => $nonce - ] ); - $I->seeResponseCodeIs( 200 ); - $I->canSee( json_encode( [ 'type' => 'no-priv' ] ) ); - } + $I->amOnAdminAjaxPage([ + 'action' => 'test_ajax_action', + '_ajax_nonce' => $nonce + ]); + $I->seeResponseCodeIs(200); + $I->canSee(json_encode([ 'type' => 'no-priv' ])); + } - public function test_valid_nonce_returns_200_for_admin( AcceptanceTester $I ) { - $I->loginAsAdmin(); - $I->amOnPage( '/' ); - $nonce = $I->grabValueFrom( '#test-ajax-nonce' ); + public function test_valid_nonce_returns_200_for_admin(AcceptanceTester $I) + { + $I->loginAsAdmin(); + $I->amOnPage('/'); + $nonce = $I->grabValueFrom('#test-ajax-nonce'); - $I->amOnAdminAjaxPage( [ - 'action' => 'test_ajax_action', - '_ajax_nonce' => $nonce - ] ); - $I->seeResponseCodeIs( 200 ); - $I->canSee( json_encode( [ 'type' => 'priv' ] ) ); - } + $I->amOnAdminAjaxPage([ + 'action' => 'test_ajax_action', + '_ajax_nonce' => $nonce + ]); + $I->seeResponseCodeIs(200); + $I->canSee(json_encode([ 'type' => 'priv' ])); + } } diff --git a/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_multisite_with_missing_blogs_entry_for_site__0.snapshot.json b/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_multisite_with_missing_blogs_entry_for_site__0.snapshot.json index 927792c61..097a74cfd 100644 --- a/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_multisite_with_missing_blogs_entry_for_site__0.snapshot.json +++ b/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_multisite_with_missing_blogs_entry_for_site__0.snapshot.json @@ -32,6 +32,9 @@ "Must-use plugins health-check:": "mu-plugins directory (wp-content/mu-plugins) does not exist.", "Plugins health-check:": { "Inactive plugin [akismet]": "wp-content/plugins/akismet", + "Inactive plugin [doing-it-right]": "wp-content/plugins/doing-it-right", + "Inactive plugin [doing-it-wrong-1]": "wp-content/plugins/doing-it-wrong-1", + "Inactive plugin [doing-it-wrong-2]": "wp-content/plugins/doing-it-wrong-2", "Inactive plugin [isolated-test-plugin-two]": "wp-content/plugins/isolated-test-plugin-two", "Inactive plugin [isolated-test-plugin]": "wp-content/plugins/isolated-test-plugin", "Inactive plugin [mu-plugin-1]": "wp-content/plugins/mu-plugin-1", diff --git a/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_with_available_wpdb_global__0.snapshot.json b/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_with_available_wpdb_global__0.snapshot.json index 867c3ac5a..2bbb81b42 100644 --- a/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_with_available_wpdb_global__0.snapshot.json +++ b/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_with_available_wpdb_global__0.snapshot.json @@ -33,6 +33,9 @@ "Plugins health-check:": { "Active plugin [airplane-mode/airplane-mode.php]": "file [wp-content/plugins/airplane-mode/airplane-mode.php] does not exist.", "Inactive plugin [akismet]": "wp-content/plugins/akismet", + "Inactive plugin [doing-it-right]": "wp-content/plugins/doing-it-right", + "Inactive plugin [doing-it-wrong-1]": "wp-content/plugins/doing-it-wrong-1", + "Inactive plugin [doing-it-wrong-2]": "wp-content/plugins/doing-it-wrong-2", "Inactive plugin [isolated-test-plugin-two]": "wp-content/plugins/isolated-test-plugin-two", "Inactive plugin [isolated-test-plugin]": "wp-content/plugins/isolated-test-plugin", "Inactive plugin [mu-plugin-1]": "wp-content/plugins/mu-plugin-1", diff --git a/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_with_diff_set_of_tables_specified_from_wpdb_global__0.snapshot.json b/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_with_diff_set_of_tables_specified_from_wpdb_global__0.snapshot.json index dc9f464b8..5a539f733 100644 --- a/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_with_diff_set_of_tables_specified_from_wpdb_global__0.snapshot.json +++ b/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_with_diff_set_of_tables_specified_from_wpdb_global__0.snapshot.json @@ -33,6 +33,9 @@ "Plugins health-check:": { "Active plugin [airplane-mode/airplane-mode.php]": "file [wp-content/plugins/airplane-mode/airplane-mode.php] does not exist.", "Inactive plugin [akismet]": "wp-content/plugins/akismet", + "Inactive plugin [doing-it-right]": "wp-content/plugins/doing-it-right", + "Inactive plugin [doing-it-wrong-1]": "wp-content/plugins/doing-it-wrong-1", + "Inactive plugin [doing-it-wrong-2]": "wp-content/plugins/doing-it-wrong-2", "Inactive plugin [isolated-test-plugin-two]": "wp-content/plugins/isolated-test-plugin-two", "Inactive plugin [isolated-test-plugin]": "wp-content/plugins/isolated-test-plugin", "Inactive plugin [mu-plugin-1]": "wp-content/plugins/mu-plugin-1", diff --git a/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_with_empty_and_missing_template_and_stylesheet_files__0.snapshot.json b/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_with_empty_and_missing_template_and_stylesheet_files__0.snapshot.json index dcf14bb64..d7b1e5272 100644 --- a/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_with_empty_and_missing_template_and_stylesheet_files__0.snapshot.json +++ b/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_with_empty_and_missing_template_and_stylesheet_files__0.snapshot.json @@ -34,6 +34,9 @@ "Active plugin [one/one.php]": "file [wp-content/plugins/one/one.php] does not exist.", "Active plugin [two/two.php]": "file [wp-content/plugins/two/two.php] does not exist.", "Inactive plugin [akismet]": "wp-content/plugins/akismet", + "Inactive plugin [doing-it-right]": "wp-content/plugins/doing-it-right", + "Inactive plugin [doing-it-wrong-1]": "wp-content/plugins/doing-it-wrong-1", + "Inactive plugin [doing-it-wrong-2]": "wp-content/plugins/doing-it-wrong-2", "Inactive plugin [isolated-test-plugin-two]": "wp-content/plugins/isolated-test-plugin-two", "Inactive plugin [isolated-test-plugin]": "wp-content/plugins/isolated-test-plugin", "Inactive plugin [mu-plugin-1]": "wp-content/plugins/mu-plugin-1", diff --git a/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_with_inactive_plugins__0.snapshot.json b/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_with_inactive_plugins__0.snapshot.json index 79b35a6d0..2fccaab9c 100644 --- a/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_with_inactive_plugins__0.snapshot.json +++ b/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_with_inactive_plugins__0.snapshot.json @@ -31,6 +31,9 @@ }, "Must-use plugins health-check:": "mu-plugins directory (wp-content/mu-plugins) does not exist.", "Plugins health-check:": { + "Inactive plugin [doing-it-right]": "../../tests/_data/plugins/doing-it-right", + "Inactive plugin [doing-it-wrong-1]": "../../tests/_data/plugins/doing-it-wrong-1", + "Inactive plugin [doing-it-wrong-2]": "../../tests/_data/plugins/doing-it-wrong-2", "Inactive plugin [isolated-test-plugin-two]": "../../tests/_data/plugins/isolated-test-plugin-two", "Inactive plugin [isolated-test-plugin]": "../../tests/_data/plugins/isolated-test-plugin", "Inactive plugin [mu-plugin-1]": "../../tests/_data/plugins/mu-plugin-1", diff --git a/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_with_missing_siteurl_option__0.snapshot.json b/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_with_missing_siteurl_option__0.snapshot.json index 6fce6a284..41fcdae51 100644 --- a/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_with_missing_siteurl_option__0.snapshot.json +++ b/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_with_missing_siteurl_option__0.snapshot.json @@ -32,6 +32,9 @@ "Must-use plugins health-check:": "mu-plugins directory (wp-content/mu-plugins) does not exist.", "Plugins health-check:": { "Inactive plugin [akismet]": "wp-content/plugins/akismet", + "Inactive plugin [doing-it-right]": "wp-content/plugins/doing-it-right", + "Inactive plugin [doing-it-wrong-1]": "wp-content/plugins/doing-it-wrong-1", + "Inactive plugin [doing-it-wrong-2]": "wp-content/plugins/doing-it-wrong-2", "Inactive plugin [isolated-test-plugin-two]": "wp-content/plugins/isolated-test-plugin-two", "Inactive plugin [isolated-test-plugin]": "wp-content/plugins/isolated-test-plugin", "Inactive plugin [mu-plugin-1]": "wp-content/plugins/mu-plugin-1", diff --git a/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_with_mu_plugins_dir_constant_set__0.snapshot.json b/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_with_mu_plugins_dir_constant_set__0.snapshot.json index 94cf71efc..4448e870f 100644 --- a/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_with_mu_plugins_dir_constant_set__0.snapshot.json +++ b/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_with_mu_plugins_dir_constant_set__0.snapshot.json @@ -33,6 +33,9 @@ "Plugins health-check:": { "Active plugin [airplane-mode/airplane-mode.php]": "file [wp-content/plugins/airplane-mode/airplane-mode.php] does not exist.", "Inactive plugin [akismet]": "wp-content/plugins/akismet", + "Inactive plugin [doing-it-right]": "wp-content/plugins/doing-it-right", + "Inactive plugin [doing-it-wrong-1]": "wp-content/plugins/doing-it-wrong-1", + "Inactive plugin [doing-it-wrong-2]": "wp-content/plugins/doing-it-wrong-2", "Inactive plugin [isolated-test-plugin-two]": "wp-content/plugins/isolated-test-plugin-two", "Inactive plugin [isolated-test-plugin]": "wp-content/plugins/isolated-test-plugin", "Inactive plugin [mu-plugin-1]": "wp-content/plugins/mu-plugin-1", diff --git a/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_with_no_results_in_blogs_for_blog_domain__0.snapshot.json b/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_with_no_results_in_blogs_for_blog_domain__0.snapshot.json index 54054dbc2..936a2d86b 100644 --- a/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_with_no_results_in_blogs_for_blog_domain__0.snapshot.json +++ b/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_with_no_results_in_blogs_for_blog_domain__0.snapshot.json @@ -32,6 +32,9 @@ "Must-use plugins health-check:": "mu-plugins directory (wp-content/mu-plugins) does not exist.", "Plugins health-check:": { "Inactive plugin [akismet]": "wp-content/plugins/akismet", + "Inactive plugin [doing-it-right]": "wp-content/plugins/doing-it-right", + "Inactive plugin [doing-it-wrong-1]": "wp-content/plugins/doing-it-wrong-1", + "Inactive plugin [doing-it-wrong-2]": "wp-content/plugins/doing-it-wrong-2", "Inactive plugin [isolated-test-plugin-two]": "wp-content/plugins/isolated-test-plugin-two", "Inactive plugin [isolated-test-plugin]": "wp-content/plugins/isolated-test-plugin", "Inactive plugin [mu-plugin-1]": "wp-content/plugins/mu-plugin-1", diff --git a/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_with_working_installation__0.snapshot.json b/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_with_working_installation__0.snapshot.json index 7013031a9..28450ae6b 100644 --- a/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_with_working_installation__0.snapshot.json +++ b/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_with_working_installation__0.snapshot.json @@ -33,6 +33,9 @@ "Plugins health-check:": { "Active plugin [airplane-mode/airplane-mode.php]": "file [wp-content/plugins/airplane-mode/airplane-mode.php] does not exist.", "Inactive plugin [akismet]": "wp-content/plugins/akismet", + "Inactive plugin [doing-it-right]": "wp-content/plugins/doing-it-right", + "Inactive plugin [doing-it-wrong-1]": "wp-content/plugins/doing-it-wrong-1", + "Inactive plugin [doing-it-wrong-2]": "wp-content/plugins/doing-it-wrong-2", "Inactive plugin [isolated-test-plugin-two]": "wp-content/plugins/isolated-test-plugin-two", "Inactive plugin [isolated-test-plugin]": "wp-content/plugins/isolated-test-plugin", "Inactive plugin [mu-plugin-1]": "wp-content/plugins/mu-plugin-1", diff --git a/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_with_working_multisite_subdir_installation__0.snapshot.json b/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_with_working_multisite_subdir_installation__0.snapshot.json index ace79169f..a9e64499c 100644 --- a/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_with_working_multisite_subdir_installation__0.snapshot.json +++ b/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_with_working_multisite_subdir_installation__0.snapshot.json @@ -32,6 +32,9 @@ "Must-use plugins health-check:": "mu-plugins directory (wp-content/mu-plugins) does not exist.", "Plugins health-check:": { "Inactive plugin [akismet]": "wp-content/plugins/akismet", + "Inactive plugin [doing-it-right]": "wp-content/plugins/doing-it-right", + "Inactive plugin [doing-it-wrong-1]": "wp-content/plugins/doing-it-wrong-1", + "Inactive plugin [doing-it-wrong-2]": "wp-content/plugins/doing-it-wrong-2", "Inactive plugin [isolated-test-plugin-two]": "wp-content/plugins/isolated-test-plugin-two", "Inactive plugin [isolated-test-plugin]": "wp-content/plugins/isolated-test-plugin", "Inactive plugin [mu-plugin-1]": "wp-content/plugins/mu-plugin-1", diff --git a/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_with_working_multisite_subdomain_installation__0.snapshot.json b/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_with_working_multisite_subdomain_installation__0.snapshot.json index b35bbd620..d48719d01 100644 --- a/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_with_working_multisite_subdomain_installation__0.snapshot.json +++ b/tests/dbunit/tad/WPBrowser/Module/Support/__snapshots__/WPHealthcheckTest__test_with_working_multisite_subdomain_installation__0.snapshot.json @@ -32,6 +32,9 @@ "Must-use plugins health-check:": "mu-plugins directory (wp-content/mu-plugins) does not exist.", "Plugins health-check:": { "Inactive plugin [akismet]": "wp-content/plugins/akismet", + "Inactive plugin [doing-it-right]": "wp-content/plugins/doing-it-right", + "Inactive plugin [doing-it-wrong-1]": "wp-content/plugins/doing-it-wrong-1", + "Inactive plugin [doing-it-wrong-2]": "wp-content/plugins/doing-it-wrong-2", "Inactive plugin [isolated-test-plugin-two]": "wp-content/plugins/isolated-test-plugin-two", "Inactive plugin [isolated-test-plugin]": "wp-content/plugins/isolated-test-plugin", "Inactive plugin [mu-plugin-1]": "wp-content/plugins/mu-plugin-1", diff --git a/tests/unit/Codeception/Lib/Generator/WPUnitTest.php b/tests/unit/Codeception/Lib/Generator/WPUnitTest.php index a3d1e2c72..ac9f162ec 100644 --- a/tests/unit/Codeception/Lib/Generator/WPUnitTest.php +++ b/tests/unit/Codeception/Lib/Generator/WPUnitTest.php @@ -7,114 +7,122 @@ use tad\Codeception\SnapshotAssertions\SnapshotAssertions; use tad\WPBrowser\Compat\Compatibility; -class WPUnitTest extends \Codeception\Test\Unit { - use WithUopz; - use SnapshotAssertions; - - /** - * A backup of the current PHPUnit Series env var. - * @var array|false|string - */ - protected $phpunitSeriesEnv; - /** - * @var \UnitTester - */ - protected $tester; - - /** - * @var string - */ - private $phpunitVersionPropertyBackup = null; - - private function setPhpUnitSeriesTo( $series ) { - $reflectionClass = new ReflectionClass( Version::class ); - $versionProp = $reflectionClass->getProperty( 'version' ); - $versionProp->setAccessible( true ); - $this->phpunitVersionPropertyBackup = $versionProp->getValue(); - $versionProp->setValue( $series ); - } - - /** - * @after - */ - public function restorePhpunitVersionProperty() { - if ( null === $this->phpunitVersionPropertyBackup ) { - return; - } - $reflectionClass = new ReflectionClass( Version::class ); - $versionProp = $reflectionClass->getProperty( 'version' ); - $versionProp->setAccessible( true ); - $versionProp->setValue( $this->phpunitVersionPropertyBackup ); - $this->phpunitVersionPropertyBackup = null; - } - - /** - * It should scaffold PHPUnit v8 compatible code on series 8 - * - * @test - * @dataProvider phpUnitEq8Series - */ - public function should_scaffold_php_unit_v_8_code_on_series_8( $series ) { - $this->setPhpUnitSeriesTo( '8.0' ); - $settings = [ 'namespace' => 'Acme' ]; - $name = 'SomeClass'; - - $generator = new WPUnit( $settings, $name, WPTestCase::class ); - $code = $generator->produce(); - - $this->assertMatchesCodeSnapshot( $code, 'php' ); - } - - public function phpUnitLt8Series() { - return [ - '5.5' => [ '5.5' ], - '5.5.5' => [ '5.5' ], - '6.2' => [ '6.2' ], - '6.2.3' => [ '6.2' ], - '7.5' => [ '7.5' ], - '7.5.6' => [ '7.5' ], - ]; - } - - /** - * It should scaffold PHPUnit lt 8.0 compatible code on series lt 8 - * - * @test - * @dataProvider phpUnitLt8Series - */ - public function should_scaffold_php_unit_lt_8_0_compatible_code_on_series_lt_8( $series ) { - $this->setPhpUnitSeriesTo( $series ); - $settings = [ 'namespace' => 'Acme' ]; - $name = 'SomeClass'; - - $generator = new WPUnit( $settings, $name, WPTestCase::class ); - $code = $generator->produce(); - - $this->assertMatchesCodeSnapshot( $code, 'php' ); - } - - /** - * It should correctly add the tester property if actor is set in the settings - * - * @test - */ - public function should_correctly_add_the_tester_property_if_actor_is_set_in_the_settings() { - $this->setPhpUnitSeriesTo( '6.0' ); - $settings = [ 'namespace' => 'Acme', 'actor' => 'Fixer' ]; - $name = 'SomeClass'; - - $generator = new WPUnit( $settings, $name, WPTestCase::class ); - $code = $generator->produce(); - - $this->assertMatchesCodeSnapshot( $code, 'php' ); - } - - public function phpUnitEq8Series() { - return [ - '8.0' => [ '8.0' ], - '8.0.4' => [ '8.0.4' ], - '8.1' => [ '8.1' ], - '8.1.6' => [ '8.1.6' ], - ]; - } +class WPUnitTest extends \Codeception\Test\Unit +{ + use WithUopz; + use SnapshotAssertions; + + /** + * A backup of the current PHPUnit Series env var. + * @var array|false|string + */ + protected $phpunitSeriesEnv; + /** + * @var \UnitTester + */ + protected $tester; + + /** + * @var string + */ + private $phpunitVersionPropertyBackup = null; + + private function setPhpUnitSeriesTo($series) + { + $reflectionClass = new ReflectionClass(Version::class); + $versionProp = $reflectionClass->getProperty('version'); + $versionProp->setAccessible(true); + $this->phpunitVersionPropertyBackup = $versionProp->getValue(); + $versionProp->setValue($series); + } + + /** + * @after + */ + public function restorePhpunitVersionProperty() + { + if (null === $this->phpunitVersionPropertyBackup) { + return; + } + $reflectionClass = new ReflectionClass(Version::class); + $versionProp = $reflectionClass->getProperty('version'); + $versionProp->setAccessible(true); + $versionProp->setValue($this->phpunitVersionPropertyBackup); + $this->phpunitVersionPropertyBackup = null; + } + + /** + * It should scaffold PHPUnit v8 compatible code on series 8 + * + * @test + * @dataProvider phpUnitEq8Series + */ + public function should_scaffold_php_unit_v_8_code_on_series_8($series) + { + $this->setPhpUnitSeriesTo('8.0'); + $settings = [ 'namespace' => 'Acme' ]; + $name = 'SomeClass'; + + $generator = new WPUnit($settings, $name, WPTestCase::class); + $code = $generator->produce(); + + $this->assertMatchesCodeSnapshot($code, 'php'); + } + + public function phpUnitLt8Series() + { + return [ + '5.5' => [ '5.5' ], + '5.5.5' => [ '5.5' ], + '6.2' => [ '6.2' ], + '6.2.3' => [ '6.2' ], + '7.5' => [ '7.5' ], + '7.5.6' => [ '7.5' ], + ]; + } + + /** + * It should scaffold PHPUnit lt 8.0 compatible code on series lt 8 + * + * @test + * @dataProvider phpUnitLt8Series + */ + public function should_scaffold_php_unit_lt_8_0_compatible_code_on_series_lt_8($series) + { + $this->setPhpUnitSeriesTo($series); + $settings = [ 'namespace' => 'Acme' ]; + $name = 'SomeClass'; + + $generator = new WPUnit($settings, $name, WPTestCase::class); + $code = $generator->produce(); + + $this->assertMatchesCodeSnapshot($code, 'php'); + } + + /** + * It should correctly add the tester property if actor is set in the settings + * + * @test + */ + public function should_correctly_add_the_tester_property_if_actor_is_set_in_the_settings() + { + $this->setPhpUnitSeriesTo('6.0'); + $settings = [ 'namespace' => 'Acme', 'actor' => 'Fixer' ]; + $name = 'SomeClass'; + + $generator = new WPUnit($settings, $name, WPTestCase::class); + $code = $generator->produce(); + + $this->assertMatchesCodeSnapshot($code, 'php'); + } + + public function phpUnitEq8Series() + { + return [ + '8.0' => [ '8.0' ], + '8.0.4' => [ '8.0.4' ], + '8.1' => [ '8.1' ], + '8.1.6' => [ '8.1.6' ], + ]; + } } diff --git a/tests/wploader_plugin_silent_activation.suite.dist.yml b/tests/wploader_plugin_silent_activation.suite.dist.yml new file mode 100644 index 000000000..57ab670a0 --- /dev/null +++ b/tests/wploader_plugin_silent_activation.suite.dist.yml @@ -0,0 +1,30 @@ +actor: Wploader_plugin_silent_activationTester +modules: + enabled: + - WPLoader + config: + WPLoader: + wpRootFolder: '%WORDPRESS_ROOT_DIR%' + dbName: '%WORDPRESS_DB_NAME%' + dbHost: '%WORDPRESS_DB_HOST%' + dbUser: '%WORDPRESS_DB_USER%' + dbPassword: '%WORDPRESS_DB_PASSWORD%' + wpDebug: true + tablePrefix: '%WORDPRESS_TABLE_PREFIX%' + domain: '%WP_DOMAIN%' + adminEmail: 'admin@%WP_DOMAIN%' + title: Test + configFile: '' + theme: dummy + plugins: + - doing-it-right/plugin.php + - doing-it-wrong-1/plugin.php + - doing-it-wrong-2/plugin.php + activateplugins: + - doing-it-right/plugin.php + - doing-it-wrong-1/plugin.php + activatePluginsSilently: + - doing-it-wrong-1/plugin.php + - doing-it-wrong-2/plugin.php + installationTableHandling: drop + booststrapActions: [] diff --git a/tests/wploader_plugin_silent_activation/DoingItRightTest.php b/tests/wploader_plugin_silent_activation/DoingItRightTest.php new file mode 100644 index 000000000..53c321932 --- /dev/null +++ b/tests/wploader_plugin_silent_activation/DoingItRightTest.php @@ -0,0 +1,26 @@ +assertTrue(is_plugin_active('doing-it-right/plugin.php')); + $this->assertEquals('activated', get_option('doing_it_right_activation')); + } + + /** + * It should correctly load the plugin + * + * @test + */ + public function should_correctly_load_the_plugin() + { + global $doing_it_right_plugin_loaded; + $this->assertTrue($doing_it_right_plugin_loaded); + } +} diff --git a/tests/wploader_plugin_silent_activation/DoingItWrongPluginOneTest.php b/tests/wploader_plugin_silent_activation/DoingItWrongPluginOneTest.php new file mode 100644 index 000000000..6af5330de --- /dev/null +++ b/tests/wploader_plugin_silent_activation/DoingItWrongPluginOneTest.php @@ -0,0 +1,35 @@ +assertTrue(is_plugin_active('doing-it-wrong-1/plugin.php')); + } + + /** + * It should not have set the option during the plugin activation + * + * @test + */ + public function should_have_not_set_the_option_during_the_plugin_activation() + { + $this->assertEquals('', get_option('doing_it_wrong_1_activation')); + } + + /** + * It should correctly load the plugin + * + * @test + */ + public function should_correctly_load_the_plugin() + { + global $doing_it_wrong_1_plugin_loaded; + $this->assertTrue($doing_it_wrong_1_plugin_loaded); + } +} diff --git a/tests/wploader_plugin_silent_activation/DoingItWrongPluginTwoTest.php b/tests/wploader_plugin_silent_activation/DoingItWrongPluginTwoTest.php new file mode 100644 index 000000000..f473f007d --- /dev/null +++ b/tests/wploader_plugin_silent_activation/DoingItWrongPluginTwoTest.php @@ -0,0 +1,35 @@ +assertTrue(is_plugin_active('doing-it-wrong-2/plugin.php')); + } + + /** + * It should have not set the option during the plugin activation + * + * @test + */ + public function should_have_set_not_the_option_during_the_plugin_activation() + { + $this->assertEquals('', get_option('doing_it_wrong_2_activation')); + } + + /** + * It should correctly load the plugin + * + * @test + */ + public function should_correctly_load_the_plugin() + { + global $doing_it_wrong_2_plugin_loaded; + $this->assertTrue($doing_it_wrong_2_plugin_loaded); + } +} diff --git a/tests/wploadersuite/BeforeAfterMethodsTest.php b/tests/wploadersuite/BeforeAfterMethodsTest.php index d83b24d73..95d9380a1 100644 --- a/tests/wploadersuite/BeforeAfterMethodsTest.php +++ b/tests/wploadersuite/BeforeAfterMethodsTest.php @@ -2,23 +2,28 @@ use PHPUnit\Framework\Assert; -class BeforeAfterMethodsTest extends \Codeception\TestCase\WPTestCase { - private static $staticCanary = true; - private $canary = false; +class BeforeAfterMethodsTest extends \Codeception\TestCase\WPTestCase +{ + private static $staticCanary = true; + private $canary = false; - public function _before() { - $this->canary = true; - } + public function _before() + { + $this->canary = true; + } - public function _after() { - self::$staticCanary = false; - } + public function _after() + { + self::$staticCanary = false; + } - public static function wpTearDownAfterClass() { - Assert::assertFalse( self::$staticCanary ); - } + public static function wpTearDownAfterClass() + { + Assert::assertFalse(self::$staticCanary); + } - public function test_before_method_is_loaded() { - $this->assertTrue( $this->canary ); - } + public function test_before_method_is_loaded() + { + $this->assertTrue($this->canary); + } }