make(); $response = $this->actingAs($user)->get('/admin/contacts'); $response->assertViewIs('admin.contacts.index'); } #[Test] public function contact_create_page_loads(): void { $user = User::factory()->make(); $response = $this->actingAs($user)->get('/admin/contacts/create'); $response->assertViewIs('admin.contacts.create'); } #[Test] public function admin_can_create_new_contact(): void { $user = User::factory()->make(); $this->actingAs($user)->post('/admin/contacts', [ 'name' => 'Fred Bloggs', 'nick' => 'fred', 'homepage' => 'https://fred.blog/gs', ]); $this->assertDatabaseHas('contacts', [ 'name' => 'Fred Bloggs', 'nick' => 'fred', 'homepage' => 'https://fred.blog/gs', ]); } #[Test] public function admin_can_see_form_to_edit_contact(): void { $user = User::factory()->make(); $contact = Contact::factory()->create(); $response = $this->actingAs($user)->get('/admin/contacts/' . $contact->id . '/edit'); $response->assertViewIs('admin.contacts.edit'); } #[Test] public function admin_can_update_contact(): void { $user = User::factory()->make(); $contact = Contact::factory()->create(); $this->actingAs($user)->post('/admin/contacts/' . $contact->id, [ '_method' => 'PUT', 'name' => 'Tantek Celik', 'nick' => 'tantek', 'homepage' => 'https://tantek.com', 'twitter' => 't', ]); $this->assertDatabaseHas('contacts', [ 'name' => 'Tantek Celik', 'homepage' => 'https://tantek.com', ]); } #[Test] public function admin_can_edit_contact_and_upload_avatar(): void { copy(__DIR__ . '/../../aaron.png', sys_get_temp_dir() . '/tantek.png'); $path = sys_get_temp_dir() . '/tantek.png'; $file = new UploadedFile($path, 'tantek.png', 'image/png', null, true); $user = User::factory()->make(); $contact = Contact::factory()->create(); $this->actingAs($user)->post('/admin/contacts/' . $contact->id, [ '_method' => 'PUT', 'name' => 'Tantek Celik', 'nick' => 'tantek', 'homepage' => 'https://tantek.com', 'twitter' => 't', 'avatar' => $file, ]); $this->assertFileEquals( __DIR__ . '/../../aaron.png', public_path() . '/assets/profile-images/tantek.com/image' ); } #[Test] public function admin_can_delete_contact(): void { $user = User::factory()->make(); $contact = Contact::factory()->create(['nick' => 'tantek']); $this->assertDatabaseHas('contacts', [ 'nick' => 'tantek', ]); $this->actingAs($user)->post('/admin/contacts/' . $contact->id, [ '_method' => 'DELETE', ]); $this->assertDatabaseMissing('contacts', [ 'nick' => 'tantek', ]); } #[Test] public function admin_can_trigger_retrieval_of_remote_avatar(): void { $html = <<<'HTML'