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;
|
|
|
|
use Engelsystem\Test\Unit\HasDatabase;
|
|
|
|
use Engelsystem\Test\Unit\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class provides tests for the News model.
|
|
|
|
*/
|
|
|
|
class NewsTest extends TestCase
|
|
|
|
{
|
|
|
|
use HasDatabase;
|
|
|
|
|
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();
|
|
|
|
$this->initDatabase();
|
|
|
|
|
2019-11-10 21:30:26 +01:00
|
|
|
$this->user = (new User())->create([
|
2019-10-31 20:02:34 +01:00
|
|
|
'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
|
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests that creating a News item with all fill values works.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testCreate(): void
|
|
|
|
{
|
2019-11-10 21:30:26 +01:00
|
|
|
$news = (new News())->create(
|
|
|
|
$this->newsData + ['is_meeting' => 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);
|
|
|
|
}
|
|
|
|
}
|