wp_upgrade();
WP_CLI::success( 'WordPress database upgraded successfully.' );
}
-
- /**
- * Set up the official test suite using the current WordPress instance.
- *
- * @subcommand init-tests
- *
- * ## OPTIONS
- *
- * [<path>]
- * : The directory in which to download the testing suite files. (Optional)
- *
- * --dbname=<dbname>
- * : Set the database name. **WARNING**: The database will be whipped every time
- * you run the tests.
- *
- * --dbuser=<dbuser>
- * : Set the database user.
- *
- * [--dbpass=<dbpass>]
- * : Set the database user password.
- *
- * [--dbhost=<host>]
- * : Set the database host.
- *
- * ## EXAMPLE
- *
- * wp core init-tests ~/svn/wp-tests --dbname=wp_test --dbuser=wp_test
- */
- function init_tests( $args, $assoc_args ) {
- if ( isset( $args[0] ) )
- $tests_dir = trailingslashit( $args[0] );
- else
- $tests_dir = ABSPATH . 'unit-tests/';
-
- $assoc_args = wp_parse_args( $assoc_args, array(
- 'dbpass' => '',
- 'dbhost' => 'localhost'
- ) );
-
- // Download the test suite
- WP_CLI::launch( 'svn co https://unit-test.svn.wordpress.org/trunk/ ' . escapeshellarg( $tests_dir ) );
-
- // Create the database
- $query = sprintf( 'CREATE DATABASE IF NOT EXISTS `%s`', $assoc_args['dbname'] );
-
- Utils\run_mysql_command( 'mysql --no-defaults', array(
- 'execute' => $query,
- 'host' => $assoc_args['dbhost'],
- 'user' => $assoc_args['dbuser'],
- 'pass' => $assoc_args['dbpass'],
- ) );
-
- // Create the wp-tests-config.php file
- $config_file = file_get_contents( $tests_dir . 'wp-tests-config-sample.php' );
-
- $replacements = array(
- "dirname( __FILE__ ) . '/wordpress/'" => "'" . ABSPATH . "'",
- "yourdbnamehere" => $assoc_args['dbname'],
- "yourusernamehere" => $assoc_args['dbuser'],
- "yourpasswordhere" => $assoc_args['dbpass'],
- "localhost" => $assoc_args['dbhost'],
- );
-
- $config_file = str_replace( array_keys( $replacements ), array_values( $replacements ), $config_file );
-
- $config_file_path = $tests_dir . 'wp-tests-config.php';
-
- file_put_contents( $config_file_path, $config_file );
-
- WP_CLI::success( "Created $config_file_path" );
- }
}
WP_CLI::add_command( 'core', 'Core_Command' );