diff --git a/app/Http/Controllers/Users/AgencyController.php b/app/Http/Controllers/Users/AgencyController.php index e0b7350..1c18430 100644 --- a/app/Http/Controllers/Users/AgencyController.php +++ b/app/Http/Controllers/Users/AgencyController.php @@ -6,6 +6,8 @@ use App\Http\Controllers\Controller; use Option; /** + * Agency Profile Controller + * * @author Nafies Luthfi */ class AgencyController extends Controller @@ -22,6 +24,15 @@ class AgencyController extends Controller public function update() { + request()->validate([ + 'name' => 'required|string|max:100', + 'tagline' => 'required|string|max:255', + 'email' => 'required|email|max:255', + 'website' => 'required|url|max:255', + 'address' => 'required|string|max:255', + 'phone' => 'required|string|max:255', + ]); + Option::set('agency_name', request('name')); Option::set('agency_tagline', request('tagline')); Option::set('agency_email', request('email')); diff --git a/app/Http/Controllers/Users/ProfileController.php b/app/Http/Controllers/Users/ProfileController.php index bd09b0b..1a24870 100644 --- a/app/Http/Controllers/Users/ProfileController.php +++ b/app/Http/Controllers/Users/ProfileController.php @@ -5,6 +5,8 @@ namespace App\Http\Controllers\Users; use App\Http\Controllers\Controller; /** + * User Profile Controller + * * @author Nafies Luthfi */ class ProfileController extends Controller @@ -22,6 +24,11 @@ class ProfileController extends Controller public function update() { + request()->validate([ + 'name' => 'required|string|max:100', + 'email' => 'required|email|max:255', + ]); + $user = auth()->user(); $user->name = request('name'); diff --git a/public/assets/imgs/default-logo.png b/public/assets/imgs/default-logo.png index 173223d..c85f67b 100644 Binary files a/public/assets/imgs/default-logo.png and b/public/assets/imgs/default-logo.png differ diff --git a/tests/Feature/AgencyProfileTest.php b/tests/Feature/AgencyProfileTest.php new file mode 100644 index 0000000..b250258 --- /dev/null +++ b/tests/Feature/AgencyProfileTest.php @@ -0,0 +1,85 @@ + + */ +class AgencyProfileTest extends TestCase +{ + /** @test */ + public function admin_user_can_visit_agency_page() + { + $user = $this->adminUserSigningIn(); + $this->visit(route('users.agency.show')); + $this->seePageIs(route('users.agency.show')); + } + + /** @test */ + public function admin_user_can_update_agency_data() + { + $user = $this->adminUserSigningIn(); + $this->visit(route('users.agency.edit')); + + $this->submitForm(trans('agency.update'), [ + 'name' => 'Nama Agensi Saya', + 'tagline' => 'Tagline agensi saya', + 'email' => 'nama_agensi@domain.com', + 'address' => 'Jln. Kalimantan, No. 20, Kota', + 'phone' => '081234567890', + 'website' => 'https://example.com', + ]); + + $this->see(trans('agency.updated')); + $this->seePageIs(route('users.agency.show')); + + $this->seeInDatabase('site_options', [ + 'key' => 'agency_name', + 'value' => 'Nama Agensi Saya', + ]); + $this->seeInDatabase('site_options', [ + 'key' => 'agency_email', + 'value' => 'nama_agensi@domain.com', + ]); + $this->seeInDatabase('site_options', [ + 'key' => 'agency_address', + 'value' => 'Jln. Kalimantan, No. 20, Kota', + ]); + $this->seeInDatabase('site_options', [ + 'key' => 'agency_phone', + 'value' => '081234567890', + ]); + $this->seeInDatabase('site_options', [ + 'key' => 'agency_website', + 'value' => 'https://example.com', + ]); + $this->seeInDatabase('site_options', [ + 'key' => 'agency_tagline', + 'value' => 'Tagline agensi saya', + ]); + } + + /** @test */ + public function admin_user_can_update_agency_logo_image() + { + $user = $this->adminUserSigningIn(); + $this->visit(route('users.agency.edit')); + + $this->attach(storage_path('app/sample-image.jpg'), 'logo'); + $this->press(trans('agency.logo_upload')); + + $this->see(trans('agency.updated')); + $this->seePageIs(route('users.agency.show')); + + $this->seeInDatabase('site_options', [ + 'key' => 'agency_logo_path', + 'value' => 'sample-image.jpg', + ]); + + $this->assertFileExistsThenDelete(public_path('assets/imgs/sample-image.jpg')); + } +} diff --git a/tests/Feature/Users/UserProfileTest.php b/tests/Feature/Users/UserProfileTest.php index 625effd..85e039a 100644 --- a/tests/Feature/Users/UserProfileTest.php +++ b/tests/Feature/Users/UserProfileTest.php @@ -4,6 +4,11 @@ namespace Tests\Feature\Users; use Tests\TestCase; +/** + * User Profile Feature Test + * + * @author Nafies Luthfi + */ class UserProfileTest extends TestCase { /** @test */ @@ -42,75 +47,4 @@ class UserProfileTest extends TestCase 'email' => 'me@domain.com', ]); } - /** @test */ - public function a_user_can_visit_their_agency_page() - { - $user = $this->adminUserSigningIn(); - $this->visit(route('users.agency.show')); - $this->seePageIs(route('users.agency.show')); - } - - /** @test */ - public function a_user_can_update_their_agency_data() - { - $user = $this->adminUserSigningIn(); - $this->visit(route('users.agency.edit')); - - $this->submitForm(trans('agency.update'), [ - 'name' => 'Nama Agensi Saya', - 'tagline' => 'Tagline agensi saya', - 'email' => 'nama_agensi@domain.com', - 'address' => 'Jln. Kalimantan, No. 20, Kota', - 'phone' => '081234567890', - 'website' => 'https://example.com', - ]); - - $this->see(trans('agency.updated')); - $this->seePageIs(route('users.agency.show')); - - $this->seeInDatabase('site_options', [ - 'key' => 'agency_name', - 'value' => 'Nama Agensi Saya', - ]); - $this->seeInDatabase('site_options', [ - 'key' => 'agency_email', - 'value' => 'nama_agensi@domain.com', - ]); - $this->seeInDatabase('site_options', [ - 'key' => 'agency_address', - 'value' => 'Jln. Kalimantan, No. 20, Kota', - ]); - $this->seeInDatabase('site_options', [ - 'key' => 'agency_phone', - 'value' => '081234567890', - ]); - $this->seeInDatabase('site_options', [ - 'key' => 'agency_website', - 'value' => 'https://example.com', - ]); - $this->seeInDatabase('site_options', [ - 'key' => 'agency_tagline', - 'value' => 'Tagline agensi saya', - ]); - } - - /** @test */ - public function admin_user_can_update_agency_logo_image() - { - $user = $this->adminUserSigningIn(); - $this->visit(route('users.agency.edit')); - - $this->attach(storage_path('app/sample-image.jpg'), 'logo'); - $this->press(trans('agency.logo_upload')); - - $this->see(trans('agency.updated')); - $this->seePageIs(route('users.agency.show')); - - $this->seeInDatabase('site_options', [ - 'key' => 'agency_logo_path', - 'value' => 'sample-image.jpg', - ]); - - $this->assertFileExistsThenDelete(public_path('assets/imgs/sample-image.jpg')); - } }