Skip to content

Commit 298eed6

Browse files
committed
use csv formatter for generating csv
1 parent c27de24 commit 298eed6

File tree

4 files changed

+85
-4
lines changed

4 files changed

+85
-4
lines changed

exporters/class-exporter-csv.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,18 @@ public function output_file( $data, $columns ) {
3838
header( 'Content-Disposition: attachment; filename="stream.csv"' );
3939
}
4040

41-
$output = join( ',', array_values( $columns ) ) . "\n";
41+
ob_start();
42+
43+
$csv = fopen( 'php://output', 'w' );
44+
fputcsv( $csv, array_values( $columns ) );
45+
4246
foreach ( $data as $row ) {
43-
$output .= join( ',', $row ) . "\n";
47+
fputcsv( $csv, $row );
4448
}
49+
fclose( $csv ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose
50+
51+
echo ob_get_clean(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
4552

46-
echo $output; // @codingStandardsIgnoreLine text-only output
4753
if ( ! defined( 'WP_STREAM_TESTS' ) || ( defined( 'WP_STREAM_TESTS' ) && ! WP_STREAM_TESTS ) ) {
4854
exit;
4955
}

playwright-report/index.html

Lines changed: 68 additions & 0 deletions
Large diffs are not rendered by default.

test-results/.last-run.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"status": "failed",
3+
"failedTests": [
4+
"ccac176be2dd67697c22-b209136356c5d91f37c8",
5+
"ccac176be2dd67697c22-700362d9db1016336ce0"
6+
]
7+
}

tests/tests/test-class-export.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function test_render_download() {
4343
$output = ob_get_clean();
4444

4545
$this->assertNotEmpty( $output );
46-
$this->assertStringStartsWith( 'Date,Summary,User,Connector,Context,Action,IP Address', $output );
46+
$this->assertStringStartsWith( 'Date,Summary,User,Connector,Context,Action,"IP Address"', $output );
4747

4848
unset( $_GET['action'] );
4949
}

0 commit comments

Comments
 (0)