Skip to content

Commit

Permalink
Create ArticleExcerptViewTest.php
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed May 11, 2022
1 parent 09d8af6 commit 4a3ecaa
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions tests/Unit/Views/ArticleExcerptViewTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Tests\Unit\Views;

use Hyde\Framework\Hyde;
use Hyde\Framework\Models\MarkdownPost;
use Illuminate\Support\Facades\Blade;
use Tests\TestCase;

/**
* @see resources/views/components/article-excerpt.blade.php
*/
class ArticleExcerptViewTest extends TestCase
{
protected function renderTestView(MarkdownPost $post): string
{
return Blade::render(file_get_contents(
Hyde::vendorPath('resources/views/components/article-excerpt.blade.php')
), ['post' => $post]);
}

public function test_component_can_be_rendered()
{
$view = $this->renderTestView(new MarkdownPost([], ''));
$this->assertStringContainsString('https://schema.org/Article', $view);
}

public function test_component_renders_post_data()
{
$view = $this->renderTestView(new MarkdownPost([
'title' => 'Test Post',
'date' => '2022-01-01 12:00:00',
'author' => 'John Doe',
'description' => 'This is a test post.',
], '# Foo Bar', 'Foo Bar', 'foo-bar'));

$this->assertStringContainsString('Test Post', $view);
$this->assertStringContainsString('Jan 1st, 2022', $view);
$this->assertStringContainsString('John Doe', $view);
$this->assertStringContainsString('This is a test post.', $view);
$this->assertStringContainsString('Read post', $view);
}

public function test_component_renders_post_with_author_object()
{
$view = $this->renderTestView(new MarkdownPost([
'author' => [
'name' => 'John Doe',
'url' => '#',
],
], ''));

$this->assertStringContainsString('John Doe', $view);
}
}

0 comments on commit 4a3ecaa

Please sign in to comment.