diff --git a/tests/Feature/Views/SidebarBrandViewTest.php b/tests/Feature/Views/SidebarBrandViewTest.php index 10b840bf..03670822 100644 --- a/tests/Feature/Views/SidebarBrandViewTest.php +++ b/tests/Feature/Views/SidebarBrandViewTest.php @@ -16,7 +16,7 @@ class SidebarBrandViewTest extends TestCase public function testSidebarBrandView() { - $view = $this->test(view('hyde::components.docs.sidebar-brand')); + $view = $this->view(view('hyde::components.docs.sidebar-brand')); $view->assertSee('HydePHP Docs'); $view->assertSee('theme-toggle-button'); @@ -27,7 +27,7 @@ public function testSidebarBrandViewWithHomeRoute() { Hyde::routes()->addRoute((new DocumentationPage('index'))->getRoute()); - $view = $this->test(view('hyde::components.docs.sidebar-brand')); + $view = $this->view(view('hyde::components.docs.sidebar-brand')); $view->assertSee('HydePHP Docs'); $view->assertSee('theme-toggle-button'); @@ -38,7 +38,7 @@ public function testSidebarBrandViewWithDefaultHeaderText() { config(['docs.sidebar' => []]); - $view = $this->test(view('hyde::components.docs.sidebar-brand')); + $view = $this->view(view('hyde::components.docs.sidebar-brand')); $view->assertSee('Documentation'); $view->assertDontSee('HydePHP Docs'); @@ -50,7 +50,7 @@ public function testSidebarBrandViewWithDefaultHeaderTextAndHomeRoute() config(['docs.sidebar' => []]); - $view = $this->test(view('hyde::components.docs.sidebar-brand')); + $view = $this->view(view('hyde::components.docs.sidebar-brand')); $view->assertSee('Documentation'); $view->assertSeeHtml('Documentation', true); @@ -63,7 +63,7 @@ public function testSidebarBrandViewWithoutDarkmodeFeature() $mock->shouldReceive('hasFeature')->with('darkmode')->andReturn(false); HydeKernel::setInstance($mock); - $view = $this->test(view('hyde::components.docs.sidebar-brand')); + $view = $this->view(view('hyde::components.docs.sidebar-brand')); $view->assertSee('HydePHP Docs'); $view->assertDontSee('theme-toggle-button'); diff --git a/tests/Feature/Views/SidebarFooterTextViewTest.php b/tests/Feature/Views/SidebarFooterTextViewTest.php index e4d5c21e..0b27fa6f 100644 --- a/tests/Feature/Views/SidebarFooterTextViewTest.php +++ b/tests/Feature/Views/SidebarFooterTextViewTest.php @@ -14,7 +14,7 @@ class SidebarFooterTextViewTest extends TestCase public function testSidebarFooterTextViewWithDefaultConfig() { - $view = $this->test(view('hyde::components.docs.sidebar-footer-text')); + $view = $this->view(view('hyde::components.docs.sidebar-footer-text')); $view->assertSeeHtml('Back to home page'); } @@ -23,7 +23,7 @@ public function testSidebarFooterTextViewWhenConfigOptionIsTrue() { Config::set('docs.sidebar.footer', true); - $view = $this->test(view('hyde::components.docs.sidebar-footer-text')); + $view = $this->view(view('hyde::components.docs.sidebar-footer-text')); $view->assertSeeHtml('Back to home page'); } @@ -32,7 +32,7 @@ public function testSidebarFooterTextViewWhenConfigOptionIsMarkdownString() { Config::set('docs.sidebar.footer', 'Your Markdown String Here'); - $view = $this->test(view('hyde::components.docs.sidebar-footer-text')); + $view = $this->view(view('hyde::components.docs.sidebar-footer-text')); $view->assertSeeText('Your Markdown String Here'); } diff --git a/tests/Unit/HtmlTestingSupportMetaTest.php b/tests/Unit/HtmlTestingSupportMetaTest.php index 4d7a92a5..5b6ec6f4 100644 --- a/tests/Unit/HtmlTestingSupportMetaTest.php +++ b/tests/Unit/HtmlTestingSupportMetaTest.php @@ -1,5 +1,7 @@ assertSame([], $this->html('
Foo
')->getRootElement()->attributes); - /** @noinspection HtmlUnknownAttribute */ $this->assertSame([ 'name' => 'test', 'foo' => 'bar', @@ -429,21 +431,79 @@ public function testToArrayWithChildren() public function testToArrayWithAttributes() { - /** @noinspection HtmlUnknownAttribute */ $this->assertSame( ['id' => 'id', 'tag' => 'div', 'text' => 'Bar', 'classes' => ['class'], 'attributes' => ['name' => 'name']], $this->html('
Bar
')->getRootElement()->toArray() ); } + public function testElementAssertHasId() + { + $this->html('
Foo
')->getRootElement()->assertHasId('foo'); + } + + public function testElementAssertDoesNotHaveId() + { + $this->html('
Foo
')->getRootElement()->assertDoesNotHaveId('foo'); + } + public function testElementAssertHasClass() { - $this->html('
Foo
')->getRootElement()->hasClass('foo'); + $this->html('
Foo
')->getRootElement()->assertHasClass('foo'); } public function testElementAssertDoesNotHaveClass() { - $this->html('
Foo
')->getRootElement()->doesNotHaveClass('bar'); + $this->html('
Foo
')->getRootElement()->assertDoesNotHaveClass('bar'); + } + + public function testElementAssertHasAttribute() + { + $this->html('
Foo
')->getRootElement()->assertHasAttribute('name'); + } + + public function testElementAssertDoesNotHaveAttribute() + { + $this->html('
Foo
')->getRootElement()->assertDoesNotHaveAttribute('href'); + } + + public function testElementAssertHasAttributeWithValue() + { + $this->html('
Foo
')->getRootElement()->assertHasAttribute('name', 'foo'); + } + + public function testElementAssertHasAttributeWithWrongValue() + { + try { + $this->html('
Foo
')->getRootElement()->assertHasAttribute('name', 'bar'); + } catch (ExpectationFailedException $exception) { + $this->assertSame("The attribute 'name' did not have the expected value.\nFailed asserting that two strings are identical.", $exception->getMessage()); + } + } + + public function testElementAssertHasAttributeForwardsIdAssertions() + { + $this->html('
Foo
')->getRootElement()->assertHasAttribute('id', 'foo'); + } + + public function testElementAssertHasAttributeForwardsClassAssertions() + { + $this->html('
Foo
')->getRootElement()->assertHasAttribute('class', 'foo'); + } + + public function testAssertionCallsOnDocumentAreForwardedToRootElement() + { + $this->assertInstanceOf(TestableHtmlElement::class, + $this->html('
Foo
') + ->assertSee('Foo') + ->assertHasId('foo') + ->assertDoesNotHaveId('bar') + ->assertHasClass('bar') + ->assertDoesNotHaveClass('baz') + ->assertHasAttribute('class', 'bar') + ->assertDoesNotHaveAttribute('href') + ->assertSee('Foo') + ); } protected function exampleElement(): TestableHtmlElement