Browse Source

Update Job Description & fix Bug checkingCI

1. Save Image 2 Mb Maximal.
2. Add folder "Foto_Profile" in Public_path.
3. Add Job Trans in app.php & user.php (en & id).
4. Add Job Information in User Search.
5. Add Input Job & Job Desription in Edit User Page.
6. Add Job & Job Desription Info in User Profile.
7. Add Job Description in Migrate Database.
pull/8/head
vickyKDV 8 years ago
parent
commit
023140a6d8
  1. 1
      .travis.yml
  2. 53
      app/Helpers/functions.php
  3. 64
      app/Http/Controllers/UsersController.php
  4. 4
      app/Providers/AppServiceProvider.php
  5. 2
      config/database.php
  6. 4
      config/filesystems.php
  7. 1
      database/migrations/2014_10_12_000000_create_users_table.php
  8. BIN
      public/app/public/foto_profile/foto_profile/j79aI14c23A4daF1YEOXLH3lqoWWWghdVri4PXuY.jpeg
  9. BIN
      public/foto_profile/images/rzy1dxWSFLXiPO68KdUEvEMLfKBxOk711Bd7tEVt.jpeg
  10. 1
      resources/lang/en/app.php
  11. 1
      resources/lang/en/user.php
  12. 1
      resources/lang/id/app.php
  13. 1
      resources/lang/id/user.php
  14. 86
      resources/views/users/edit.blade.php
  15. 14
      resources/views/users/partials/profile.blade.php
  16. 10
      resources/views/users/search.blade.php
  17. 3
      routes/web.php
  18. 118
      tests/Unit/Helpers/UserPhotoHelperTest.php

1
.travis.yml

@ -8,6 +8,7 @@ before_script:
- travis_retry composer install --prefer-source --no-interaction --dev - travis_retry composer install --prefer-source --no-interaction --dev
- cp .env.example .env - cp .env.example .env
- php artisan key:generate - php artisan key:generate
- php artisan storage:link
script: script:
- vendor/bin/phpunit - vendor/bin/phpunit

53
app/Helpers/functions.php

@ -1,31 +1,40 @@
<?php <?php
use App\User;
function formatSizeUnits($bytes) function formatSizeUnits($bytes)
{ {
if ($bytes >= 1073741824)
{
$bytes = number_format($bytes / 1073741824, 2) . ' GB';
}
elseif ($bytes >= 1048576)
{
$bytes = number_format($bytes / 1048576, 2) . ' MB';
}
elseif ($bytes >= 1024)
{
$bytes = number_format($bytes / 1024, 2) . ' KB';
}
elseif ($bytes > 1)
{
$bytes = $bytes . ' bytes';
}
elseif ($bytes == 1)
{
$bytes = $bytes . ' byte';
}
else
{
if ($bytes >= 1073741824) {
$bytes = number_format($bytes / 1073741824, 2).' GB';
} elseif ($bytes >= 1048576) {
$bytes = number_format($bytes / 1048576, 2).' MB';
} elseif ($bytes >= 1024) {
$bytes = number_format($bytes / 1024, 2).' KB';
} elseif ($bytes > 1) {
$bytes = $bytes.' bytes';
} elseif ($bytes == 1) {
$bytes = $bytes.' byte';
} else {
$bytes = '0 bytes'; $bytes = '0 bytes';
} }
return $bytes; return $bytes;
} }
function userPhoto(User $user, $attributes = [])
{
return Html::image(
userPhotoPath($user->photo_path, $user->gender_id),
null,
$attributes
);
}
function userPhotoPath($photoPath, $genderId)
{
if (is_file(public_path('foto_profile/'.$photoPath))) {
return asset('foto_profile/'.$photoPath);
}
return asset('images/icon_user_'.$genderId.'.png');
}

64
app/Http/Controllers/UsersController.php

