Make WordPress Core


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

    r38762 r42343  
    99        parent::setUp();
    1010
    11         $file = tempnam( '/tmp', 'foo') ;
     11        $file      = tempnam( '/tmp', 'foo' );
    1212        $this->dir = dirname( $file );
    1313        unlink( $file );
     
    2222    function test_get_file_data() {
    2323        $theme_headers = array(
    24             'Name' => 'Theme Name',
    25             'ThemeURI' => 'Theme URI',
     24            'Name'        => 'Theme Name',
     25            'ThemeURI'    => 'Theme URI',
    2626            'Description' => 'Description',
    27             'Version' => 'Version',
    28             'Author' => 'Author',
    29             'AuthorURI' => 'Author URI',
     27            'Version'     => 'Version',
     28            'Author'      => 'Author',
     29            'AuthorURI'   => 'Author URI',
    3030        );
    3131
     
    3333
    3434        $expected = array(
    35             'Name' => 'WordPress Default',
    36             'ThemeURI' => 'http://wordpress.org/',
     35            'Name'        => 'WordPress Default',
     36            'ThemeURI'    => 'http://wordpress.org/',
    3737            'Description' => 'The default WordPress theme based on the famous <a href="http://binarybonsai.com/kubrick/">Kubrick</a>.',
    38             'Version' => '1.6',
    39             'Author' => 'Michael Heilemann',
    40             'AuthorURI' => 'http://binarybonsai.com/',
     38            'Version'     => '1.6',
     39            'Author'      => 'Michael Heilemann',
     40            'AuthorURI'   => 'http://binarybonsai.com/',
    4141        );
    4242
    43         foreach ( $actual as $header => $value )
     43        foreach ( $actual as $header => $value ) {
    4444            $this->assertEquals( $expected[ $header ], $value, $header );
     45        }
    4546    }
    4647
     
    5051     */
    5152    function test_get_file_data_cr_line_endings() {
    52         $headers = array( 'SomeHeader' => 'Some Header', 'Description' => 'Description', 'Author' => 'Author' );
    53         $actual = get_file_data( DIR_TESTDATA . '/formatting/cr-line-endings-file-header.php', $headers );
     53        $headers  = array(
     54            'SomeHeader'  => 'Some Header',
     55            'Description' => 'Description',
     56            'Author'      => 'Author',
     57        );
     58        $actual   = get_file_data( DIR_TESTDATA . '/formatting/cr-line-endings-file-header.php', $headers );
    5459        $expected = array(
    55             'SomeHeader' => 'Some header value!',
     60            'SomeHeader'  => 'Some header value!',
    5661            'Description' => 'This file is using CR line endings for a testcase.',
    57             'Author' => 'A Very Old Mac',
     62            'Author'      => 'A Very Old Mac',
    5863        );
    5964
    60         foreach ( $actual as $header => $value )
     65        foreach ( $actual as $header => $value ) {
    6166            $this->assertEquals( $expected[ $header ], $value, $header );
     67        }
    6268    }
    6369
    64     function is_unique_writable_file($path, $filename) {
     70    function is_unique_writable_file( $path, $filename ) {
    6571        $fullpath = $path . DIRECTORY_SEPARATOR . $filename;
    6672
    6773        $fp = fopen( $fullpath, 'x' );
    6874        // file already exists?
    69         if (!$fp)
     75        if ( ! $fp ) {
    7076            return false;
     77        }
    7178
    7279        // write some random contents
    7380        $c = rand_str();
    74         fwrite($fp, $c);
    75         fclose($fp);
     81        fwrite( $fp, $c );
     82        fclose( $fp );
    7683
    77         if ( file_get_contents($fullpath) === $c )
     84        if ( file_get_contents( $fullpath ) === $c ) {
    7885            $result = true;
    79         else
     86        } else {
    8087            $result = false;
     88        }
    8189
    8290        return $result;
     
    8795        $filename = wp_unique_filename( $this->dir, __FUNCTION__ . '.txt' );
    8896
    89         $this->assertTrue( $this->is_unique_writable_file($this->dir, $filename) );
     97        $this->assertTrue( $this->is_unique_writable_file( $this->dir, $filename ) );
    9098
    91         unlink($this->dir . DIRECTORY_SEPARATOR . $filename);
     99        unlink( $this->dir . DIRECTORY_SEPARATOR . $filename );
    92100    }
    93101
     
    97105
    98106        $filename1 = wp_unique_filename( $this->dir, $name . '.txt' );
    99         $this->assertTrue( $this->is_unique_writable_file($this->dir, $filename1) );
     107        $this->assertTrue( $this->is_unique_writable_file( $this->dir, $filename1 ) );
    100108        $filename2 = wp_unique_filename( $this->dir, $name . '.txt' );
    101         $this->assertTrue( $this->is_unique_writable_file($this->dir, $filename2) );
     109        $this->assertTrue( $this->is_unique_writable_file( $this->dir, $filename2 ) );
    102110
    103111        // the two should be different
    104112        $this->assertNotEquals( $filename1, $filename2 );
    105113
    106         unlink($this->dir . DIRECTORY_SEPARATOR . $filename1);
    107         unlink($this->dir . DIRECTORY_SEPARATOR . $filename2);
     114        unlink( $this->dir . DIRECTORY_SEPARATOR . $filename1 );
     115        unlink( $this->dir . DIRECTORY_SEPARATOR . $filename2 );
    108116    }
    109117
    110118    function test_unique_filename_is_sanitized() {
    111         $name = __FUNCTION__;
    112         $filename = wp_unique_filename( $this->dir, $name . $this->badchars .  '.txt' );
     119        $name     = __FUNCTION__;
     120        $filename = wp_unique_filename( $this->dir, $name . $this->badchars . '.txt' );
    113121
    114122        // make sure the bad characters were all stripped out
    115123        $this->assertEquals( $name . '.txt', $filename );
    116124
    117         $this->assertTrue( $this->is_unique_writable_file($this->dir, $filename) );
     125        $this->assertTrue( $this->is_unique_writable_file( $this->dir, $filename ) );
    118126
    119         unlink($this->dir . DIRECTORY_SEPARATOR . $filename);
     127        unlink( $this->dir . DIRECTORY_SEPARATOR . $filename );
    120128    }
    121129
     
    123131        $name = __FUNCTION__;
    124132        // "foo/foo.txt"
    125         $filename = wp_unique_filename( $this->dir, $name . '/' . $name .  '.txt' );
     133        $filename = wp_unique_filename( $this->dir, $name . '/' . $name . '.txt' );
    126134
    127135        // the slash should be removed, i.e. "foofoo.txt"
    128136        $this->assertEquals( $name . $name . '.txt', $filename );
    129137
    130         $this->assertTrue( $this->is_unique_writable_file($this->dir, $filename) );
     138        $this->assertTrue( $this->is_unique_writable_file( $this->dir, $filename ) );
    131139
    132         unlink($this->dir . DIRECTORY_SEPARATOR . $filename);
     140        unlink( $this->dir . DIRECTORY_SEPARATOR . $filename );
    133141    }
    134142
    135143    function test_unique_filename_multiple_ext() {
    136         $name = __FUNCTION__;
     144        $name     = __FUNCTION__;
    137145        $filename = wp_unique_filename( $this->dir, $name . '.php.txt' );
    138146
     
    140148        $this->assertEquals( $name . '.php_.txt', $filename );
    141149
    142         $this->assertTrue( $this->is_unique_writable_file($this->dir, $filename) );
     150        $this->assertTrue( $this->is_unique_writable_file( $this->dir, $filename ) );
    143151
    144         unlink($this->dir . DIRECTORY_SEPARATOR . $filename);
     152        unlink( $this->dir . DIRECTORY_SEPARATOR . $filename );
    145153    }
    146154
    147155    function test_unique_filename_no_ext() {
    148         $name = __FUNCTION__;
     156        $name     = __FUNCTION__;
    149157        $filename = wp_unique_filename( $this->dir, $name );
    150158
    151159        $this->assertEquals( $name, $filename );
    152160
    153         $this->assertTrue( $this->is_unique_writable_file($this->dir, $filename) );
     161        $this->assertTrue( $this->is_unique_writable_file( $this->dir, $filename ) );
    154162
    155         unlink($this->dir . DIRECTORY_SEPARATOR . $filename);
     163        unlink( $this->dir . DIRECTORY_SEPARATOR . $filename );
    156164    }
    157165
Note: See TracChangeset for help on using the changeset viewer.