Skip to content

Commit

Permalink
Merge pull request #133 from 2ndkauboy/104-add-locale-parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
schlessera authored Aug 26, 2022
2 parents 709cec9 + 14b426e commit ea2adda
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 9 deletions.
85 changes: 85 additions & 0 deletions features/core-install.feature
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,91 @@ Feature: Install WordPress core
"""
And the return code should be 0
@less-than-php-7
Scenario: Install WordPress with locale set to de_DE on WP < 4.0
Given an empty directory
And an empty cache
And a database
When I run `wp core download --version=3.7 --locale=de_DE`
And save STDOUT 'Downloading WordPress ([\d\.]+)' as {VERSION}
And I run `echo {VERSION}`
Then STDOUT should contain:
"""
3.7
"""
And the wp-settings.php file should exist
And the {SUITE_CACHE_DIR}/core/wordpress-{VERSION}-de_DE.tar.gz file should exist
When I run `wp config create --dbname={DB_NAME} --dbuser={DB_USER} --dbpass={DB_PASSWORD} --dbhost={DB_HOST} --locale=de_DE`
Then STDOUT should be:
"""
Success: Generated 'wp-config.php' file.
"""
# Old versions of WP can generate wpdb database errors if the WP tables don't exist, so STDERR may or may not be empty
When I try `wp core install --url=example.org --title=Test --admin_user=testadmin [email protected] --admin_password=newpassword --locale=de_DE --skip-email`
Then STDERR should contain:
"""
Warning: The flag --locale=de_DE is being ignored as it requires WordPress 4.0+.
"""
Then STDOUT should contain:
"""
Success: WordPress installed successfully.
"""
When I run `wp core version`
Then STDOUT should contain:
"""
3.7
"""
When I run `wp taxonomy list`
Then STDOUT should contain:
"""
Kategorien
"""
Scenario: Install WordPress with locale set to de_DE on WP >= 4.0
Given an empty directory
And an empty cache
And a database

When I run `wp core download --version=5.6 --locale=de_DE`
And save STDOUT 'Downloading WordPress ([\d\.]+)' as {VERSION}
And I run `echo {VERSION}`
Then STDOUT should contain:
"""
5.6
"""
And the wp-settings.php file should exist
And the {SUITE_CACHE_DIR}/core/wordpress-{VERSION}-de_DE.tar.gz file should exist

When I run `wp config create --dbname={DB_NAME} --dbuser={DB_USER} --dbpass={DB_PASSWORD} --dbhost={DB_HOST} --locale=de_DE`
Then STDOUT should be:
"""
Success: Generated 'wp-config.php' file.
"""

# Old versions of WP can generate wpdb database errors if the WP tables don't exist, so STDERR may or may not be empty
When I run `wp core install --url=example.org --title=Test --admin_user=testadmin --admin_email=testadmin@example.com --admin_password=newpassword --locale=de_DE --skip-email`
Then STDOUT should contain:
"""
Success: WordPress installed successfully.
"""

When I run `wp core version`
Then STDOUT should contain:
"""
5.6
"""

When I run `wp taxonomy list`
Then STDOUT should contain:
"""
Kategorien
"""

Scenario: Install WordPress multisite without specifying the password
Given an empty directory
And WP files
Expand Down
2 changes: 1 addition & 1 deletion features/core.feature
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ Feature: Manage WordPress installation
<?php
// ** MySQL settings ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wp_cli_test');
define('DB_NAME', '{DB_NAME}');
/** MySQL database username */
define('DB_USER', '{DB_USER}');
Expand Down
44 changes: 36 additions & 8 deletions src/Core_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,9 @@ public function is_installed( $args, $assoc_args ) {
* --admin_email=<email>
* : The email address for the admin user.
*
* [--locale=<locale>]
* : The locale/language for the installation (e.g. `de_DE`). Default is `en_US`.
*
* [--skip-email]
* : Don't send an email notification to the new admin user.
*
Expand Down Expand Up @@ -605,6 +608,19 @@ function wp_new_blog_notification() {
'admin_password' => '',
];

if ( Utils\wp_version_compare( '4.0', '<' ) ) {
if ( array_key_exists( 'locale', $assoc_args ) ) {
WP_CLI::warning(
sprintf(
'The flag --locale=%s is being ignored as it requires WordPress 4.0+.',
$assoc_args['locale']
)
);
}
} else {
$defaults['locale'] = '';
}

$args = wp_parse_args( $assoc_args, $defaults );

// Support prompting for the `--url=<url>`,
Expand All @@ -622,14 +638,26 @@ function wp_new_blog_notification() {
WP_CLI::error( "The '{$args['admin_email']}' email address is invalid." );
}

$result = wp_install(
$args['title'],
$args['admin_user'],
$args['admin_email'],
$public,
'',
$password
);
if ( Utils\wp_version_compare( '4.0', '>=' ) ) {
$result = wp_install(
$args['title'],
$args['admin_user'],
$args['admin_email'],
$public,
'',
$password,
$args['locale']
);
} else {
$result = wp_install(
$args['title'],
$args['admin_user'],
$args['admin_email'],
$public,
'',
$password
);
}

if ( is_wp_error( $result ) ) {
$reason = WP_CLI::error_to_string( $result );
Expand Down

0 comments on commit ea2adda

Please sign in to comment.