@ -119,18 +119,19 @@ class UsersController extends Controller
public function update(Request $request, User $user) public function update(Request $request, User $user)
{ {
$this->validate($request, [ $this->validate($request, [
'nickname' => 'required|string|max:255',
'name' => 'required|string|max:255',
'gender_id' => 'required|numeric',
'dob' => 'nullable|date|date_format:Y-m-d',
'dod' => 'nullable|date|date_format:Y-m-d',
'yod' => 'nullable|date_format:Y',
'phone' => 'nullable|string|max:255',
'job' => 'nullable|string|max:255',
'address' => 'nullable|string|max:255',
'city' => 'nullable|string|max:255',
'email' => 'nullable|string|max:255',
'password' => 'nullable|min:6|max:15',
'nickname' => 'required|string|max:255',
'name' => 'required|string|max:255',
'gender_id' => 'required|numeric',
'dob' => 'nullable|date|date_format:Y-m-d',
'dod' => 'nullable|date|date_format:Y-m-d',
'yod' => 'nullable|date_format:Y',
'phone' => 'nullable|string|max:255',
'job' => 'nullable|string|max:255',
'job_description' => 'nullable|string|max:255',
'address' => 'nullable|string|max:255',
'city' => 'nullable|string|max:255',
'email' => 'nullable|string|max:255',
// 'password' => 'nullable|min:6|max:15',
]); ]);
$user->nickname = $request->nickname; $user->nickname = $request->nickname;
@ -145,15 +146,16 @@ class UsersController extends Controller
$user->yod = $request->get('yod'); $user->yod = $request->get('yod');
} }
$user->phone = $request->get('phone');
$user->job = $request->get('job');
$user->address = $request->get('address');
$user->city = $request->get('city');
$user->email = $request->get('email');
$user->phone = $request->get('phone');
$user->job = $request->get('job');
$user->job_description = $request->get('job_description');
$user->address = $request->get('address');
$user->city = $request->get('city');
$user->email = $request->get('email');
if ($request->get('email')) {
$user->password = bcrypt($request->get('email'));
}
// if ($request->get('email')) {
// $user->password = bcrypt($request->get('email'));
// }
$user->save(); $user->save();
@ -166,10 +168,26 @@ class UsersController extends Controller
* @param \App\User $user * @param \App\User $user
* @return \Illuminate\Http\Response * @return \Illuminate\Http\Response
*/ */
// public function destroy(User $user)
// {
// //
// }
public function destroy(User $user) public function destroy(User $user)
{ {
$user->delete('manager_id');
return redirect()->route('users.search');
$this->authorize('delete', $user);
$this->validate(request(), [
'user' => 'required',
]);
$routeParam = request()->only('page', 'q');
if (request('user') == $user->id && $user->delete()) {
return redirect()->route('users.profile', $routeParam);
}
return back();
} }
/** /**
@ -183,7 +201,7 @@ class UsersController extends Controller
public function photoUpload(Request $request, User $user) public function photoUpload(Request $request, User $user)
{ {
$request->validate([ $request->validate([
'photo' => 'required|image|max:200',
'photo' => 'required|image|max:2000',
]); ]);
$storage = env('APP_ENV') == 'testing' ? 'avatars' : 'public'; $storage = env('APP_ENV') == 'testing' ? 'avatars' : 'public';

4
app/Providers/AppServiceProvider.php

@ -28,8 +28,6 @@ class AppServiceProvider extends ServiceProvider
*/ */
public function register() public function register()
{ {
if ($this->app->environment() == 'local') {
$this->app->register(\Barryvdh\Debugbar\ServiceProvider::class);
}
//
} }
} }

2
config/database.php

@ -45,7 +45,7 @@ return [
'port' => env('DB_PORT', '3306'), 'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'), 'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'), 'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'password' => env('DB_PASSWORD', 'secret'),
'unix_socket' => env('DB_SOCKET', ''), 'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8', 'charset' => 'utf8',
'collation' => 'utf8_unicode_ci', 'collation' => 'utf8_unicode_ci',

4
config/filesystems.php

