|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Hyde\Framework\Testing\Unit; |
|
4
|
|
|
|
|
5
|
|
|
use Hyde\Framework\Concerns\HasAuthor; |
|
6
|
|
|
use Hyde\Framework\Models\Author; |
|
7
|
|
|
use Hyde\Framework\Models\FrontMatter; |
|
8
|
|
|
use Hyde\Testing\TestCase; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class HasAuthorTest. |
|
12
|
|
|
* |
|
13
|
|
|
* @covers \Hyde\Framework\Concerns\HasAuthor |
|
14
|
|
|
*/ |
|
15
|
|
|
class HasAuthorTest extends TestCase |
|
16
|
|
|
{ |
|
17
|
|
|
use HasAuthor; |
|
18
|
|
|
|
|
19
|
|
|
protected FrontMatter $matter; |
|
20
|
|
|
|
|
21
|
|
|
protected function matter(...$args) |
|
22
|
|
|
{ |
|
23
|
|
|
return $this->matter->get(...$args); |
|
|
|
|
|
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function test_it_can_create_a_new_author_instance_from_username_string() |
|
27
|
|
|
{ |
|
28
|
|
|
$this->matter = FrontMatter::fromArray([ |
|
29
|
|
|
'author' => 'John Doe', |
|
30
|
|
|
]); |
|
31
|
|
|
|
|
32
|
|
|
$this->constructAuthor(); |
|
33
|
|
|
$this->assertInstanceOf(Author::class, $this->author); |
|
34
|
|
|
$this->assertEquals('John Doe', $this->author->username); |
|
35
|
|
|
$this->assertNull($this->author->name); |
|
36
|
|
|
$this->assertNull($this->author->website); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function test_it_can_create_a_new_author_instance_from_user_array() |
|
40
|
|
|
{ |
|
41
|
|
|
$this->matter = FrontMatter::fromArray(['author' => [ |
|
42
|
|
|
'username' => 'john_doe', |
|
43
|
|
|
'name' => 'John Doe', |
|
44
|
|
|
'website' => 'https://example.com', |
|
45
|
|
|
]]); |
|
46
|
|
|
$this->constructAuthor(); |
|
47
|
|
|
$this->assertInstanceOf(Author::class, $this->author); |
|
48
|
|
|
$this->assertEquals('john_doe', $this->author->username); |
|
49
|
|
|
$this->assertEquals('John Doe', $this->author->name); |
|
50
|
|
|
$this->assertEquals('https://example.com', $this->author->website); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|