2019-10-31 20:02:34 +01:00
|
|
|
<?php
|
2019-11-10 21:30:26 +01:00
|
|
|
|
2019-10-31 20:02:34 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2019-11-10 21:30:26 +01:00
|
|
|
namespace Engelsystem\Test\Unit\Models;
|
|
|
|
|
|
|
|
use Engelsystem\Models\News;
|
2019-10-31 20:02:34 +01:00
|
|
|
use Engelsystem\Models\User\User;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class provides tests for the News model.
|
|
|
|
*/
|
2020-05-11 19:57:25 +02:00
|
|
|
class NewsTest extends ModelTest
|
2019-10-31 20:02:34 +01:00
|
|
|
{
|
2019-11-10 21:30:26 +01:00
|
|
|
/** @var array */
|
2019-10-31 20:02:34 +01:00
|
|
|
private $newsData;
|
|
|
|
|
2019-11-10 21:30:26 +01:00
|
|
|
/** @var User */
|
2019-10-31 20:02:34 +01:00
|
|
|
private $user;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function setUp(): void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
2021-06-29 00:27:57 +02:00
|
|
|
$this->user = User::factory()->create();
|
2019-10-31 20:02:34 +01:00
|
|
|
$this->newsData = [
|
|
|
|
'title' => 'test title',
|
|
|
|
'text' => 'test text',
|
|
|
|
'user_id' => $this->user->id
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests that creating a News item with default values works.
|
|
|
|
*
|
2020-01-02 15:08:08 +01:00
|
|
|
* @covers \Engelsystem\Models\News
|
2019-10-31 20:02:34 +01:00
|
|
|
*/
|
|
|
|
public function testCreateDefault(): void
|
|
|
|
{
|
2019-11-10 21:30:26 +01:00
|
|
|
$news = (new News())->create($this->newsData);
|
|
|
|
$news = $news->find($news->id);
|
2019-10-31 20:02:34 +01:00
|
|
|
|
|
|
|
$this->assertSame(1, $news->id);
|
|
|
|
$this->assertSame($this->newsData['title'], $news->title);
|
|
|
|
$this->assertSame($this->newsData['text'], $news->text);
|
|
|
|
$this->assertFalse($news->is_meeting);
|
|
|
|
}
|
|
|
|
|
2020-01-02 15:08:08 +01:00
|
|
|
/**
|
|
|
|
* Tests that accessing the NewsComments of a News works.
|
|
|
|
*
|
|
|
|
* @covers \Engelsystem\Models\News::comments
|
|
|
|
*/
|
|
|
|
public function testNewsComments(): void
|
|
|
|
{
|
|
|
|
$news = (new News())->create($this->newsData);
|
|
|
|
$comment = $news->comments()->create(['text' => 'test comment', 'user_id' => $this->user->id]);
|
|
|
|
|
|
|
|
$comments = $news->comments;
|
|
|
|
$this->assertCount(1, $comments);
|
|
|
|
$this->assertEquals($comment->toArray(), $news->comments->first()->toArray());
|
|
|
|
}
|
|
|
|
|
2019-10-31 20:02:34 +01:00
|
|
|
/**
|
|
|
|
* Tests that creating a News item with all fill values works.
|
|
|
|
*
|
2020-01-02 15:08:08 +01:00
|
|
|
* @covers \Engelsystem\Models\News
|
2019-10-31 20:02:34 +01:00
|
|
|
*/
|
|
|
|
public function testCreate(): void
|
|
|
|
{
|
2019-11-10 21:30:26 +01:00
|
|
|
$news = (new News())->create(
|
2020-12-27 02:51:05 +01:00
|
|
|
$this->newsData + ['is_meeting' => true, 'is_pinned' => true]
|
2019-10-31 20:02:34 +01:00
|
|
|
);
|
2019-11-10 21:30:26 +01:00
|
|
|
$news = $news->find($news->id);
|
2019-10-31 20:02:34 +01:00
|
|
|
|
|
|
|
$this->assertSame(1, $news->id);
|
|
|
|
$this->assertSame($this->newsData['title'], $news->title);
|
|
|
|
$this->assertSame($this->newsData['text'], $news->text);
|
|
|
|
$this->assertTrue($news->is_meeting);
|
2020-12-27 02:51:05 +01:00
|
|
|
$this->assertTrue($news->is_pinned);
|
2019-10-31 20:02:34 +01:00
|
|
|
}
|
|
|
|
}
|