Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (6 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/comment/slashes.php

    r35244 r42343  
    2626    /**
    2727     * Tests the extended model function that expects slashed data
    28      *
    2928     */
    3029    function test_wp_new_comment() {
     
    3433        // as slashes are not permitted in that data
    3534        $data = array(
    36             'comment_post_ID' => $post_id,
    37             'comment_author' => $this->slash_1,
    38             'comment_author_url' => '',
     35            'comment_post_ID'      => $post_id,
     36            'comment_author'       => $this->slash_1,
     37            'comment_author_url'   => '',
    3938            'comment_author_email' => '',
    40             'comment_type' => '',
    41             'comment_content' => $this->slash_7,
     39            'comment_type'         => '',
     40            'comment_content'      => $this->slash_7,
    4241        );
    43         $id = wp_new_comment( $data );
     42        $id   = wp_new_comment( $data );
    4443
    45         $comment = get_comment($id);
     44        $comment = get_comment( $id );
    4645
    4746        $this->assertEquals( wp_unslash( $this->slash_1 ), $comment->comment_author );
     
    4948
    5049        $data = array(
    51             'comment_post_ID' => $post_id,
    52             'comment_author' => $this->slash_2,
    53             'comment_author_url' => '',
     50            'comment_post_ID'      => $post_id,
     51            'comment_author'       => $this->slash_2,
     52            'comment_author_url'   => '',
    5453            'comment_author_email' => '',
    55             'comment_type' => '',
    56             'comment_content' => $this->slash_4,
     54            'comment_type'         => '',
     55            'comment_content'      => $this->slash_4,
    5756        );
    58         $id = wp_new_comment( $data );
     57        $id   = wp_new_comment( $data );
    5958
    60         $comment = get_comment($id);
     59        $comment = get_comment( $id );
    6160
    6261        $this->assertEquals( wp_unslash( $this->slash_2 ), $comment->comment_author );
     
    6665    /**
    6766     * Tests the controller function that expects slashed data
    68      *
    6967     */
    7068    function test_edit_comment() {
    71         $post_id = self::factory()->post->create();
    72         $comment_id = self::factory()->comment->create(array(
    73             'comment_post_ID' => $post_id
    74         ));
     69        $post_id    = self::factory()->post->create();
     70        $comment_id = self::factory()->comment->create(
     71            array(
     72                'comment_post_ID' => $post_id,
     73            )
     74        );
    7575
    7676        // not testing comment_author_email or comment_author_url
    7777        // as slashes are not permitted in that data
    78         $_POST = array();
    79         $_POST['comment_ID'] = $comment_id;
    80         $_POST['comment_status'] = '';
    81         $_POST['newcomment_author'] = $this->slash_1;
    82         $_POST['newcomment_author_url'] = '';
     78        $_POST                            = array();
     79        $_POST['comment_ID']              = $comment_id;
     80        $_POST['comment_status']          = '';
     81        $_POST['newcomment_author']       = $this->slash_1;
     82        $_POST['newcomment_author_url']   = '';
    8383        $_POST['newcomment_author_email'] = '';
    84         $_POST['content'] = $this->slash_7;
    85         $_POST = add_magic_quotes( $_POST );
     84        $_POST['content']                 = $this->slash_7;
     85        $_POST                            = add_magic_quotes( $_POST );
    8686
    8787        edit_comment();
     
    9191        $this->assertEquals( $this->slash_7, $comment->comment_content );
    9292
    93         $_POST = array();
    94         $_POST['comment_ID'] = $comment_id;
    95         $_POST['comment_status'] = '';
    96         $_POST['newcomment_author'] = $this->slash_2;
    97         $_POST['newcomment_author_url'] = '';
     93        $_POST                            = array();
     94        $_POST['comment_ID']              = $comment_id;
     95        $_POST['comment_status']          = '';
     96        $_POST['newcomment_author']       = $this->slash_2;
     97        $_POST['newcomment_author_url']   = '';
    9898        $_POST['newcomment_author_email'] = '';
    99         $_POST['content'] = $this->slash_4;
    100         $_POST = add_magic_quotes( $_POST );
     99        $_POST['content']                 = $this->slash_4;
     100        $_POST                            = add_magic_quotes( $_POST );
    101101
    102102        edit_comment();
     
    109109    /**
    110110     * Tests the model function that expects slashed data
    111      *
    112111     */
    113112    function test_wp_insert_comment() {
    114113        $post_id = self::factory()->post->create();
    115114
    116         $comment_id = wp_insert_comment(array(
    117             'comment_post_ID' => $post_id,
    118             'comment_author' => $this->slash_1,
    119             'comment_content' => $this->slash_7,
    120         ));
    121         $comment = get_comment( $comment_id );
     115        $comment_id = wp_insert_comment(
     116            array(
     117                'comment_post_ID' => $post_id,
     118                'comment_author'  => $this->slash_1,
     119                'comment_content' => $this->slash_7,
     120            )
     121        );
     122        $comment    = get_comment( $comment_id );
    122123
    123124        $this->assertEquals( wp_unslash( $this->slash_1 ), $comment->comment_author );
    124125        $this->assertEquals( wp_unslash( $this->slash_7 ), $comment->comment_content );
    125126
    126         $comment_id = wp_insert_comment(array(
    127             'comment_post_ID' => $post_id,
    128             'comment_author' => $this->slash_2,
    129             'comment_content' => $this->slash_4,
    130         ));
    131         $comment = get_comment( $comment_id );
     127        $comment_id = wp_insert_comment(
     128            array(
     129                'comment_post_ID' => $post_id,
     130                'comment_author'  => $this->slash_2,
     131                'comment_content' => $this->slash_4,
     132            )
     133        );
     134        $comment    = get_comment( $comment_id );
    132135
    133136        $this->assertEquals( wp_unslash( $this->slash_2 ), $comment->comment_author );
     
    137140    /**
    138141     * Tests the model function that expects slashed data
    139      *
    140142     */
    141143    function test_wp_update_comment() {
    142         $post_id = self::factory()->post->create();
    143         $comment_id = self::factory()->comment->create(array(
    144             'comment_post_ID' => $post_id
    145         ));
     144        $post_id    = self::factory()->post->create();
     145        $comment_id = self::factory()->comment->create(
     146            array(
     147                'comment_post_ID' => $post_id,
     148            )
     149        );
    146150
    147         wp_update_comment(array(
    148             'comment_ID' => $comment_id,
    149             'comment_author' => $this->slash_1,
    150             'comment_content' => $this->slash_7,
    151         ));
     151        wp_update_comment(
     152            array(
     153                'comment_ID'      => $comment_id,
     154                'comment_author'  => $this->slash_1,
     155                'comment_content' => $this->slash_7,
     156            )
     157        );
    152158        $comment = get_comment( $comment_id );
    153159
     
    155161        $this->assertEquals( wp_unslash( $this->slash_7 ), $comment->comment_content );
    156162
    157         wp_update_comment(array(
    158             'comment_ID' => $comment_id,
    159             'comment_author' => $this->slash_2,
    160             'comment_content' => $this->slash_4,
    161         ));
     163        wp_update_comment(
     164            array(
     165                'comment_ID'      => $comment_id,
     166                'comment_author'  => $this->slash_2,
     167                'comment_content' => $this->slash_4,
     168            )
     169        );
    162170        $comment = get_comment( $comment_id );
    163171
Note: See TracChangeset for help on using the changeset viewer.