Skip to content

Commit a942a62

Browse files
authored
Merge pull request #229 from hydephp/add-more-view-tests
Add more view tests
2 parents c08a05a + 3eafe20 commit a942a62

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace Hyde\Framework\Testing\Unit\Views;
4+
5+
use Hyde\Testing\TestCase;
6+
7+
/**
8+
* @see resources/views/layouts/navigation.blade.php
9+
*/
10+
class NavigationMenuViewTest extends TestCase
11+
{
12+
protected function setUp(): void
13+
{
14+
parent::setUp();
15+
$this->mockRoute();
16+
$this->mockPage();
17+
}
18+
19+
protected function render(): string
20+
{
21+
return view('hyde::layouts.navigation')->render();
22+
}
23+
24+
public function test_component_can_be_rendered()
25+
{
26+
$this->assertStringContainsString('id="main-navigation"', $this->render());
27+
}
28+
29+
public function test_component_contains_dark_mode_button()
30+
{
31+
$this->assertStringContainsString('theme-toggle-button', $this->render());
32+
}
33+
34+
public function test_component_contains_navigation_menu_toggle_button()
35+
{
36+
$this->assertStringContainsString('id="navigation-toggle-button"', $this->render());
37+
}
38+
39+
public function test_component_contains_main_navigation_links()
40+
{
41+
$this->assertStringContainsString('id="main-navigation-links"', $this->render());
42+
}
43+
44+
public function test_component_contains_index_html_link()
45+
{
46+
$this->assertStringContainsString('href="index.html"', $this->render());
47+
}
48+
49+
public function test_component_not_contains_404_html_link()
50+
{
51+
$this->assertStringNotContainsString('href="404.html"', $this->render());
52+
}
53+
}

tests/TestCase.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,16 @@ protected function tearDown(): void
6060
parent::tearDown();
6161
}
6262

63-
protected function mockRoute()
63+
/** @internal */
64+
protected function mockRoute(?Route $route = null)
6465
{
65-
view()->share('currentRoute', (new Route(new MarkdownPage())));
66+
view()->share('currentRoute', $route ?? (new Route(new MarkdownPage())));
67+
}
68+
69+
/** @internal */
70+
protected function mockPage()
71+
{
72+
view()->share('page', new MarkdownPage());
73+
view()->share('currentPage', 'PHPUnit');
6674
}
6775
}

0 commit comments

Comments
 (0)