summaryrefslogtreecommitdiff
path: root/tests/Unit/Models/News/NewsTest.php
blob: 7309c0b0ddbe73755a55f2ab69654eb95277ce05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
declare(strict_types=1);

use Engelsystem\Models\News\News;
use Engelsystem\Models\User\User;
use Engelsystem\Test\Unit\HasDatabase;
use Engelsystem\Test\Unit\TestCase;

/**
 * This class provides tests for the News model.
 */
class NewsTest extends TestCase
{
    use HasDatabase;

    /**
     * @var array
     */
    private $newsData;

    /**
     * @var User
     */
    private $user;

    /**
     * @return void
     */
    protected function setUp(): void
    {
        parent::setUp();
        $this->initDatabase();

        $this->user = User::make([
            'name'     => 'lorem',
            'password' => '',
            'email'    => 'foo@bar.batz',
            'api_key'  => '',
        ]);
        $this->user->save();

        $this->newsData = [
            'title'   => 'test title',
            'text'    => 'test text',
            'user_id' => $this->user->id
        ];
    }

    /**
     * Tests that creating a News item with default values works.
     *
     * @return void
     */
    public function testCreateDefault(): void
    {
        $news = News::create($this->newsData);

        $this->assertSame(1, $news->id);
        $this->assertSame($this->newsData['title'], $news->title);
        $this->assertSame($this->newsData['text'], $news->text);
        $this->assertFalse($news->is_meeting);
    }

    /**
     * Tests that creating a News item with all fill values works.
     *
     * @return void
     */
    public function testCreate(): void
    {
        $news = News::create(
            $this->newsData + ['is_meeting' => true,]
        );

        $this->assertSame(1, $news->id);
        $this->assertSame($this->newsData['title'], $news->title);
        $this->assertSame($this->newsData['text'], $news->text);
        $this->assertTrue($news->is_meeting);
    }
}