2018-10-06 14:15:54 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Engelsystem\Test\Unit\Models;
|
|
|
|
|
2019-04-24 10:45:00 +02:00
|
|
|
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
|
2018-10-06 14:15:54 +02:00
|
|
|
use Engelsystem\Models\User\Contact;
|
|
|
|
use Engelsystem\Models\User\HasUserModel;
|
|
|
|
use Engelsystem\Models\User\PersonalData;
|
|
|
|
use Engelsystem\Models\User\Settings;
|
|
|
|
use Engelsystem\Models\User\State;
|
|
|
|
use Engelsystem\Models\User\User;
|
|
|
|
use Engelsystem\Test\Unit\HasDatabase;
|
2019-10-08 13:57:50 +02:00
|
|
|
use Engelsystem\Test\Unit\TestCase;
|
2018-10-06 14:15:54 +02:00
|
|
|
|
|
|
|
class UserTest extends TestCase
|
|
|
|
{
|
2019-04-24 10:45:00 +02:00
|
|
|
use ArraySubsetAsserts;
|
2018-10-06 14:15:54 +02:00
|
|
|
use HasDatabase;
|
|
|
|
|
|
|
|
protected $data = [
|
|
|
|
'name' => 'lorem',
|
|
|
|
'password' => '',
|
|
|
|
'email' => 'foo@bar.batz',
|
|
|
|
'api_key' => '',
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function hasOneRelationsProvider()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
Contact::class,
|
|
|
|
'contact',
|
|
|
|
[
|
2018-12-22 00:12:46 +01:00
|
|
|
'dect' => '1234567',
|
2018-10-06 14:15:54 +02:00
|
|
|
'email' => 'foo@bar.batz',
|
|
|
|
'mobile' => '1234/12341234',
|
2019-04-24 11:01:37 +02:00
|
|
|
],
|
2018-10-06 14:15:54 +02:00
|
|
|
],
|
|
|
|
[
|
|
|
|
PersonalData::class,
|
|
|
|
'personalData',
|
|
|
|
[
|
2019-04-24 11:01:37 +02:00
|
|
|
'first_name' => 'Foo',
|
|
|
|
],
|
2018-10-06 14:15:54 +02:00
|
|
|
],
|
|
|
|
[
|
|
|
|
Settings::class,
|
|
|
|
'settings',
|
|
|
|
[
|
|
|
|
'language' => 'de_DE',
|
|
|
|
'theme' => 4,
|
2019-04-24 11:01:37 +02:00
|
|
|
],
|
2018-10-06 14:15:54 +02:00
|
|
|
],
|
|
|
|
[
|
|
|
|
State::class,
|
|
|
|
'state',
|
|
|
|
[
|
|
|
|
'force_active' => true,
|
2019-04-24 11:01:37 +02:00
|
|
|
],
|
2018-10-06 14:15:54 +02:00
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Models\User\User::contact
|
|
|
|
* @covers \Engelsystem\Models\User\User::personalData
|
|
|
|
* @covers \Engelsystem\Models\User\User::settings
|
|
|
|
* @covers \Engelsystem\Models\User\User::state
|
|
|
|
*
|
|
|
|
* @dataProvider hasOneRelationsProvider
|
|
|
|
*
|
|
|
|
* @param string $class
|
|
|
|
* @param string $name
|
|
|
|
* @param array $data
|
|
|
|
*/
|
|
|
|
public function testHasOneRelations($class, $name, $data)
|
|
|
|
{
|
|
|
|
$user = new User($this->data);
|
|
|
|
$user->save();
|
|
|
|
|
|
|
|
/** @var HasUserModel $contact */
|
|
|
|
$contact = new $class($data);
|
|
|
|
$contact->user()
|
|
|
|
->associate($user)
|
|
|
|
->save();
|
|
|
|
|
|
|
|
$this->assertArraySubset($data, (array)$user->{$name}->attributesToArray());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepare test
|
|
|
|
*/
|
2019-04-24 10:45:00 +02:00
|
|
|
protected function setUp(): void
|
2018-10-06 14:15:54 +02:00
|
|
|
{
|
2019-10-08 13:57:50 +02:00
|
|
|
parent::setUp();
|
2018-10-06 14:15:54 +02:00
|
|
|
$this->initDatabase();
|
|
|
|
}
|
|
|
|
}
|