-
Notifications
You must be signed in to change notification settings - Fork 171
/
UsedByTeamsTraitTest.php
131 lines (106 loc) · 3.32 KB
/
UsedByTeamsTraitTest.php
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
use Mpociot\Teamwork\TeamworkTeam;
class UsedByTeamsTraitTest extends Orchestra\Testbench\TestCase
{
protected $user;
protected $team;
/**
* Define environment setup.
*
* @param \Illuminate\Foundation\Application $app
*
* @return void
*/
protected function getEnvironmentSetUp($app)
{
$app['config']->set('database.default', 'testing');
$app['config']->set('teamwork.user_model', 'User');
\Schema::create('users', function ($table) {
$table->increments('id');
$table->string('name');
$table->timestamps();
$table->softDeletes();
});
\Schema::create('tasks', function ($table) {
$table->increments('id');
$table->string('name');
$table->integer('team_id');
$table->timestamps();
});
}
/**
*
*/
public function setUp()
{
parent::setUp();
$this->artisan('migrate', [
'--database' => 'testing',
'--realpath' => realpath(__DIR__.'/../src/database/migrations'),
]);
$this->user = new User();
$this->user->name = 'Marcel';
$this->user->save();
$this->team = TeamworkTeam::create(['name' => 'Test-Team']);
$this->user->attachTeam($this->team);
}
protected function getPackageProviders($app)
{
return [\Mpociot\Teamwork\TeamworkServiceProvider::class];
}
protected function getPackageAliases($app)
{
return [
'Teamwork' => \Mpociot\Teamwork\Facades\Teamwork::class
];
}
public function testThrowsExceptionWhenUnauthorized()
{
$this->setExpectedException(\Exception::class,'No authenticated user with selected team present.');
$task = new Task();
$task->name = 'Buy milk';
$task->save();
}
public function testGetsCurrentTeamTasks()
{
auth()->login($this->user);
$task = new Task();
$task->team_id = $this->user->currentTeam->getKey();
$task->name = 'Buy milk';
$task->save();
$task2 = new Task();
$task2->team_id = $this->user->currentTeam->getKey() + 1;
$task2->name = 'Buy steaks';
$task2->save();
$tasks = Task::all();
$this->assertCount(1, $tasks);
$this->assertEquals($task->id, $tasks->first()->id);
$this->assertEquals($task->team_id, $tasks->first()->team_id);
$this->assertEquals($task->name, $tasks->first()->name);
}
public function testGetsAllTasks()
{
auth()->login($this->user);
$task = new Task();
$task->team_id = $this->user->currentTeam->getKey();
$task->name = 'Buy milk';
$task->save();
$task2 = new Task();
$task2->team_id = $this->user->currentTeam->getKey() + 1;
$task2->name = 'Buy steaks';
$task2->save();
$tasks = Task::allTeams()->get();
$this->assertCount(2, $tasks);
}
public function testScopeAutomaticallyAddsCurrentTeam()
{
auth()->login($this->user);
$task = new Task();
$task->name = 'Buy milk';
$task->save();
$this->seeInDatabase('tasks', [
'name' => 'Buy milk',
'team_id' => $this->user->currentTeam->getKey()
]);
}
}