From e92e86db649626f55870125d66d316b9a94e90b7 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Thu, 14 Dec 2017 06:04:31 -0800 Subject: [PATCH 1/2] Use a helper `count-instances.php` script for cross-platform compat Uses `wp` instead of calling `php` directly to use WP-CLI's ability to use multiple PHP executables --- features/export.feature | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/features/export.feature b/features/export.feature index 55613455c..17a39a7dd 100644 --- a/features/export.feature +++ b/features/export.feature @@ -429,9 +429,14 @@ Feature: Export content. Scenario: Export posts using --max_num_posts Given a WP install + And a count-instances.php file: + """ + ' . $args[0] . '<\/wp:post_type>#', file_get_contents( 'php://stdin' ) ); + """ When I run `wp post generate --post_type=post --count=10` - And I run `wp export --post_type=post --max_num_posts=1 --stdout | grep -cF 'post'` + And I run `wp export --post_type=post --max_num_posts=1 --stdout | wp --skip-wordpress eval-file count-instances.php post` Then STDOUT should be: """ 1 @@ -439,12 +444,18 @@ Feature: Export content. When I run `wp post generate --post_type=post --count=10` And I run `wp post generate --post_type=attachment --count=10` - And I run `wp export --max_num_posts=1 --stdout | grep -cP '\(attachment|post)\'` + And I run `wp export --max_num_posts=1 --stdout | wp --skip-wordpress eval-file count-instances.php "(post|attachment)"` Then STDOUT should be: """ 1 """ + When I run `wp export --max_num_posts=5 --stdout | wp --skip-wordpress eval-file count-instances.php "(post|attachment)"` + Then STDOUT should be: + """ + 5 + """ + Scenario: Export a site with a custom filename format Given a WP install From 8e3b2b8740ec8416ab939eccfeec0510818a9255 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Thu, 14 Dec 2017 09:59:10 -0800 Subject: [PATCH 2/2] Add `$matches` for PHP 5.3 compat --- features/export.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/export.feature b/features/export.feature index 17a39a7dd..60f32fd83 100644 --- a/features/export.feature +++ b/features/export.feature @@ -432,7 +432,7 @@ Feature: Export content. And a count-instances.php file: """ ' . $args[0] . '<\/wp:post_type>#', file_get_contents( 'php://stdin' ) ); + echo preg_match_all( '#' . $args[0] . '<\/wp:post_type>#', file_get_contents( 'php://stdin' ), $matches ); """ When I run `wp post generate --post_type=post --count=10`