Skip to content

Commit

Permalink
Updating the helper
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanedev-maroc committed Apr 11, 2019
1 parent d2a9ca6 commit 993d76a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
11 changes: 7 additions & 4 deletions helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@ function is_active(array $routes)
/**
* Get the active class if the current route/path matches with the haystack.
*
* @param array $routes
* @param string|null $class
* @param string|array $routes
* @param string|null $class
* @param string|null $fallback
*
* @return \Arcanedev\LaravelActive\Contracts\Active|string|null
*/
function active(array $routes = [], $class = null)
function active($routes = [], $class = null, $fallback = null)
{
$active = app(Arcanedev\LaravelActive\Contracts\Active::class);

return empty($routes) ? $active : $active->active($routes, $class);
return empty($routes)
? $active
: $active->active($routes, $class, $fallback);
}
}
32 changes: 32 additions & 0 deletions tests/HelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ public function it_can_check_if_current_request_is_active()
static::assertFalse(active()->isRoute(['foo']));
}

/** @test */
public function it_can_check_if_current_request_is_active_with_string_value()
{
$this->get('foo');

static::assertTrue(active()->isActive('foo'));
static::assertTrue(active()->isPath('foo'));
static::assertFalse(active()->isRoute('foo'));
}

/** @test */
public function it_can_check_if_current_route_is_active()
{
Expand Down Expand Up @@ -134,4 +144,26 @@ public function it_must_return_false_when_the_given_route_or_path_not_active()
static::assertFalse(active()->isRoute(['404']));
static::assertFalse(active()->isPath(['404']));
}

/** @test */
public function it_can_fallback_with_custom_inactive_class()
{
static::assertSame('inactive', active('blog', 'active', 'inactive'));
static::assertSame('inactive', active()->route('blog', 'active', 'inactive'));
static::assertSame('inactive', active()->path('blog', 'active', 'inactive'));
}

/** @test */
public function it_can_fallback_with_custom_inactive_class_from_config_file()
{
static::assertNull(active('blog'));
static::assertNull(active()->route('blog'));
static::assertNull(active()->path('blog'));

$this->app['config']->set('active.fallback-class', 'inactive');

static::assertSame('inactive', active('blog'));
static::assertSame('inactive', active()->route('blog'));
static::assertSame('inactive', active()->path('blog'));
}
}

0 comments on commit 993d76a

Please sign in to comment.