Make WordPress Core


Ignore:
Timestamp:
04/27/2015 02:47:22 PM (11 years ago)
Author:
pento
Message:

WPDB: Sanity check that any strings being stored in the DB are not too long to store correctly.

Merge [32299] to the 4.1 and 4.2 branches.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/4.1/tests/phpunit/tests/comment.php

    r30402 r32307  
    4343                $this->assertSame( array(), $found );
    4444        }
     45
     46        public function test_comment_content_length() {
     47                // `wp_new_comment()` checks REMOTE_ADDR, so we fake it to avoid PHP notices.
     48                if ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
     49                        $remote_addr = $_SERVER['REMOTE_ADDR'];
     50                } else {
     51                        $_SERVER['REMOTE_ADDR'] = '';
     52                }
     53
     54                $post_id = $this->factory->post->create();
     55
     56                $data = array(
     57                        'comment_post_ID' => $post_id,
     58                        'comment_author' => rand_str(),
     59                        'comment_author_url' => '',
     60                        'comment_author_email' => '',
     61                        'comment_type' => '',
     62                        'comment_content' => str_repeat( 'A', 65536 ),
     63                        'comment_date' => '2011-01-01 10:00:00',
     64                        'comment_date_gmt' => '2011-01-01 10:00:00',
     65                );
     66
     67                $id = wp_new_comment( $data );
     68
     69                $this->assertFalse( $id );
     70
     71                // Cleanup.
     72                if ( isset( $remote_addr ) ) {
     73                        $_SERVER['REMOTE_ADDR'] = $remote_addr;
     74                } else {
     75                        unset( $_SERVER['REMOTE_ADDR'] );
     76                }
     77        }
    4578}
Note: See TracChangeset for help on using the changeset viewer.