Skip to content

Commit

Permalink
breadcrumb tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Jan 25, 2024
1 parent 21eb496 commit f14eb70
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Breadcrumbs/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ class Registry
*/
public function patterns(array $patterns): void
{
$this->patterns = array_merge($this->patterns, $patterns);
foreach ($patterns as $pattern => $label) {
$this->pattern($pattern, $label);
}
}

/**
Expand Down
46 changes: 46 additions & 0 deletions tests/Breadcrumbs/RegistryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Cone\Root\Tests\Breadcrumbs;

use Cone\Root\Breadcrumbs\Registry;
use Cone\Root\Tests\TestCase;
use Illuminate\Http\Request;
use Illuminate\Routing\Route;

class RegistryTest extends TestCase
{
protected Registry $registry;

public function setUp(): void
{
parent::setUp();

$this->registry = new Registry();
}

public function test_a_breadcrumb_registry_can_register_patterns(): void
{
$this->registry->patterns([
'/' => 'Dashboard',
'/posts' => 'Posts',
'/posts/{post}' => function () {
return 'Post Title';
},
'/settings' => 'Settings',
]);

$request = Request::create('/posts/1');

$route = new Route('GET', '/posts/{post}', fn () => null);
$route->bind($request);
$route->setParameter('post', 1);

$request->setRouteResolver(fn () => $route);

$this->assertSame([
['uri' => '/', 'label' => 'Dashboard'],
['uri' => '/posts', 'label' => 'Posts'],
['uri' => '/posts/1', 'label' => 'Post Title'],
], $this->registry->resolve($request));
}
}

0 comments on commit f14eb70

Please sign in to comment.