Skip to content

Commit f5101e4

Browse files
danielbachhuberbaizmandesign
authored andcommitted
Refactor Behat tests
1 parent 2020056 commit f5101e4

File tree

1 file changed

+45
-60
lines changed

1 file changed

+45
-60
lines changed

features/plugin-list.feature

Lines changed: 45 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,56 @@
11
Feature: List WordPress plugins
22

3-
Background:
3+
Scenario: Refresh update_plugins transient when listing plugins with --force-check flag
44
Given a WP install
55
And I run `wp plugin uninstall --all`
66
And I run `wp plugin install hello-dolly`
7-
And a setup.php file:
7+
And a update-transient.php file:
88
"""
99
<?php
10-
$plugin_transient = get_site_transient('update_plugins') ;
11-
# manually set the version
12-
$fake_version = '10.0.0';
13-
$plugin_transient->no_update["hello-dolly/hello.php"]->new_version = $fake_version;
14-
$return = set_site_transient( 'update_plugins', $plugin_transient );
10+
$transient = get_site_transient( 'update_plugins' );
11+
$transient->response['hello-dolly/hello.php'] = (object) array(
12+
'id' => 'w.org/plugins/hello-dolly',
13+
'slug' => 'hello-dolly',
14+
'plugin' => 'hello-dolly/hello.php',
15+
'new_version' => '100.0.0',
16+
'url' => 'https://wordpress.org/plugins/hello-dolly/',
17+
'package' => 'https://downloads.wordpress.org/plugin/hello-dolly.100.0.0.zip',
18+
);
19+
$transient->checked = array(
20+
'hello-dolly/hello.php' => '1.7.2',
21+
);
22+
unset( $transient->no_update['hello-dolly/hello.php'] );
23+
set_site_transient( 'update_plugins', $transient );
24+
WP_CLI::success( 'Transient updated.' );
1525
"""
16-
# And a wp-content/mu-plugins/test-plugin-update.php file:
17-
# """
18-
# <?php
19-
# /**
20-
# * Plugin Name: Test Plugin Update
21-
# * Description: Fakes installed plugin's data to verify plugin version mismatch
22-
# * Author: WP-CLI tests
23-
# */
24-
#
25-
# add_filter( 'site_transient_update_plugins', function( $value ) {
26-
# if ( ! is_object( $value ) ) {
27-
# return $value;
28-
# }
29-
# $fake_version = '10.0.0';
30-
#
31-
# unset( $value->response['hello-dolly/hello.php'] );
32-
# $value->no_update['hello-dolly/hello.php']->new_version = $fake_version;
33-
#
34-
# return $value;
35-
# } );
36-
# ?>
37-
# """
38-
39-
Scenario: Refresh update_plugins transient when listing plugins with --force-check flag
40-
41-
# Listing the plugins will populate the transient in the database
42-
When I run `wp plugin list`
43-
Then STDOUT should not be empty
44-
And save STDOUT as {PLUGIN_LIST_ORIGINAL_VERSIONS}
45-
46-
# Write a test value
47-
When I run `wp eval-file setup.php`
48-
Then STDOUT should be empty
4926

50-
# Get value of plugin transient
51-
#When I run `wp option get _site_transient_update_plugins`
52-
#Then STDOUT should be empty
27+
# Populates the initial transient in the database
28+
When I run `wp plugin list --fields=name,status,update`
29+
Then STDOUT should be a table containing rows:
30+
| name | status | update |
31+
| hello-dolly | inactive | none |
5332

54-
# Run list again
55-
When I run `wp plugin list`
56-
Then STDOUT should be empty
57-
And save STDOUT as {PLUGIN_LIST_FAKE_VERSIONS}
58-
59-
# TODO: compare {PLUGIN_LIST_ORIGINAL_VERSIONS} to {PLUGIN_LIST_FAKE_VERSIONS}
60-
# expected result: they should be different
61-
62-
# Get value of plugin transient
63-
When I run `wp option get _site_transient_update_plugins`
64-
Then STDOUT should be empty
65-
66-
When I run `wp plugin list --force-check`
67-
Then STDOUT should not be empty
68-
And save STDOUT as {PLUGIN_LIST_FORCE_CHECK_VERSIONS}
33+
# Modify the transient in the database to simulate an update
34+
When I run `wp eval-file update-transient.php`
35+
Then STDOUT should be:
36+
"""
37+
Success: Transient updated.
38+
"""
6939

70-
# TODO: compare {PLUGIN_LIST_ORIGINAL_VERSIONS} to {PLUGIN_LIST_FORCE_CHECK_VERSIONS}
71-
# expected result: they should be the same
40+
# Verify the fake transient value produces the expected output
41+
When I run `wp plugin list --fields=name,status,update`
42+
Then STDOUT should be a table containing rows:
43+
| name | status | update |
44+
| hello-dolly | inactive | available |
45+
46+
# Repeating the same command again should produce the same results
47+
When I run `wp plugin list --fields=name,status,update`
48+
Then STDOUT should be a table containing rows:
49+
| name | status | update |
50+
| hello-dolly | inactive | available |
51+
52+
# Using the --force-check flag should refresh the transient back to the original value
53+
When I run `wp plugin list --fields=name,status,update --force-check`
54+
Then STDOUT should be a table containing rows:
55+
| name | status | update |
56+
| hello-dolly | inactive | none |

0 commit comments

Comments
 (0)