Skip to content

Commit 1ec4ca5

Browse files
authored
Merge pull request #1588 from hydephp/improved-view-testing
Improved view testing
2 parents 0864ef1 + d190704 commit 1ec4ca5

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Hyde\Framework\Testing\Feature\Views;
6+
7+
use Hyde\Facades\Config;
8+
use Hyde\Testing\TestCase;
9+
use Hyde\Testing\TestsBladeViews;
10+
11+
class SidebarFooterTextViewTest extends TestCase
12+
{
13+
use TestsBladeViews;
14+
15+
public function testSidebarFooterTextViewWithDefaultConfig()
16+
{
17+
$view = $this->test(view('hyde::components.docs.sidebar-footer-text'));
18+
19+
$view->assertSeeHtml('<a href="index.html">Back to home page</a>');
20+
}
21+
22+
public function testSidebarFooterTextViewWhenConfigOptionIsTrue()
23+
{
24+
Config::set('docs.sidebar.footer', true);
25+
26+
$view = $this->test(view('hyde::components.docs.sidebar-footer-text'));
27+
28+
$view->assertSeeHtml('<a href="index.html">Back to home page</a>');
29+
}
30+
31+
public function testSidebarFooterTextViewWhenConfigOptionIsMarkdownString()
32+
{
33+
Config::set('docs.sidebar.footer', 'Your Markdown String Here');
34+
35+
$view = $this->test(view('hyde::components.docs.sidebar-footer-text'));
36+
37+
$view->assertSeeText('Your Markdown String Here');
38+
}
39+
40+
public function testSidebarFooterTextViewWhenConfigOptionIsFalse()
41+
{
42+
// This state is handled earlier in the component by the sidebar component so we don't need to test it here.
43+
44+
$this->assertTrue(true);
45+
}
46+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Hyde\Testing\Support;
6+
7+
class TestView extends \Illuminate\Testing\TestView
8+
{
9+
/**
10+
* Assert that the given HTML is contained within the view.
11+
*
12+
* @return $this
13+
*/
14+
public function assertSeeHtml(string $value): static
15+
{
16+
return $this->assertSee($value, false);
17+
}
18+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Hyde\Testing;
6+
7+
use Illuminate\View\View;
8+
use Hyde\Testing\Support\TestView;
9+
10+
/**
11+
* Provides a more fluent way to test Blade views.
12+
*/
13+
trait TestsBladeViews
14+
{
15+
/**
16+
* Test a Blade view.
17+
*/
18+
protected function test(string|View $view, $data = []): TestView
19+
{
20+
if ($view instanceof View) {
21+
return new TestView($view);
22+
}
23+
24+
return new TestView(view($view, $data));
25+
}
26+
}

0 commit comments

Comments
 (0)