|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace the42coders\TLAP\Tests\Integration; |
| 4 | + |
| 5 | +use the42coders\TLAP\Tests\models\User; |
| 6 | + |
| 7 | +class UserCrudTest extends TestCase |
| 8 | +{ |
| 9 | + protected function setUp(): void |
| 10 | + { |
| 11 | + parent::setUp(); |
| 12 | + config(['tlap.models.users' => User::class]); |
| 13 | + } |
| 14 | + |
| 15 | + public function testItCanListUsers() |
| 16 | + { |
| 17 | + $user = User::create([ |
| 18 | + 'name' => 'Test User', |
| 19 | + 'email' => 'user@test.com', |
| 20 | + 'password' => 'secret' |
| 21 | + ]); |
| 22 | + |
| 23 | + $this->get(route('tlap.index', ['models' => User::getModelPluralName()])) |
| 24 | + ->assertOk(); |
| 25 | + |
| 26 | + } |
| 27 | + |
| 28 | + public function testItCanCreateUser() |
| 29 | + { |
| 30 | + $userData = [ |
| 31 | + 'name' => 'Test User', |
| 32 | + 'email' => 'user@test.com', |
| 33 | + 'password' => 'pass' |
| 34 | + ]; |
| 35 | + |
| 36 | + $this->post(route('tlap.store', ['models' => User::getModelPluralName()]), $userData) |
| 37 | + ->assertRedirect(); |
| 38 | + |
| 39 | + unset($userData['password']); |
| 40 | + $this->assertDatabaseHas('users', $userData); |
| 41 | + } |
| 42 | + |
| 43 | + public function testItCanShowUser() |
| 44 | + { |
| 45 | + /** @var User $user */ |
| 46 | + $user = User::create([ |
| 47 | + 'name' => 'Test User', |
| 48 | + 'email' => 'user@test.com', |
| 49 | + 'password' => 'secret' |
| 50 | + ]); |
| 51 | + |
| 52 | + $this->get(route('tlap.show', ['models' => User::getModelPluralName(), 'id' => $user->id])) |
| 53 | + ->assertOk() |
| 54 | + ->assertSee($user->name); |
| 55 | + } |
| 56 | + |
| 57 | + public function testItCanShowUserCreateForm() |
| 58 | + { |
| 59 | + $this->get(route('tlap.create', ['models' => User::getModelPluralName()])) |
| 60 | + ->assertOk() |
| 61 | + ->assertSee('name'); |
| 62 | + } |
| 63 | + |
| 64 | + public function testItCanShowUserEditForm() |
| 65 | + { |
| 66 | + /** @var User $user */ |
| 67 | + $user = User::create([ |
| 68 | + 'name' => 'Test User', |
| 69 | + 'email' => 'user@test.com', |
| 70 | + 'password' => 'secret' |
| 71 | + ]); |
| 72 | + |
| 73 | + $this->get(route('tlap.edit', ['models' => User::getModelPluralName(), 'id' => $user->id])) |
| 74 | + ->assertOk() |
| 75 | + ->assertSee('name') |
| 76 | + ->assertSee($user->name); |
| 77 | + } |
| 78 | + |
| 79 | + public function testItCanUpdateUser() |
| 80 | + { |
| 81 | + /** @var User $user */ |
| 82 | + $user = User::create([ |
| 83 | + 'name' => 'Test User', |
| 84 | + 'email' => 'user@test.com', |
| 85 | + 'password' => 'secret' |
| 86 | + ]); |
| 87 | + |
| 88 | + $userData = [ |
| 89 | + 'name' => 'Test User Updated', |
| 90 | + 'email' => 'user@test.com', |
| 91 | + 'password' => 'pass' |
| 92 | + ]; |
| 93 | + |
| 94 | + $this->post(route('tlap.update', ['models' => User::getModelPluralName(), 'id' => $user->id]), $userData) |
| 95 | + ->assertRedirect(); |
| 96 | + |
| 97 | + unset($userData['password']); |
| 98 | + $this->assertDatabaseHas('users', $userData); |
| 99 | + } |
| 100 | + |
| 101 | + public function testItCanDeleteUser() |
| 102 | + { |
| 103 | + /** @var User $user */ |
| 104 | + $user = User::create([ |
| 105 | + 'name' => 'Test User', |
| 106 | + 'email' => 'user@test.com', |
| 107 | + 'password' => 'secret' |
| 108 | + ]); |
| 109 | + |
| 110 | + $this->assertModelExists($user); |
| 111 | + |
| 112 | + $this->get(route('tlap.delete', ['models' => User::getModelPluralName(), 'id' => $user->id])) |
| 113 | + ->assertRedirect(); |
| 114 | + |
| 115 | + $this->assertModelMissing($user); |
| 116 | + } |
| 117 | +} |
0 commit comments