Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main/php/web/Environment.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ public function tempDir() {
* @return io.Path
*/
public function path($path) {
return new Path($this->webroot, $path);
$p= $path instanceof Path ? $path : new Path($path);
return $p->isAbsolute() ? $p : new Path($this->webroot, $p);
}

/**
Expand Down
28 changes: 28 additions & 0 deletions src/test/php/web/unittest/EnvironmentTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use io\{File, Files, Path};
use lang\{ElementNotFoundException, Environment as System};
use test\{Assert, Expect, Test, Values};
use test\verify\Runtime;
use util\{Properties, PropertySource, RegisteredPropertySource};
use web\{Environment, Logging};

Expand Down Expand Up @@ -89,6 +90,33 @@ public function path() {
);
}

#[Test]
public function relative_path() {
$environment= new Environment('dev', '.', 'static', []);
Assert::equals(
new Path($environment->webroot(), 'src/main/handlebars'),
$environment->path('src/main/handlebars')
);
}

#[Test, Runtime(os: 'BSD|Darwin|Solaris|Linux')]
public function absolute_unix_path() {
$environment= new Environment('dev', '.', 'static', []);
Assert::equals(
new Path('/etc'),
$environment->path('/etc')
);
}

#[Test, Runtime(os: 'Windows')]
public function absolute_windows_path() {
$environment= new Environment('dev', '.', 'static', []);
Assert::equals(
new Path('C:\\Windows'),
$environment->path('C:\\Windows')
);
}

#[Test]
public function non_existant_variable() {
putenv('XP_TEST');
Expand Down
Loading