| | 2774 | /** |
| | 2775 | * @ticket |
| | 2776 | */ |
| | 2777 | public function test_update_comment_db_error () { |
| | 2778 | global $wpdb; |
| | 2779 | |
| | 2780 | wp_set_current_user( self::$admin_id ); |
| | 2781 | |
| | 2782 | $params = array( |
| | 2783 | 'content' => 'This isn\'t a saxophone. It\'s an umbrella.', |
| | 2784 | ); |
| | 2785 | |
| | 2786 | // Block comments from being saved, simulate a DB error |
| | 2787 | add_filter( 'query', array( $this, '_block_comments' ) ); |
| | 2788 | |
| | 2789 | $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); |
| | 2790 | |
| | 2791 | $request->add_header( 'content-type', 'application/json' ); |
| | 2792 | $request->set_body( wp_json_encode( $params ) ); |
| | 2793 | |
| | 2794 | try { |
| | 2795 | $response = $this->server->dispatch( $request ); |
| | 2796 | } catch ( Exception $e ) { |
| | 2797 | $this->assertContains( 'Empty query', $e->getMessage() ); |
| | 2798 | } |
| | 2799 | |
| | 2800 | remove_filter( 'query', array( $this, '_block_comments' ) ); |
| | 2801 | } |
| | 2802 | |
| | 2803 | /** |
| | 2804 | * Block comments from being saved |
| | 2805 | */ |
| | 2806 | public function _block_comments( $sql ) { |
| | 2807 | global $wpdb; |
| | 2808 | if ( false !== strpos( $sql, $wpdb->comments ) && 0 === stripos( trim ( $sql ), 'UPDATE') ) { |
| | 2809 | //echo "\n". $sql . "\n"; |
| | 2810 | return ''; |
| | 2811 | } |
| | 2812 | return $sql; |
| | 2813 | } |
| | 2814 | |