2019-11-12 21:49:43 +01:00
|
|
|
<?php
|
2019-11-12 22:04:39 +01:00
|
|
|
|
2019-11-12 21:49:43 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Engelsystem\Test\Unit\Models;
|
|
|
|
|
|
|
|
use Engelsystem\Models\News;
|
|
|
|
use Engelsystem\Models\NewsComment;
|
|
|
|
use Engelsystem\Models\User\User;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class provides tests for the NewsComments model.
|
|
|
|
*/
|
2020-05-11 19:57:25 +02:00
|
|
|
class NewsCommentsTest extends ModelTest
|
2019-11-12 21:49:43 +01:00
|
|
|
{
|
2022-12-15 19:50:56 +01:00
|
|
|
private User $user;
|
2019-11-12 21:49:43 +01:00
|
|
|
|
2022-12-15 19:50:56 +01:00
|
|
|
private News $news;
|
2019-11-12 21:49:43 +01:00
|
|
|
|
|
|
|
/** @var array */
|
2022-12-15 19:50:56 +01:00
|
|
|
private array $newsCommentData;
|
2019-11-12 21:49:43 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets up some test objects and test data.
|
|
|
|
*/
|
|
|
|
protected function setUp(): void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
2021-06-29 00:27:57 +02:00
|
|
|
$this->user = User::factory()->create();
|
2019-11-12 21:49:43 +01:00
|
|
|
|
|
|
|
$this->news = News::create([
|
|
|
|
'title' => 'test title',
|
|
|
|
'text' => 'test text',
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->newsCommentData = [
|
|
|
|
'news_id' => $this->news->id,
|
|
|
|
'text' => 'test comment',
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests that a NewsComment can be created and loaded.
|
|
|
|
*
|
2020-01-02 15:08:08 +01:00
|
|
|
* @covers \Engelsystem\Models\NewsComment
|
2019-11-12 21:49:43 +01:00
|
|
|
*/
|
|
|
|
public function testCreate(): void
|
|
|
|
{
|
|
|
|
$createdNewsComment = NewsComment::create($this->newsCommentData);
|
|
|
|
|
|
|
|
$newsComment = NewsComment::find($createdNewsComment->id);
|
|
|
|
$this->assertInstanceOf(NewsComment::class, $newsComment);
|
|
|
|
$this->assertEquals($this->newsCommentData['news_id'], $newsComment->news_id);
|
|
|
|
$this->assertSame($this->newsCommentData['text'], $newsComment->text);
|
|
|
|
$this->assertEquals($this->newsCommentData['user_id'], $newsComment->user_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests that accessing the User of a NewsComment works.
|
|
|
|
*
|
2020-01-02 15:08:08 +01:00
|
|
|
* @covers \Engelsystem\Models\NewsComment::user
|
2019-11-12 21:49:43 +01:00
|
|
|
*/
|
|
|
|
public function testUser(): void
|
|
|
|
{
|
|
|
|
$newsComment = NewsComment::create($this->newsCommentData);
|
|
|
|
$this->assertInstanceOf(User::class, $newsComment->user);
|
|
|
|
$this->assertSame($this->user->id, $newsComment->user->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests that accessing the News of a NewsComment works.
|
|
|
|
*
|
2020-01-02 15:08:08 +01:00
|
|
|
* @covers \Engelsystem\Models\NewsComment::news
|
2019-11-12 21:49:43 +01:00
|
|
|
*/
|
|
|
|
public function testNews(): void
|
|
|
|
{
|
|
|
|
$newsComment = NewsComment::create($this->newsCommentData);
|
|
|
|
$this->assertInstanceOf(News::class, $newsComment->news);
|
|
|
|
$this->assertSame($this->news->id, $newsComment->news->id);
|
|
|
|
}
|
|
|
|
}
|