Make WordPress Core


Ignore:
Timestamp:
06/02/2022 02:58:38 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Tests: Add unit tests for path_join().

Props karlijnbk.
See #55897.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/functions.php

    r53129 r53457  
    128128                        $this->assertFalse( path_is_absolute( $path ), "path_is_absolute('$path') should return false" );
    129129                }
     130        }
     131
     132        /**
     133         * Tests path_join().
     134         *
     135         * @ticket 55897
     136         * @dataProvider path_join_data_provider
     137         */
     138        public function test_path_join( $base, $path, $expected ) {
     139                $this->assertSame( $expected, path_join( $base, $path ) );
     140        }
     141
     142        /**
     143         * Data provider for test_path_join().
     144         *
     145         * @return string[][]
     146         */
     147        public function path_join_data_provider() {
     148                return array(
     149                        // Absolute path.
     150                        'absolute path should return path' => array(
     151                                'base'     => 'base',
     152                                'path'     => '/path',
     153                                'expected' => '/path',
     154                        ),
     155                        // Non-absolute paths.
     156                        'join base and path'               => array(
     157                                'base'     => 'base',
     158                                'path'     => 'path',
     159                                'expected' => 'base/path',
     160                        ),
     161                        'strip trailing slashes in base'   => array(
     162                                'base'     => 'base///',
     163                                'path'     => 'path',
     164                                'expected' => 'base/path',
     165                        ),
     166                        'empty path'                       => array(
     167                                'base'     => 'base',
     168                                'path'     => '',
     169                                'expected' => 'base/',
     170                        ),
     171                        'empty base'                       => array(
     172                                'base'     => '',
     173                                'path'     => 'path',
     174                                'expected' => '/path',
     175                        ),
     176                        'empty path and base'              => array(
     177                                'base'     => '',
     178                                'path'     => '',
     179                                'expected' => '/',
     180                        ),
     181                );
    130182        }
    131183
Note: See TracChangeset for help on using the changeset viewer.