Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions features/db-check.feature
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Feature: Check the database

@require-mysql-or-mariadb
Scenario: Run db check to check the database
Given a WP install

Expand All @@ -13,6 +14,7 @@ Feature: Check the database
Success: Database checked.
"""

@require-mysql-or-mariadb
Scenario: Run db check with MySQL defaults to check the database
Given a WP install

Expand All @@ -26,6 +28,7 @@ Feature: Check the database
Success: Database checked.
"""

@require-mysql-or-mariadb
Scenario: Run db check with --no-defaults to check the database
Given a WP install

Expand All @@ -39,6 +42,7 @@ Feature: Check the database
Success: Database checked.
"""

@require-mysql-or-mariadb
Scenario: Run db check with passed-in options
Given a WP install

Expand Down Expand Up @@ -124,6 +128,7 @@ Feature: Check the database
"""
And STDOUT should be empty

@require-mysql-or-mariadb
Scenario: MySQL defaults are available as appropriate with --defaults flag
Given a WP install

Expand All @@ -136,3 +141,12 @@ Feature: Check the database
When I try `wp db check --no-defaults --debug`
Then STDERR should match #Debug \(db\): Running shell command: /usr/bin/env (mysqlcheck|mariadb-check) --no-defaults %s#

@require-sqlite
Scenario: SQLite commands that show warnings
Given a WP install

When I try `wp db check`
Then STDERR should contain:
"""
Warning: Database check is not supported for SQLite databases
"""
11 changes: 11 additions & 0 deletions features/db-cli.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Feature: Open a MySQL console

@require-sqlite
Scenario: SQLite commands that show warnings for cli
Given a WP install

When I try `wp db cli`
Then STDERR should contain:
"""
Warning: Interactive console (cli) is not supported for SQLite databases
"""
12 changes: 12 additions & 0 deletions features/db-columns.feature
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Feature: Display information about a given table.
Couldn't find any tables matching: wp_foobar
"""

@require-mysql-or-mariadb
Scenario: Display information about a non default WordPress table
Given a WP install
And I run `wp db query "CREATE TABLE not_wp ( date DATE NOT NULL, awesome_stuff TEXT, PRIMARY KEY (date) );;"`
Expand All @@ -50,3 +51,14 @@ Feature: Display information about a given table.
| Field | Type | Null | Key | Default | Extra |
| date | date | NO | PRI | | |
| awesome_stuff | text | YES | | | |

@require-sqlite
Scenario: Display information about a non default WordPress table
Given a WP install
And I run `wp db query "CREATE TABLE not_wp ( date DATE NOT NULL, awesome_stuff TEXT, PRIMARY KEY (date) );;"`

When I try `wp db columns not_wp`
Then STDOUT should be a table containing rows:
| Field | Type | Null | Key | Default |
| date | TEXT | NO | PRI | '' |
| awesome_stuff | TEXT | YES | | |
24 changes: 24 additions & 0 deletions features/db-create.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Feature: Create a new database

@require-mysql-or-mariadb
Scenario: Create a new database
Given an empty directory
And WP files
And wp-config.php

When I run `wp db create`
Then STDOUT should contain:
"""
Success: Database created.
"""

@require-sqlite
Scenario: SQLite DB create operation should fail if already existing
Given a WP install

When I try `wp db create`
Then the return code should be 1
And STDERR should contain:
"""
Database already exists
"""
32 changes: 23 additions & 9 deletions features/db-export.feature
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,10 @@ Feature: Export a WordPress database
Scenario: Exclude tables when exporting the database
Given a WP install

When I run `wp db export wp_cli_test.sql --exclude_tables=wp_users --porcelain`
When I try `wp db export wp_cli_test.sql --exclude_tables=wp_users --porcelain`
Then the wp_cli_test.sql file should exist
And the wp_cli_test.sql file should not contain:
"""
wp_users
"""
And the wp_cli_test.sql file should contain:
"""
wp_options
"""
And the contents of the wp_cli_test.sql file should not match /CREATE TABLE ["`]?wp_users["`]?/
And the contents of the wp_cli_test.sql file should match /CREATE TABLE ["`]?wp_options["`]?/

Scenario: Export database to STDOUT
Given a WP install
Expand Down Expand Up @@ -61,6 +55,7 @@ Feature: Export a WordPress database
-- Dump completed on
"""

@require-mysql-or-mariadb
Scenario: Export database with passed-in options
Given a WP install

