* Both strings are expected to have headers for their CSVs.
* $actualCSV must match all data rows in $expectedCSV
*
- * @return bool Whether $actualCSV contacts $expectedCSV
+ * @param string A CSV string
+ * @param array A nested array of values
+ * @return bool Whether $actualCSV contains $expectedCSV
*/
-function checkThatCsvStringContainsCsvString( $actualCSV, $expectedCSV ) {
+function checkThatCsvStringContainsValues( $actualCSV, $expectedCSV ) {
$actualCSV = array_map( 'str_getcsv', explode( PHP_EOL, $actualCSV ) );
- $expectedCSV = array_map( 'str_getcsv', explode( PHP_EOL, $expectedCSV ) );
if ( empty( $actualCSV ) )
return false;
When I run `wp post list --post_type='post' --fields=post_title,post_name,post_status --format=csv`
Then STDOUT should be CSV containing:
- """
- post_title,post_name,post_status
- "Publish post",publish-post,publish
- "Draft post",,draft
- """
+ | post_title | post_name | post_status |
+ | Publish post | publish-post | publish |
+ | Draft post | | draft |
});
$steps->Then( '/^STDOUT should be CSV containing:$/',
- function( $world, PyStringNode $expected ) {
+ function( $world, TableNode $expected ) {
$output = $world->result->STDOUT;
- $expected = $world->replace_variables( (string) $expected );
- if ( ! checkThatCsvStringContainsCsvString( $output, $expected ) )
+ $expectedRows = $expected->getRows();
+ foreach ( $expected as &$row ) {
+ foreach ( $row as &$value ) {
+ $value = $world->replace_variables( $value );
+ }
+ }
+
+ if ( ! checkThatCsvStringContainsValues( $output, $expectedRows ) )
throw new \Exception( $output );
}
);
When I run `wp term list post_tag --fields=name,slug --format=csv`
Then STDOUT should be CSV containing:
- """
- name,slug
- "Test term",test
- """
+ | name | slug |
+ | Test term | test |
Scenario: Creating/deleting a term
Given a WP install