Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (8 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/url.php

    r36722 r42343  
    8585            array(
    8686                null,
    87                 '/wp-admin/'
     87                '/wp-admin/',
    8888            ),
    8989            array(
    9090                0,
    91                 '/wp-admin/'
     91                '/wp-admin/',
    9292            ),
    9393            array(
    9494                -1,
    95                 '/wp-admin/'
     95                '/wp-admin/',
    9696            ),
    9797            array(
    9898                '///',
    99                 '/wp-admin/'
     99                '/wp-admin/',
    100100            ),
    101101            array(
     
    153153            array(
    154154                null,
    155                 "",
     155                '',
    156156            ),
    157157            array(
    158158                0,
    159                 "",
     159                '',
    160160            ),
    161161            array(
    162162                -1,
    163                 "",
     163                '',
    164164            ),
    165165            array(
    166166                '///',
    167                 "/",
     167                '/',
    168168            ),
    169169            array(
    170170                '',
    171                 "",
     171                '',
    172172            ),
    173173            array(
    174174                'foo',
    175                 "/foo",
    176             ),
    177             array(
    178175                '/foo',
    179                 "/foo",
     176            ),
     177            array(
     178                '/foo',
     179                '/foo',
    180180            ),
    181181            array(
    182182                '/foo/',
    183                 "/foo/",
     183                '/foo/',
    184184            ),
    185185            array(
    186186                'foo.php',
    187                 "/foo.php",
    188             ),
    189             array(
    190187                '/foo.php',
    191                 "/foo.php",
     188            ),
     189            array(
     190                '/foo.php',
     191                '/foo.php',
    192192            ),
    193193            array(
    194194                '/foo.php?bar=1',
    195                 "/foo.php?bar=1",
     195                '/foo.php?bar=1',
    196196            ),
    197197        );
     
    203203        // Pretend to be in the site admin
    204204        set_current_screen( 'dashboard' );
    205         $home = get_option('home');
     205        $home = get_option( 'home' );
    206206
    207207        // home_url() should return http when in the admin
     
    216216        $this->assertEquals( $home, home_url() );
    217217        $_SERVER['HTTPS'] = 'on';
    218         $home = str_replace('http://', 'https://', $home);
    219         $this->assertEquals( $home, home_url() );
    220 
     218        $home             = str_replace( 'http://', 'https://', $home );
     219        $this->assertEquals( $home, home_url() );
    221220
    222221        // Test with https in home
     
    225224        // Pretend to be in the site admin
    226225        set_current_screen( 'dashboard' );
    227         $home = get_option('home');
     226        $home = get_option( 'home' );
    228227
    229228        // home_url() should return whatever scheme is set in the home option when in the admin
     
    255254
    256255        // home_url() should return http when in the admin
    257         $this->assertEquals( 0, strpos( $home, 'http://') );
     256        $this->assertEquals( 0, strpos( $home, 'http://' ) );
    258257        $_SERVER['HTTPS'] = 'on';
    259258        $this->assertEquals( $home, network_home_url() );
     
    266265        $this->assertEquals( $home, network_home_url() );
    267266        $_SERVER['HTTPS'] = 'on';
    268         $home = str_replace('http://', 'https://', $home);
     267        $home             = str_replace( 'http://', 'https://', $home );
    269268        $this->assertEquals( $home, network_home_url() );
    270269
     
    273272
    274273    function test_set_url_scheme() {
    275         if ( ! function_exists( 'set_url_scheme' ) )
     274        if ( ! function_exists( 'set_url_scheme' ) ) {
    276275            return;
     276        }
    277277
    278278        $links = array(
     
    301301            '/',
    302302            '/news/',
    303             ''
     303            '',
    304304        );
    305305
    306306        $forced_admin = force_ssl_admin();
    307         $i = 0;
     307        $i            = 0;
    308308        foreach ( $links as $link ) {
    309309            $this->assertEquals( $https_links[ $i ], set_url_scheme( $link, 'https' ) );
     
    336336
    337337    public function test_get_adjacent_post() {
    338         $now = time();
    339         $post_id = self::factory()->post->create( array( 'post_date' => date( 'Y-m-d H:i:s', $now - 1 ) ) );
     338        $now      = time();
     339        $post_id  = self::factory()->post->create( array( 'post_date' => date( 'Y-m-d H:i:s', $now - 1 ) ) );
    340340        $post_id2 = self::factory()->post->create( array( 'post_date' => date( 'Y-m-d H:i:s', $now ) ) );
    341341
    342         if ( ! isset( $GLOBALS['post'] ) )
     342        if ( ! isset( $GLOBALS['post'] ) ) {
    343343            $GLOBALS['post'] = null;
    344         $orig_post = $GLOBALS['post'];
     344        }
     345        $orig_post       = $GLOBALS['post'];
    345346        $GLOBALS['post'] = get_post( $post_id2 );
    346347
     
    370371     */
    371372    public function test_get_adjacent_post_should_return_private_posts_belonging_to_the_current_user() {
    372         $u = self::factory()->user->create( array( 'role' => 'author' ) );
     373        $u       = self::factory()->user->create( array( 'role' => 'author' ) );
    373374        $old_uid = get_current_user_id();
    374375        wp_set_current_user( $u );
    375376
    376377        $now = time();
    377         $p1 = self::factory()->post->create( array( 'post_author' => $u, 'post_status' => 'private', 'post_date' => date( 'Y-m-d H:i:s', $now - 1 ) ) );
    378         $p2 = self::factory()->post->create( array( 'post_author' => $u, 'post_date' => date( 'Y-m-d H:i:s', $now ) ) );
     378        $p1  = self::factory()->post->create(
     379            array(
     380                'post_author' => $u,
     381                'post_status' => 'private',
     382                'post_date'   => date( 'Y-m-d H:i:s', $now - 1 ),
     383            )
     384        );
     385        $p2  = self::factory()->post->create(
     386            array(
     387                'post_author' => $u,
     388                'post_date'   => date( 'Y-m-d H:i:s', $now ),
     389            )
     390        );
    379391
    380392        if ( ! isset( $GLOBALS['post'] ) ) {
     
    396408     */
    397409    public function test_get_adjacent_post_should_return_private_posts_belonging_to_other_users_if_the_current_user_can_read_private_posts() {
    398         $u1 = self::factory()->user->create( array( 'role' => 'author' ) );
    399         $u2 = self::factory()->user->create( array( 'role' => 'administrator' ) );
     410        $u1      = self::factory()->user->create( array( 'role' => 'author' ) );
     411        $u2      = self::factory()->user->create( array( 'role' => 'administrator' ) );
    400412        $old_uid = get_current_user_id();
    401413        wp_set_current_user( $u2 );
    402414
    403415        $now = time();
    404         $p1 = self::factory()->post->create( array( 'post_author' => $u1, 'post_status' => 'private', 'post_date' => date( 'Y-m-d H:i:s', $now - 1 ) ) );
    405         $p2 = self::factory()->post->create( array( 'post_author' => $u1, 'post_date' => date( 'Y-m-d H:i:s', $now ) ) );
     416        $p1  = self::factory()->post->create(
     417            array(
     418                'post_author' => $u1,
     419                'post_status' => 'private',
     420                'post_date'   => date( 'Y-m-d H:i:s', $now - 1 ),
     421            )
     422        );
     423        $p2  = self::factory()->post->create(
     424            array(
     425                'post_author' => $u1,
     426                'post_date'   => date( 'Y-m-d H:i:s', $now ),
     427            )
     428        );
    406429
    407430        if ( ! isset( $GLOBALS['post'] ) ) {
     
    423446     */
    424447    public function test_get_adjacent_post_should_not_return_private_posts_belonging_to_other_users_if_the_current_user_cannot_read_private_posts() {
    425         $u1 = self::factory()->user->create( array( 'role' => 'author' ) );
    426         $u2 = self::factory()->user->create( array( 'role' => 'author' ) );
     448        $u1      = self::factory()->user->create( array( 'role' => 'author' ) );
     449        $u2      = self::factory()->user->create( array( 'role' => 'author' ) );
    427450        $old_uid = get_current_user_id();
    428451        wp_set_current_user( $u2 );
    429452
    430453        $now = time();
    431         $p1 = self::factory()->post->create( array( 'post_author' => $u1, 'post_date' => date( 'Y-m-d H:i:s', $now - 2 ) ) );
    432         $p2 = self::factory()->post->create( array( 'post_author' => $u1, 'post_status' => 'private', 'post_date' => date( 'Y-m-d H:i:s', $now - 1 ) ) );
    433         $p3 = self::factory()->post->create( array( 'post_author' => $u1, 'post_date' => date( 'Y-m-d H:i:s', $now ) ) );
     454        $p1  = self::factory()->post->create(
     455            array(
     456                'post_author' => $u1,
     457                'post_date'   => date( 'Y-m-d H:i:s', $now - 2 ),
     458            )
     459        );
     460        $p2  = self::factory()->post->create(
     461            array(
     462                'post_author' => $u1,
     463                'post_status' => 'private',
     464                'post_date'   => date( 'Y-m-d H:i:s', $now - 1 ),
     465            )
     466        );
     467        $p3  = self::factory()->post->create(
     468            array(
     469                'post_author' => $u1,
     470                'post_date'   => date( 'Y-m-d H:i:s', $now ),
     471            )
     472        );
    434473
    435474        if ( ! isset( $GLOBALS['post'] ) ) {
     
    467506
    468507        foreach ( $functions as $function ) {
    469             $this->assertEquals( call_user_func( $function, '/' ) . '../',
    470                 call_user_func( $function, '../' ) );
    471             $this->assertEquals( call_user_func( $function, '/' ) . 'something...here',
    472                 call_user_func( $function, 'something...here' ) );
     508            $this->assertEquals(
     509                call_user_func( $function, '/' ) . '../',
     510                call_user_func( $function, '../' )
     511            );
     512            $this->assertEquals(
     513                call_user_func( $function, '/' ) . 'something...here',
     514                call_user_func( $function, 'something...here' )
     515            );
    473516        }
    474517
    475518        // These functions accept a blog ID argument.
    476519        foreach ( array( 'get_site_url', 'get_home_url', 'get_admin_url' ) as $function ) {
    477             $this->assertEquals( call_user_func( $function, null, '/' ) . '../',
    478                 call_user_func( $function, null, '../' ) );
    479             $this->assertEquals( call_user_func( $function, null, '/' ) . 'something...here',
    480                 call_user_func( $function, null, 'something...here' ) );
     520            $this->assertEquals(
     521                call_user_func( $function, null, '/' ) . '../',
     522                call_user_func( $function, null, '../' )
     523            );
     524            $this->assertEquals(
     525                call_user_func( $function, null, '/' ) . 'something...here',
     526                call_user_func( $function, null, 'something...here' )
     527            );
    481528        }
    482529    }
Note: See TracChangeset for help on using the changeset viewer.