summaryrefslogtreecommitdiff
path: root/tests/Unit/Models
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2018-10-06 14:15:54 +0200
committermsquare <msquare@notrademark.de>2018-10-31 13:43:23 +0100
commit8e62c4c52c27f9432820915deeb699c3d1f58ce7 (patch)
tree43d22891924aeaa42108c21309da6b09b5390128 /tests/Unit/Models
parentb443b53919f50bd0176e7b67dfd1efc28276a770 (diff)
Added new user models
Diffstat (limited to 'tests/Unit/Models')
-rw-r--r--tests/Unit/Models/User/HasUserModelTest.php33
-rw-r--r--tests/Unit/Models/User/Stub/HasUserModelImplementation.php10
-rw-r--r--tests/Unit/Models/User/UserTest.php98
3 files changed, 141 insertions, 0 deletions
diff --git a/tests/Unit/Models/User/HasUserModelTest.php b/tests/Unit/Models/User/HasUserModelTest.php
new file mode 100644
index 00000000..07f3d726
--- /dev/null
+++ b/tests/Unit/Models/User/HasUserModelTest.php
@@ -0,0 +1,33 @@
+<?php
+
+namespace Engelsystem\Test\Unit\Models;
+
+use Engelsystem\Models\User\HasUserModel;
+use Engelsystem\Test\Unit\HasDatabase;
+use Engelsystem\Test\Unit\Models\User\Stub\HasUserModelImplementation;
+use Illuminate\Database\Eloquent\Relations\BelongsTo;
+use PHPUnit\Framework\TestCase;
+
+class HasUserModelTest extends TestCase
+{
+ use HasDatabase;
+
+ /**
+ * @covers \Engelsystem\Models\User\HasUserModel::user
+ */
+ public function testHasOneRelations()
+ {
+ /** @var HasUserModel $contact */
+ $model = new HasUserModelImplementation();
+
+ $this->assertInstanceOf(BelongsTo::class, $model->user());
+ }
+
+ /**
+ * Prepare test
+ */
+ protected function setUp()
+ {
+ $this->initDatabase();
+ }
+}
diff --git a/tests/Unit/Models/User/Stub/HasUserModelImplementation.php b/tests/Unit/Models/User/Stub/HasUserModelImplementation.php
new file mode 100644
index 00000000..0456eb6a
--- /dev/null
+++ b/tests/Unit/Models/User/Stub/HasUserModelImplementation.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace Engelsystem\Test\Unit\Models\User\Stub;
+
+use Engelsystem\Models\User\HasUserModel;
+
+class HasUserModelImplementation extends HasUserModel
+{
+
+}
diff --git a/tests/Unit/Models/User/UserTest.php b/tests/Unit/Models/User/UserTest.php
new file mode 100644
index 00000000..c30f7761
--- /dev/null
+++ b/tests/Unit/Models/User/UserTest.php
@@ -0,0 +1,98 @@
+<?php
+
+namespace Engelsystem\Test\Unit\Models;
+
+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;
+use PHPUnit\Framework\TestCase;
+
+class UserTest extends TestCase
+{
+ use HasDatabase;
+
+ protected $data = [
+ 'name' => 'lorem',
+ 'password' => '',
+ 'email' => 'foo@bar.batz',
+ 'api_key' => '',
+ ];
+
+ /**
+ * @return array
+ */
+ public function hasOneRelationsProvider()
+ {
+ return [
+ [
+ Contact::class,
+ 'contact',
+ [
+ 'dect' => '1234',
+ 'email' => 'foo@bar.batz',
+ 'mobile' => '1234/12341234',
+ ]
+ ],
+ [
+ PersonalData::class,
+ 'personalData',
+ [
+ 'first_name' => 'Foo'
+ ]
+ ],
+ [
+ Settings::class,
+ 'settings',
+ [
+ 'language' => 'de_DE',
+ 'theme' => 4,
+ ]
+ ],
+ [
+ State::class,
+ 'state',
+ [
+ 'force_active' => true,
+ ]
+ ],
+ ];
+ }
+
+ /**
+ * @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
+ */
+ protected function setUp()
+ {
+ $this->initDatabase();
+ }
+}