summaryrefslogtreecommitdiff
path: root/tests/Unit/Models/TeamTest.php
blob: fdd5be44eb3b3917e39dc2e0053809a02ad513e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php

namespace Engelsystem\Test\Unit\Models;

use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
use Engelsystem\Models\Team;
use Engelsystem\Test\Unit\Models\Auth\AuthModelTest;

class TeamTest extends AuthModelTest
{
    use ArraySubsetAsserts;

    /** @var array */
    protected $data = [
        'name'                     => 'Example team',
        'description'              => 'Lorem Ipsum',
        'contact_name'             => 'Con Tact',
        'contact_dect'             => '1337',
        'contact_email'            => 'foo@bar.batz',
        'restricted'               => false,
        'self_signup'              => true,
        'requires_drivers_license' => false,
        'show_on_frontend'         => true,
        'show_on_dashboard'        => true,
    ];

    /**
     * @covers \Engelsystem\Models\Team::roles
     */
    public function testRoles()
    {
        $role = $this->getRole();
        $role2 = $this->getRole([], ['name' => 'Another Role']);

        $team = new Team($this->data);
        $team->save();
        $team->roles()->attach($role);
        $team->roles()->attach($role2);

        $this->assertCount(2, $team->roles);
        $this->assertEquals('Test Role', $team->roles()->get()->first()->name);
    }

    /**
     * @covers \Engelsystem\Models\Team::supporters
     */
    public function testSupporters()
    {
        $user = $this->getUser();

        $team = new Team($this->data);
        $team->save();
        $team->supporters()->attach($user);

        $this->assertEquals('Test User', $team->supporters()->get()->first()->name);
    }

    /**
     * @covers \Engelsystem\Models\Team::users
     */
    public function testUsers()
    {
        $user = $this->getUser();

        $team = new Team($this->data);
        $team->save();
        $team->users()->attach($user);

        $this->assertEquals('Test User', $team->users()->get()->first()->name);
    }
}