You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
1.9 KiB
PHTML
81 lines
1.9 KiB
PHTML
5 years ago
|
<?php
|
||
5 years ago
|
|
||
5 years ago
|
declare(strict_types=1);
|
||
|
|
||
5 years ago
|
namespace Engelsystem\Test\Unit\Models;
|
||
|
|
||
|
use Engelsystem\Models\News;
|
||
5 years ago
|
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;
|
||
|
|
||
5 years ago
|
/** @var array */
|
||
5 years ago
|
private $newsData;
|
||
|
|
||
5 years ago
|
/** @var User */
|
||
5 years ago
|
private $user;
|
||
|
|
||
|
/**
|
||
|
* @return void
|
||
|
*/
|
||
|
protected function setUp(): void
|
||
|
{
|
||
|
parent::setUp();
|
||
|
$this->initDatabase();
|
||
|
|
||
5 years ago
|
$this->user = (new User())->create([
|
||
5 years ago
|
'name' => 'lorem',
|
||
|
'password' => '',
|
||
|
'email' => 'foo@bar.batz',
|
||
|
'api_key' => '',
|
||
|
]);
|
||
|
|
||
|
$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
|
||
|
{
|
||
5 years ago
|
$news = (new News())->create($this->newsData);
|
||
|
$news = $news->find($news->id);
|
||
5 years ago
|
|
||
|
$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
|
||
|
{
|
||
5 years ago
|
$news = (new News())->create(
|
||
|
$this->newsData + ['is_meeting' => true]
|
||
5 years ago
|
);
|
||
5 years ago
|
$news = $news->find($news->id);
|
||
5 years ago
|
|
||
|
$this->assertSame(1, $news->id);
|
||
|
$this->assertSame($this->newsData['title'], $news->title);
|
||
|
$this->assertSame($this->newsData['text'], $news->text);
|
||
|
$this->assertTrue($news->is_meeting);
|
||
|
}
|
||
|
}
|