diff --git a/app/Http/Controllers/ContactsController.php b/app/Http/Controllers/ContactsController.php index 46573423..6d07234f 100644 --- a/app/Http/Controllers/ContactsController.php +++ b/app/Http/Controllers/ContactsController.php @@ -39,11 +39,11 @@ class ContactsController extends Controller $contact = Contact::where('nick', '=', $nick)->firstOrFail(); $contact->homepageHost = parse_url($contact->homepage, PHP_URL_HOST); $file = public_path() . '/assets/profile-images/' . $contact->homepageHost . '/image'; - $contact->image = ($filesystem->exists($file)) ? + $image = ($filesystem->exists($file)) ? '/assets/profile-images/' . $contact->homepageHost . '/image' : '/assets/profile-images/default-image'; - return view('contacts.show', ['contact' => $contact]); + return view('contacts.show', compact('contact', 'image')); } } diff --git a/resources/views/contacts/index.blade.php b/resources/views/contacts/index.blade.php index 31427ad5..737ac239 100644 --- a/resources/views/contacts/index.blade.php +++ b/resources/views/contacts/index.blade.php @@ -6,6 +6,6 @@ Contacts « @section('content') @foreach($contacts as $contact) - @include('templates.contact', ['contact' => $contact]) + @include('templates.contact', ['contact' => $contact, 'image' => $contact->image]) @endforeach @stop diff --git a/resources/views/contacts/show.blade.php b/resources/views/contacts/show.blade.php index 98c61339..796485ea 100644 --- a/resources/views/contacts/show.blade.php +++ b/resources/views/contacts/show.blade.php @@ -1,9 +1,9 @@ @extends('master') @section('title') -Contacts « +Contacts « @stop @section('content') -@include('templates.contact', array('contact' => $contact)) +@include('templates.contact', ['contact' => $contact, 'image' => $image]) @stop diff --git a/resources/views/templates/contact.blade.php b/resources/views/templates/contact.blade.php index aff9cf46..2ac599d4 100644 --- a/resources/views/templates/contact.blade.php +++ b/resources/views/templates/contact.blade.php @@ -1,6 +1,6 @@
- +
{{ $contact->name }} {{ '@' . $contact->nick }} diff --git a/tests/Feature/ContactsTest.php b/tests/Feature/ContactsTest.php new file mode 100644 index 00000000..b6da3b5a --- /dev/null +++ b/tests/Feature/ContactsTest.php @@ -0,0 +1,44 @@ +get('/contacts'); + $response->assertStatus(200); + } + + /** + * Test an individual contact page with default profile image. + * + * @return void + */ + public function test_contact_page_with_default_pic() + { + $response = $this->get('/contacts/tantek'); + $response->assertViewHas('image', '/assets/profile-images/default-image'); + } + + /** + * Test an individual contact page with a specific profile image. + * + * @return void + */ + public function test_contact_page_with_specific_pic() + { + $response = $this->get('/contacts/tantek'); + $response->assertViewHas('image', '/assets/profile-images/aaronparecki.com/image'); + } +}