Skip to content

Commit

Permalink
Fix an issue resolving sites from simple name. Add tests to verify.
Browse files Browse the repository at this point in the history
  • Loading branch information
Keoghan committed Sep 20, 2018
1 parent 2d68970 commit 6772f57
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/Models/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ public static function nameFromPath($path)
{
$home = setting('home');

if (strpos($path, DIRECTORY_SEPARATOR) === false) {
return $path;
}

if (strpos($path, $home) !== 0) {
return;
}
Expand Down
21 changes: 21 additions & 0 deletions tests/Unit/SiteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ public function it_will_return_null_if_the_path_is_outside_the_home_dir()
$this->assertNull(Site::nameFromPath('/tmp/sample'));
}

/** @test */
public function it_will_resolve_a_simple_site_name()
{
Setting::updateOrCreate('home', '/Users/keoghan/Code');

$this->assertEquals('sample', Site::nameFromPath('sample'));
}

/** @test */
public function it_will_resolve_a_site_name_from_the_current_working_directory()
{
Expand All @@ -127,6 +135,19 @@ public function it_will_resolve_a_site_name_from_the_current_working_directory()
$this->assertEquals('sample', Site::nameFromPath('/Users/keoghan/Code/sample'));
}

/** @test */
public function it_will_resolve_a_site_from_a_simple_name()
{
Setting::updateOrCreate('home', '/Users/keoghan/Code');

$site = factory(Site::class)->create(['name' => 'sample']);

$this->assertEquals(
$site->getKey(),
Site::resolveFromPathOrCurrentWorkingDirectory('sample')->getKey()
);
}

/** @test */
public function it_will_resolve_a_site_from_a_path()
{
Expand Down

0 comments on commit 6772f57

Please sign in to comment.