@ -45,12 +45,12 @@ return [
'local' => [ 'local' => [
'driver' => 'local', 'driver' => 'local',
'root' => storage_path('app'),
'root' => public_path('foto_profile'),
], ],
'public' => [ 'public' => [
'driver' => 'local', 'driver' => 'local',
'root' => storage_path('app/public'),
'root' => public_path('foto_profile'),
'url' => env('APP_URL').'/storage', 'url' => env('APP_URL').'/storage',
'visibility' => 'public', 'visibility' => 'public',
], ],

1
database/migrations/2014_10_12_000000_create_users_table.php

@ -30,6 +30,7 @@ class CreateUsersTable extends Migration
$table->string('city')->nullable(); $table->string('city')->nullable();
$table->string('phone')->nullable(); $table->string('phone')->nullable();
$table->string('job')->nullable(); $table->string('job')->nullable();
$table->string('job_description')->nullable();
$table->string('photo_path')->nullable(); $table->string('photo_path')->nullable();
$table->uuid('manager_id')->nullable(); $table->uuid('manager_id')->nullable();
$table->rememberToken(); $table->rememberToken();

BIN
public/app/public/foto_profile/foto_profile/j79aI14c23A4daF1YEOXLH3lqoWWWghdVri4PXuY.jpeg

After

Width: 1000  |  Height: 1533  |  Size: 679 KiB

BIN
public/foto_profile/images/rzy1dxWSFLXiPO68KdUEvEMLfKBxOk711Bd7tEVt.jpeg

After

Width: 1000  |  Height: 1533  |  Size: 679 KiB

1
resources/lang/en/app.php

@ -22,6 +22,7 @@ return [
'city' => 'City', 'city' => 'City',
'phone' => 'Phone', 'phone' => 'Phone',
'job' => 'Job', 'job' => 'Job',
'job_description' => 'Job Description',
'login_account' => 'Login Account', 'login_account' => 'Login Account',
'childs_were_not_recorded' => 'Childs were not recorded.', 'childs_were_not_recorded' => 'Childs were not recorded.',

1
resources/lang/en/user.php

@ -45,6 +45,7 @@ return [
'city' => 'City', 'city' => 'City',
'phone' => 'Phone', 'phone' => 'Phone',
'job' => 'Job', 'job' => 'Job',
'job_description' => 'Job Description',
'manager' => 'Manager', 'manager' => 'Manager',
// Photo // Photo

1
resources/lang/id/app.php

@ -22,6 +22,7 @@ return [
'city' => 'Kota', 'city' => 'Kota',
'phone' => 'Telp.', 'phone' => 'Telp.',
'job' => 'Pekerjaan', 'job' => 'Pekerjaan',
'job_description' => 'Bidang Pekerjaan',
'login_account' => 'Akun Login', 'login_account' => 'Akun Login',
'childs_were_not_recorded' => 'Anak-anak belum tercatat.', 'childs_were_not_recorded' => 'Anak-anak belum tercatat.',

1
resources/lang/id/user.php

@ -45,6 +45,7 @@ return [
'city' => 'Kota', 'city' => 'Kota',
'phone' => 'Telp.', 'phone' => 'Telp.',
'job' => 'Pekerjaan', 'job' => 'Pekerjaan',
'job_description' => 'Bidang Pekerjaan',
'manager' => 'Pengelola', 'manager' => 'Pengelola',
// Photo // Photo

86
resources/views/users/edit.blade.php

@ -1,7 +1,44 @@
@extends('layouts.app') @extends('layouts.app')
@section('title', trans('user.edit'))
@section('content') @section('content')
<h2 class="page-header"> <h2 class="page-header">
@if (request('action') == 'delete' && $user)
@can('delete', $user)
<div class="panel panel-default">
<div class="panel-heading"><h3 class="panel-title">{{ trans('app.delete') }}</h3></div>
<div class="panel-body">
<label class="control-label">{{ trans('user.name') }}</label>
<p>{{ $user->name }}</p>
<label class="control-label">{{ trans('user.nickname') }}</label>
<p>{{ $user->nickname }}</p>
<label class="control-label">{{ trans('user.gender') }}</label>
<p>{{ $user->gender }}</p>
<label class="control-label">{{ trans('user.job') }}</label>
<p>{{ $user->job }}</p>
<label class="control-label">{{ trans('user.job_description') }}</label>
<p>{{ $user->job_description }}</p>
{!! $errors->first('id', '<span class="form-error small">:message</span>') !!}
</div>
<hr style="margin:0">
<div class="panel-body">{{ trans('app.delete') }}</div>
<div class="panel-footer">
{!! FormField::delete(
['route' => ['users.destroy', $user]],
__('app.delete'),
['class'=>'btn btn-danger'],
[
'id' => $user->id,
'page' => request('page'),
'q' => request('q'),
]
) !!}
{{ link_to_route('users.edit', trans('app.cancel'), [$user], ['class' => 'btn btn-default']) }}
</div>
</div>
@endcan
@else
<div class="pull-right"> <div class="pull-right">
{{ link_to_route('users.show', trans('app.show_profile').' '.$user->name, [$user->id], ['class' => 'btn btn-default']) }} {{ link_to_route('users.show', trans('app.show_profile').' '.$user->name, [$user->id], ['class' => 'btn btn-default']) }}
</div> </div>
@ -9,18 +46,10 @@
</h2> </h2>
<div class="row"> <div class="row">
{{ Form::model($user, ['route' => ['users.update', $user->id], 'method' =>'patch', 'autocomplete' => 'off']) }} {{ Form::model($user, ['route' => ['users.update', $user->id], 'method' =>'patch', 'autocomplete' => 'off']) }}
{{ Form::model($user, ['route' => ['users.destroy', $user->id], 'method' =>'delete', 'autocomplete' => 'on']) }}
<div class="col-md-4"> <div class="col-md-4">
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading"><h3 class="panel-title">{{ trans('user.edit') }}</h3></div> <div class="panel-heading"><h3 class="panel-title">{{ trans('user.edit') }}</h3></div>
<div class="panel-body"> <div class="panel-body">
<div class="text-center">
@if ($user->photo_path && is_file(public_path('storage/'.$user->photo_path)))
{{ Html::image('storage/'.$user->photo_path, $user->name, ['style' => 'max-width:100%']) }}
@else
{{ Html::image('images/icon_user_'.$user->gender_id.'.png', $user->name, ['style' => 'max-width:100%']) }}
@endif
</div>
{!! FormField::text('name', ['label' => trans('user.name')]) !!} {!! FormField::text('name', ['label' => trans('user.name')]) !!}
{!! FormField::text('nickname', ['label' => trans('user.nickname')]) !!} {!! FormField::text('nickname', ['label' => trans('user.nickname')]) !!}
<div class="row"> <div class="row">
@ -33,6 +62,13 @@
</div> </div>
</div> </div>
</div> </div>
<div class="panel panel-default">
<div class="panel-heading"><h3 class="panel-title">{{ trans('app.login_account') }}</h3></div>
<div class="panel-body">
{!! FormField::email('email', ['label' => trans('auth.email'), 'placeholder' => trans('app.example').' nama@mail.com']) !!}
<!-- {!! FormField::text('password', ['label' => trans('auth.password'), 'placeholder' => '******', 'value' => '']) !!} -->
</div>
</div>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<div class="panel panel-default"> <div class="panel panel-default">
@ -41,29 +77,35 @@
{!! FormField::textarea('address', ['label' => trans('app.address')]) !!} {!! FormField::textarea('address', ['label' => trans('app.address')]) !!}
{!! FormField::text('city', ['label' => trans('app.city'), 'placeholder' => trans('app.example').' Jakarta']) !!} {!! FormField::text('city', ['label' => trans('app.city'), 'placeholder' => trans('app.example').' Jakarta']) !!}
{!! FormField::text('phone', ['label' => trans('app.phone'), 'placeholder' => trans('app.example').' 081234567890']) !!} {!! FormField::text('phone', ['label' => trans('app.phone'), 'placeholder' => trans('app.example').' 081234567890']) !!}
{!! FormField::text('job', ['label' => trans('app.job'), 'placeholder' => trans('app.example').' Karyawan']) !!}
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading"><h3 class="panel-title">{{ trans('app.login_account') }}</h3></div>
<div class="panel-body">
{!! FormField::email('email', ['label' => trans('auth.email'), 'placeholder' => trans('app.example').' nama@mail.com']) !!}
{!! FormField::text('password', ['label' => trans('auth.password'), 'placeholder' => '******', 'value' => '']) !!}
{!! FormField::text('job', ['label' => trans('user.job'), 'placeholder' => trans('app.example').' Karyawan']) !!}
{!! FormField::textarea('job_description', ['label' => trans('app.job_description')]) !!}
</div> </div>
</div> </div>
<div class="text-right"> <div class="text-right">
{{ Form::submit(trans('app.update'), ['class' => 'btn btn-primary']) }} {{ Form::submit(trans('app.update'), ['class' => 'btn btn-primary']) }}
{{ Form::submit(trans('app.delete'), ['class' => 'btn btn-danger']) }}
{{ link_to_route('users.edit', trans('app.delete'), [$user, 'action' => 'delete'], ['class' => 'btn btn-danger pull-center', 'id' => 'del-users-'.$user->id]) }}
{{ link_to_route('users.show', trans('app.cancel'), [$user->id], ['class' => 'btn btn-default']) }} {{ link_to_route('users.show', trans('app.cancel'), [$user->id], ['class' => 'btn btn-default']) }}
</div> </div>
</div> </div>
{{ Form::close() }} {{ Form::close() }}
<div class="col-md-4"> <div class="col-md-4">
{{ Form::open(['route' => ['users.photo-upload', $user], 'method' => 'patch', 'files' => true]) }}
{!! FormField::file('photo', ['required' => true, 'label' => __('user.reupload_photo'), 'info' => ['text' => 'Format jpg, maks: 200 Kb.', 'class' => 'warning']]) !!}
{!! Form::submit(__('user.update_photo'), ['class' => 'btn btn-success']) !!}
{{ link_to_route('users.show', trans('app.cancel'), [$user], ['class' => 'btn btn-default']) }}
{{ Form::close() }}
<div class="panel panel-default">
<div class="panel-heading"><h3 class="panel-title">{{ __('user.update_photo') }}</h3></div>
{{ Form::open(['route' => ['users.photo-upload', $user], 'method' => 'patch', 'files' => true]) }}
<div class="panel-body text-center">
{{ userPhoto($user, ['style' => 'width:100%;max-width:300px']) }}
</div>
<div class="panel-body">
{!! FormField::file('photo', ['required' => true, 'label' => __('user.reupload_photo'), 'info' => ['text' => 'Format jpg, maks: 2 Mb.', 'class' => 'warning']]) !!}
</div>
<div class="panel-footer">
{!! Form::submit(__('user.update_photo'), ['class' => 'btn btn-success']) !!}
{{ link_to_route('users.show', trans('app.cancel'), [$user], ['class' => 'btn btn-default']) }}
</div>
{{ Form::close() }}
</div>
</div> </div>
</div> </div>
@endif
@endsection @endsection

14
resources/views/users/partials/profile.blade.php

@ -1,11 +1,7 @@
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading"><h3 class="panel-title">{{ trans('user.profile') }}</h3></div> <div class="panel-heading"><h3 class="panel-title">{{ trans('user.profile') }}</h3></div>
<div class="panel-body text-center"> <div class="panel-body text-center">
@if ($user->photo_path && is_file(public_path('storage/'.$user->photo_path)))
{{ Html::image('storage/'.$user->photo_path, $user->name, ['style' => 'max-width:100%']) }}
@else
{{ Html::image('images/icon_user_'.$user->gender_id.'.png', $user->name, ['style' => 'max-width:100%']) }}
@endif
{{ userPhoto($user, ['style' => 'width:100%;max-width:300px']) }}
</div> </div>
<table class="table"> <table class="table">
<tbody> <tbody>
@ -40,6 +36,14 @@
</tr> </tr>
@endif @endif
<tr> <tr>
<th>{{ trans('user.job') }}</th>
<td>{{ $user->job }}</td>
</tr>
<tr>
<th>{{ trans('user.job_description') }}</th>
<td>{{ $user->job_description }}</td>
</tr>
<tr>
<th>{{ trans('user.phone') }}</th> <th>{{ trans('user.phone') }}</th>
<td>{{ $user->phone }}</td> <td>{{ $user->phone }}</td>
</tr> </tr>

10
resources/views/users/search.blade.php

@ -1,5 +1,6 @@
@extends('layouts.app') @extends('layouts.app')
@section('user-content')
@section('content') @section('content')
<h2 class="page-header"> <h2 class="page-header">
{{ trans('app.search_your_family') }} {{ trans('app.search_your_family') }}
@ -27,13 +28,18 @@
@foreach ($chunkedUser as $user) @foreach ($chunkedUser as $user)
<div class="col-md-3"> <div class="col-md-3">
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading"><h3 class="panel-title">{{ $user->profileLink() }} ({{ $user->gender }})</h3></div>
<div class="panel-heading">
{{ userPhoto($user, ['style' => 'width:100%;max-width:300px']) }}
</div>
<div class="panel-body"> <div class="panel-body">
<h3 class="panel-title">{{ $user->profileLink() }} ({{ $user->gender }})</h3>
<div>{{ trans('user.nickname') }} : {{ $user->nickname }}</div> <div>{{ trans('user.nickname') }} : {{ $user->nickname }}</div>
<hr style="margin: 5px 0;"> <hr style="margin: 5px 0;">
<div>{{ trans('user.job') }} : {{ $user->job }}</div>
<div>{{ trans('user.job_description') }} : {{ $user->job_description }}</div>
<hr style="margin: 5px 0;">
<div>{{ trans('user.father') }} : {{ $user->father_id ? $user->father->name : '' }}</div> <div>{{ trans('user.father') }} : {{ $user->father_id ? $user->father->name : '' }}</div>
<div>{{ trans('user.mother') }} : {{ $user->mother_id ? $user->mother->name : '' }}</div> <div>{{ trans('user.mother') }} : {{ $user->mother_id ? $user->mother->name : '' }}</div>
<div>{{ trans('user.job') }} : {{ $user->job }}</div>
</div> </div>
<div class="panel-footer"> <div class="panel-footer">
{{ link_to_route('users.show', trans('app.show_profile'), [$user->id], ['class' => 'btn btn-default btn-xs']) }} {{ link_to_route('users.show', trans('app.show_profile'), [$user->id], ['class' => 'btn btn-default btn-xs']) }}

3
routes/web.php

@ -27,11 +27,12 @@ Route::post('family-actions/{user}/set-parent', 'FamilyActionsController@setPare
Route::get('profile-search', 'UsersController@search')->name('users.search'); Route::get('profile-search', 'UsersController@search')->name('users.search');
Route::get('users/{user}', 'UsersController@show')->name('users.show'); Route::get('users/{user}', 'UsersController@show')->name('users.show');
Route::get('users/{user}/edit', 'UsersController@edit')->name('users.edit'); Route::get('users/{user}/edit', 'UsersController@edit')->name('users.edit');
Route::delete('users/{user}', 'UsersController@destroy')->name('users.destroy');
Route::get('users/{user}', 'UsersController@destroy')->name('users.destroy');
Route::patch('users/{user}', 'UsersController@update')->name('users.update'); Route::patch('users/{user}', 'UsersController@update')->name('users.update');
Route::get('users/{user}/chart', 'UsersController@chart')->name('users.chart'); Route::get('users/{user}/chart', 'UsersController@chart')->name('users.chart');
Route::get('users/{user}/tree', 'UsersController@tree')->name('users.tree'); Route::get('users/{user}/tree', 'UsersController@tree')->name('users.tree');
Route::patch('users/{user}/photo-upload', 'UsersController@photoUpload')->name('users.photo-upload'); Route::patch('users/{user}/photo-upload', 'UsersController@photoUpload')->name('users.photo-upload');
Route::resource('users', 'UsersController');
Route::get('users/{user}/marriages', 'UserMarriagesController@index')->name('users.marriages'); Route::get('users/{user}/marriages', 'UserMarriagesController@index')->name('users.marriages');

118
tests/Unit/Helpers/UserPhotoHelperTest.php

@ -0,0 +1,118 @@
<?php
namespace Tests\Unit\Helpers;
use App\User;
use Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseMigrations;
class UserPhotoHelperTest extends TestCase
{
use DatabaseMigrations;
/** @test */
public function user_photo_path_function_exists()
{
$this->assertTrue(function_exists('userPhotoPath'));
}
/** @test */
public function user_photo_path_function_returns_default_photo_path_based_on_gender_if_photo_path_is_null()
{
$genderId = 1; // Male
$this->assertEquals(
asset('images/icon_user_1.png'), userPhotoPath(null, $genderId)
);
$genderId = 2; // Female
$this->assertEquals(
asset('images/icon_user_2.png'), userPhotoPath(null, $genderId)
);
}
/** @test */
public function user_photo_function_exists()
{
$this->assertTrue(function_exists('userPhoto'));
}
/** @test */
public function user_photo_function_returns_default_image_photo_element_if_no_agency_image_path_setting()
{
$user = factory(User::class)->create(['gender_id' => 1]);
$photoFile = 'images/icon_user_1.png';
$imageString = '<img';
$imageString .= ' src="'.asset($photoFile).'"';
$imageString .= '>';
$this->assertEquals($imageString, userPhoto($user));
}
/** @test */
public function user_photo_function_returns_correct_photo_element_based_on_user_photo_path()
{
$photoPath = 'images/user_photo_path.jpg';
if (!is_dir(storage_path('app/public/images'))) {
mkdir(storage_path('app/public/images'), 0700);
}
copy(public_path('images/icon_user_1.png'), storage_path('app/public/images/user_photo_path.jpg'));
$this->assertFileExists(storage_path('app/public/images/user_photo_path.jpg'));
$user = factory(User::class)->create([
'gender_id' => 2,
'photo_path' => $photoPath,
]);
$imageString = '<img';
$imageString .= ' src="'.asset('storage/'.$photoPath).'"';
$imageString .= '>';
$this->assertEquals($imageString, userPhoto($user));
$this->assertFileExists(storage_path('app/public/images/user_photo_path.jpg'));
unlink(storage_path('app/public/images/user_photo_path.jpg'));
$this->assertFileNotExists(storage_path('app/public/images/user_photo_path.jpg'));
}
/** @test */
public function user_photo_function_has_overrideable_attributes()
{
$user = factory(User::class)->create([
'gender_id' => 1,
]);
$photoFile = 'images/icon_user_1.png';
$imageString = '<img';
$imageString .= ' src="'.asset($photoFile).'"';
$imageString .= ' class="123"';
$imageString .= ' style="display: inline"';
$imageString .= '>';
$overrides = [
'class' => '123',
'style' => 'display: inline',
];
$this->assertEquals($imageString, userPhoto($user, $overrides));
}
/** @test */
public function user_photo_function_returns_default_gender_logo_image_if_user_photo_file_doesnt_exists()
{
$user = factory(User::class)->create([
'gender_id' => 2,
'photo_path' => 'images/non_exists_photo_path.jpg',
]);
$photoFile = 'images/icon_user_2.png';
$imageString = '<img';
$imageString .= ' src="'.asset($photoFile).'"';
$imageString .= '>';
$this->assertEquals($imageString, userPhoto($user));
}
}
Loading…
Cancel
Save