Skip to content

Commit 153a886

Browse files
Tests: Add unit tests for path_join().
Props karlijnbk. See #55897. git-svn-id: https://develop.svn.wordpress.org/trunk@53457 602fd350-edb4-49c9-b593-d223f7449a82
1 parent b654298 commit 153a886

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

tests/phpunit/tests/functions.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,58 @@ public function test_path_is_not_absolute() {
129129
}
130130
}
131131

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+
);
182+
}
183+
132184
/**
133185
* @ticket 33265
134186
* @ticket 35996

0 commit comments

Comments
 (0)