Skip to content

Commit

Permalink
Merge pull request #18 from JasonMillward/wilder-wildcards
Browse files Browse the repository at this point in the history
Wilder wildcards + testing
  • Loading branch information
Mario Bašić authored Mar 20, 2017
2 parents 8fdc10c + 36988d7 commit 40432c9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Laravelista/Ekko/Ekko.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function isActiveRoute($routeName, $output = "active")
if (strpos($routeName, '*') !== false) {
// Quote all RE characters, then undo the quoted '*' characters to match any
// sequence of non-'.' characters.
$regex = '/^' . str_replace(preg_quote('*'), '[^.]*?', preg_quote($routeName, '/')) . '$/';
$regex = '/^' . str_replace(preg_quote('*'), '[^.]*?', preg_quote($routeName, '/')) . '/';
if (preg_match($regex, $this->route->currentRouteName())) {
return $output;
}
Expand Down
17 changes: 17 additions & 0 deletions tests/EkkoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,23 @@ public function it_detects_active_routes_by_name()
$this->assertEquals(null, $ekko->areActiveRoutes(['clients.*']));
$this->assertEquals(null, $ekko->areActiveRoutes(['clients.*'], 'hello'));
}

/** @test */
public function it_detects_deep_active_routes_by_name()
{
$router = m::mock(\Illuminate\Routing\Router::class);
$router->shouldReceive('currentRouteName')->times(4)->andReturn('frontend.users.show.stats');

$url = m::mock(\Illuminate\Routing\UrlGenerator::class);

$ekko = new Ekko($router, $url);

// Wildcard support
$this->assertEquals("active", $ekko->areActiveRoutes(['frontend.users.*']));
$this->assertEquals("hello", $ekko->areActiveRoutes(['frontend.users.*'], 'hello'));
$this->assertEquals(null, $ekko->areActiveRoutes(['clients.*']));
$this->assertEquals(null, $ekko->areActiveRoutes(['clients.*'], 'hello'));
}

/** @test */
public function it_detects_active_routes_by_url()
Expand Down

0 comments on commit 40432c9

Please sign in to comment.