Expand All @@ -78,6 +73,25 @@ Feature: Export a WordPress database
"""
And STDOUT should be empty

@require-sqlite
Scenario: Export database with passed-in options
Given a WP install

When I run `wp db export - --skip-comments`
Then STDOUT should not contain:
"""
-- Table structure
"""

# dbpass has no effect on SQLite
When I try `wp db export - --dbpass=no_such_pass`
Then the return code should be 0
And STDERR should not contain:
"""
Access denied
"""

@require-mysql-or-mariadb
Scenario: MySQL defaults are available as appropriate with --defaults flag
Given a WP install

Expand Down
33 changes: 32 additions & 1 deletion features/db-import.feature
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ Feature: Import a WordPress database
"""
wp db import
"""

@require-mysql-or-mariadb
Scenario: MySQL defaults are available as appropriate with --defaults flag
Given a WP install

Expand All @@ -142,7 +144,7 @@ Feature: Import a WordPress database
When I try `wp db import --no-defaults --debug`
Then STDERR should match #Debug \(db\): Running shell command: /usr/bin/env (mysql|mariadb) --no-defaults --no-auto-rehash#

@require-wp-4.2
@require-wp-4.2 @require-mysql-or-mariadb
Scenario: Import db that has emoji in post
Given a WP install

Expand Down Expand Up @@ -178,3 +180,32 @@ Feature: Import a WordPress database
"""
🍣
"""

@require-wp-4.2 @require-sqlite
Scenario: Import db that has emoji in post
Given a WP install

When I run `wp post create --post_title="🍣"`
And I run `wp post list`
Then the return code should be 0
And STDOUT should contain:
"""
🍣
"""

When I try `wp db export wp_cli_test.sql --debug`
Then the return code should be 0
And the wp_cli_test.sql file should exist

When I run `wp db import --dbuser=wp_cli_test --dbpass=password1`
Then STDOUT should be:
"""
Success: Imported from 'wp_cli_test.sql'.
"""

When I run `wp post list`
Then the return code should be 0
And STDOUT should contain:
"""
🍣
"""
21 changes: 21 additions & 0 deletions features/db-optimize.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Feature: Optimize the database

@require-mysql-or-mariadb
Scenario: Run db optimize to optimize the database
Given a WP install

When I run `wp db optimize`
Then STDOUT should contain:
"""
Success: Database optimized.
"""

@require-sqlite
Scenario: SQLite commands that show warnings for optimize
Given a WP install

When I try `wp db optimize`
Then STDERR should contain:
"""
Warning: Database optimization is not supported for SQLite databases
"""
1 change: 1 addition & 0 deletions features/db-query.feature
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Feature: Query the database with WordPress' MySQL config
"""
And STDOUT should be empty

@require-mysql-or-mariadb
Scenario: MySQL defaults are available as appropriate with --defaults flag
Given a WP install

Expand Down
21 changes: 21 additions & 0 deletions features/db-repair.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Feature: Repair the database

@require-mysql-or-mariadb
Scenario: Run db repair to repair the database
Given a WP install

When I run `wp db repair`
Then STDOUT should contain:
"""
Success: Database repaired.
"""

@require-sqlite
Scenario: SQLite commands that show warnings for repair
Given a WP install

When I try `wp db repair`
Then STDERR should contain:
"""
Warning: Database repair is not supported for SQLite databases
"""
54 changes: 54 additions & 0 deletions features/db-size.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

Feature: Display database size

@require-mysql-or-mariadb
Scenario: Display only database size for a WordPress install
Given a WP install

Expand All @@ -16,6 +17,21 @@ Feature: Display database size
B
"""

@require-sqlite
Scenario: Display only database size for a WordPress install
Given a WP install

When I run `wp db size`
Then STDOUT should contain:
"""
.ht.sqlite
"""

And STDOUT should contain:
"""
B
"""

Scenario: Display only table sizes for a WordPress install
Given a WP install

Expand All @@ -27,6 +43,7 @@ Feature: Display database size
wp_cli_test
"""

@require-mysql-or-mariadb
Scenario: Display only database size in a human readable format for a WordPress install
Given a WP install

Expand All @@ -49,6 +66,21 @@ Feature: Display database size
"""
And STDOUT should be empty

@require-sqlite
Scenario: Display only database size in a human readable format for a WordPress install
Given a WP install

When I run `wp db size --human-readable`
Then STDOUT should contain:
"""
.ht.sqlite
"""

And STDOUT should contain:
"""
KB
"""

Scenario: Display only table sizes in a human readable format for a WordPress install
Given a WP install

Expand Down Expand Up @@ -155,6 +187,7 @@ Feature: Display database size
MB
"""

@require-mysql-or-mariadb
Scenario: Display database size in bytes with specific format for a WordPress install
Given a WP install

Expand All @@ -175,6 +208,27 @@ Feature: Display database size

But STDOUT should not be a number

@require-sqlite
Scenario: Display database size in bytes with specific format for a WordPress install
Given a WP install

When I run `wp db size --size_format=b --format=csv`
Then STDOUT should contain:
"""
Name,Size
.ht.sqlite,"
"""

But STDOUT should not be a number

When I run `wp db size --size_format=b --format=json`
Then STDOUT should contain:
"""
[{"Name":".ht.sqlite","Size":"
"""

But STDOUT should not be a number

Scenario: Display all table sizes for a WordPress install
Given a WP install

Expand Down
Loading
Loading