From a25fdfe7e19660861f34ec779272f62eaa97ae73 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Sun, 12 Nov 2017 23:52:05 +0800 Subject: [PATCH] Add unit tests appLogoImage function helper --- app/helpers.php | 19 ++++++-- tests/Unit/Helpers/AppLogoImageTest.php | 86 +++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 5 deletions(-) create mode 100644 tests/Unit/Helpers/AppLogoImageTest.php diff --git a/app/helpers.php b/app/helpers.php index f2c9702..ca7f8c3 100755 --- a/app/helpers.php +++ b/app/helpers.php @@ -204,16 +204,25 @@ function dateDifference($date1, $date2, $differenceFormat = '%a') return $interval->format($differenceFormat); } -function appLogoImage() +function appLogoImage($attributes = []) { - $logoString = ''; - return $logoString; + return Html::image( + appLogoPath(), + 'Logo '.Option::get('agency_name', 'Laravel'), + $attributes + ); } function appLogoPath() { - return asset('assets/imgs/'.Option::get('agency_logo_path', 'default-logo.png')); + $defaultLogoImagePath = 'default-logo.png'; + $optionLogoImagePath = Option::get('agency_logo_path'); + + if (is_file(public_path('assets/imgs/'.$optionLogoImagePath))) { + return asset('assets/imgs/'.$optionLogoImagePath); + } + + return asset('assets/imgs/'.$defaultLogoImagePath); } function monthDateArray($year, $month) diff --git a/tests/Unit/Helpers/AppLogoImageTest.php b/tests/Unit/Helpers/AppLogoImageTest.php new file mode 100644 index 0000000..a0538c0 --- /dev/null +++ b/tests/Unit/Helpers/AppLogoImageTest.php @@ -0,0 +1,86 @@ +insert([ + 'key' => 'agency_logo_path', + 'value' => 'icon_user_1.png', + ]); + + $this->assertEquals(asset('assets/imgs/icon_user_1.png'), appLogoPath()); + } + + /** @test */ + public function app_logo_path_function_returns_default_logo_image_path_if_no_image_logo_path_setting() + { + $this->assertEquals(asset('assets/imgs/default-logo.png'), appLogoPath()); + } + + /** @test */ + public function app_logo_image_function_returns_default_logo_image_element_if_no_agency_logo_path_setting() + { + $logoString = 'assertEquals($logoString, appLogoImage()); + } + + /** @test */ + public function app_logo_image_function_returns_correct_logo_image_elemet_based_on_agency_logo_path_setting() + { + \DB::table('site_options')->insert([ + 'key' => 'agency_logo_path', + 'value' => 'icon_user_1.png', + ]); + + $logoString = 'assertEquals($logoString, appLogoImage()); + } + + /** @test */ + public function app_logo_image_function_has_overrideable_attributes() + { + \DB::table('site_options')->insert([ + 'key' => 'agency_name', + 'value' => 'My Agency Name', + ]); + + $logoString = ' '123', + 'style' => 'display: inline', + ]; + $this->assertEquals($logoString, appLogoImage($overrides)); + } + + /** @test */ + public function app_logo_image_function_returns_default_logo_image_if_agency_logo_file_doesnt_exists() + { + \DB::table('site_options')->insert([ + 'key' => 'agency_logo_path', + 'value' => 'agency_logo.jpg', + ]); + + $logoString = 'assertEquals($logoString, appLogoImage()); + } +}