-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #980 from Automattic/add/behat-tests
- Loading branch information
Showing
7 changed files
with
187 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
default: | ||
suites: | ||
default: | ||
contexts: | ||
- Automattic\CoAuthorsPlus\Tests\Behat\FeatureContext | ||
paths: | ||
- features |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Feature: Guest authors can be created | ||
|
||
Background: | ||
Given a WP installation with the Co-Authors Plus plugin | ||
|
||
Scenario: Create a guest author | ||
When I run `wp co-authors-plus create-guest-authors` | ||
Then STDOUT should be: | ||
""" | ||
All done! Here are your results: | ||
- 1 guest author profiles were created | ||
- 0 users already had guest author profiles | ||
""" | ||
|
||
Scenario: Try to create a guest authors a second time | ||
When I run `wp co-authors-plus create-guest-authors` | ||
Then I run the previous command again | ||
Then STDOUT should be: | ||
""" | ||
All done! Here are your results: | ||
- 0 guest author profiles were created | ||
- 1 users already had guest author profiles | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
Feature: Co-authors can be renamed | ||
|
||
Background: | ||
Given a WP installation with the Co-Authors Plus plugin | ||
|
||
Scenario: Error on a missing required --from parameter | ||
When I try `wp co-authors-plus rename-coauthor --to="still-not-a-user"` | ||
Then STDERR should be: | ||
""" | ||
Error: Parameter errors: | ||
missing --from parameter | ||
""" | ||
|
||
Scenario: Error on a missing required --to parameter | ||
When I try `wp co-authors-plus rename-coauthor --from="not-a-user"` | ||
Then STDERR should be: | ||
""" | ||
Error: Parameter errors: | ||
missing --to parameter | ||
""" | ||
|
||
Scenario: Error on an invalid co-author | ||
When I try `wp co-authors-plus rename-coauthor --from="not-a-user" --to="still-not-a-user"` | ||
Then STDERR should be: | ||
""" | ||
Error: No co-author found for not-a-user | ||
""" | ||
|
||
Scenario: Try to rename co-author to the same name | ||
When I try `wp co-authors-plus create-guest-authors` | ||
Then I try `wp co-authors-plus rename-coauthor --from="admin" --to="admin"` | ||
Then STDERR should be: | ||
""" | ||
Error: New user_login value conflicts with existing co-author | ||
""" | ||
|
||
Scenario: Rename co-author | ||
When I run `wp co-authors-plus create-guest-authors` | ||
Then I run `wp co-authors-plus rename-coauthor --from="admin" --to="renamed-admin"` | ||
Then STDOUT should be: | ||
""" | ||
Renaming admin to renamed-admin | ||
Updated guest author profile value too | ||
Success: All done! | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
Feature: The Behat tests are configured correctly | ||
|
||
Scenario: WP-CLI loads for your tests | ||
Given a WP install | ||
|
||
When I run `wp eval 'echo "Hello world.";'` | ||
Then STDOUT should be: | ||
""" | ||
Hello world. | ||
""" | ||
|
||
Scenario: WP-CLI recognises plugin commands | ||
Given a WP install | ||
|
||
When I run `wp plugin --help` | ||
Then STDOUT should contain: | ||
""" | ||
Manages plugins, including installs, activations, and updates. | ||
""" | ||
|
||
Scenario: WP-CLI recognises Co-Authors Plus commands when the plugin is loaded | ||
Given a WP installation with the Co-Authors Plus plugin | ||
|
||
When I run `wp co-authors-plus --help` | ||
Then STDOUT should contain: | ||
""" | ||
Manage co-authors and guest authors. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
/** | ||
* Feature tests context class with Co-Authors Plus specific steps. | ||
* | ||
* @package Automattic\CoAuthorsPlus | ||
*/ | ||
|
||
namespace Automattic\CoAuthorsPlus\Tests\Behat; | ||
|
||
use WP_CLI\Tests\Context\FeatureContext as WP_CLI_FeatureContext; | ||
|
||
/** | ||
* Feature tests context class with Co-Authors Plus-specific steps. | ||
* | ||
* This class extends the one that is provided by the wp-cli/wp-cli-tests package. | ||
* To see a list of all recognized step definitions, run `vendor/bin/behat -dl`. | ||
*/ | ||
final class FeatureContext extends WP_CLI_FeatureContext { | ||
|
||
/** | ||
* Set up the plugin to be active. | ||
* | ||
* @Given a WP install(ation) with the Co-Authors Plus plugin | ||
* | ||
* Adapted from https://github.com/wearerequired/traduttore/blob/master/tests/phpunit/tests/Behat/FeatureContext.php | ||
* with credit and thanks to them. | ||
*/ | ||
public function given_a_wp_installation_with_the_cap_plugin() { | ||
$this->install_wp(); | ||
|
||
// Symlink the current project folder into the WP folder as a plugin. | ||
$project_dir = realpath( self::get_vendor_dir() . '/../' ); | ||
$plugin_dir = $this->variables['RUN_DIR'] . '/wp-content/plugins'; | ||
$this->ensure_dir_exists( $plugin_dir ); | ||
$this->proc( "ln -s {$project_dir} {$plugin_dir}/co-authors-plus" )->run_check(); | ||
|
||
// Activate the plugin. | ||
$this->proc( 'wp plugin activate co-authors-plus' )->run_check(); | ||
} | ||
|
||
/** | ||
* Ensure that a requested directory exists and create it recursively as needed. | ||
* | ||
* Copied as is from the Tradutorre repo as well. | ||
* | ||
* @param string $directory Directory to ensure the existence of. | ||
* @throws \RuntimeException Directory could not be created. | ||
*/ | ||
private function ensure_dir_exists( $directory ) { | ||
$parent = dirname( $directory ); | ||
|
||
if ( ! empty( $parent ) && ! is_dir( $parent ) ) { | ||
$this->ensure_dir_exists( $parent ); | ||
} | ||
|
||
if ( ! is_dir( $directory ) && ! mkdir( $directory ) && ! is_dir( $directory ) ) { | ||
throw new \RuntimeException( "Could not create directory '{$directory}'." ); | ||
} | ||
} | ||
|
||
/** | ||
* Add a published post. | ||
* | ||
* @Given there is a published post with a slug of :post_name | ||
* | ||
* @param string $post_name Post name to use. | ||
*/ | ||
public function there_is_a_published_post( $post_name ) { | ||
$this->proc( "wp post create --post_title='{$post_name}' --post_name='{$post_name}' --post_status='publish'" )->run_check(); | ||
} | ||
} |