| | 634 | |
| | 635 | /** |
| | 636 | * Test should generate JSON error when JSON encoding fails. |
| | 637 | * |
| | 638 | * @ticket 52892 |
| | 639 | */ |
| | 640 | public function test_should_generate_json_error_when_json_encoding_fails() { |
| | 641 | add_filter( 'get_post_metadata', array( $this, 'filter_export_data_grouped_metadata' ), 10, 3 ); |
| | 642 | |
| | 643 | // Validate JSON encoding fails and returns `false`. |
| | 644 | $metadata = get_post_meta( self::$export_request_id, '_export_data_grouped', true ); |
| | 645 | $this->assertFalse( wp_json_encode( $metadata ) ); |
| | 646 | |
| | 647 | $this->expectException( 'WPDieException' ); |
| | 648 | $this->expectOutputString( '{"success":false,"data":"Unable to encode the personal data for export. Error: Type is not supported"}' ); |
| | 649 | wp_privacy_generate_personal_data_export_file( self::$export_request_id ); |
| | 650 | } |
| | 651 | |
| | 652 | public function filter_export_data_grouped_metadata( $value, $object_id, $meta_key ) { |
| | 653 | if ( $object_id !== self::$export_request_id ) { |
| | 654 | return $value; |
| | 655 | } |
| | 656 | |
| | 657 | if ( '_export_data_grouped' !== $meta_key ) { |
| | 658 | return $value; |
| | 659 | } |
| | 660 | |
| | 661 | $file = fopen( __FILE__, 'r' ); |
| | 662 | |
| | 663 | $value = array( |
| | 664 | 'user' => array( |
| | 665 | 'group_label' => 'User', |
| | 666 | 'group_description' => 'User’s profile data.', |
| | 667 | 'items' => array(), |
| | 668 | 'resource' => $file, |
| | 669 | ), |
| | 670 | ); |
| | 671 | |
| | 672 | fclose( $file ); |
| | 673 | |
| | 674 | return array( $value ); |
| | 675 | } |