CityTest.php
2.75 KB
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
<?php
namespace Tests\Feature;
use App\Models\Account;
use App\Models\Campaigns;
use App\Models\Dictionary;
use App\Models\Tokens;
use App\Models\User;
use App\Models\Organization;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class CityTest extends TestCase
{
use RefreshDatabase;
private $token;
private $token_main;
protected function setUp(): void
{
parent::setUp();
$account = Account::create(['name' => 'Acme Corporation']);
$this->user = factory(User::class)->create([
'account_id' => $account->id,
'first_name' => 'John',
'last_name' => 'Doe',
'email' => 'johndoe@example.com',
'owner' => true,
]);
$this->token = factory(Tokens::class)->create([
'created_by' => $this->user->getKey()
]);
$this->token_main = factory(Tokens::class)->create([
'type' => Tokens::MAIN,
]);
factory(Campaigns::class, 2)->create([
'manage' => true,
'token' => $this->token_main->getKey(),
]);
factory(Campaigns::class, 2)->create([
'manage' => false,
'token' => $this->token_main->getKey(),
]);
factory(Dictionary::class, 10)->create([
'type' => Dictionary::CITY,
]);
}
public function test_add_city(){
$ids = Dictionary::all()->pluck('id');
$this->actingAs($this->user)
->post(route('token.city.store', [
'token' => $this->token->id,
'city' => $ids[0]
]))
->assertStatus(302);
$this->token->load('cities.campaigns');
$this->assertEquals($this->token->cities->count(), 1);
foreach ($this->token->cities as $city){
$this->assertEquals($city->campaigns->count(), 2);
}
$this->actingAs($this->user)
->post(route('token.city.store', [
'token' => $this->token->id,
'city' => $ids[1]
]))
->assertStatus(302);
$this->token->load('cities.campaigns');
$this->assertEquals($this->token->cities->count(), 2);
foreach ($this->token->cities as $city){
$this->assertEquals($city->campaigns->count(), 2);
}
$this->actingAs($this->user)
->post(route('token.city.store', [
'token' => $this->token->id,
'city' => $ids[2]
]))
->assertStatus(302);
$this->token->load('cities.campaigns');
$this->assertEquals($this->token->cities->count(), 3);
foreach ($this->token->cities as $city){
$this->assertEquals($city->campaigns->count(), 2);
}
}
}