Add Contacts tests

This commit is contained in:
Jonny Barnes 2017-02-18 14:16:22 +00:00
parent b84f8278b6
commit ebb13b905f
5 changed files with 50 additions and 6 deletions

View file

@ -39,11 +39,11 @@ class ContactsController extends Controller
$contact = Contact::where('nick', '=', $nick)->firstOrFail(); $contact = Contact::where('nick', '=', $nick)->firstOrFail();
$contact->homepageHost = parse_url($contact->homepage, PHP_URL_HOST); $contact->homepageHost = parse_url($contact->homepage, PHP_URL_HOST);
$file = public_path() . '/assets/profile-images/' . $contact->homepageHost . '/image'; $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/' . $contact->homepageHost . '/image'
: :
'/assets/profile-images/default-image'; '/assets/profile-images/default-image';
return view('contacts.show', ['contact' => $contact]); return view('contacts.show', compact('contact', 'image'));
} }
} }

View file

@ -6,6 +6,6 @@ Contacts «
@section('content') @section('content')
@foreach($contacts as $contact) @foreach($contacts as $contact)
@include('templates.contact', ['contact' => $contact]) @include('templates.contact', ['contact' => $contact, 'image' => $contact->image])
@endforeach @endforeach
@stop @stop

View file

@ -5,5 +5,5 @@ Contacts «
@stop @stop
@section('content') @section('content')
@include('templates.contact', array('contact' => $contact)) @include('templates.contact', ['contact' => $contact, 'image' => $image])
@stop @stop

View file

@ -1,6 +1,6 @@
<div class="h-card contact"> <div class="h-card contact">
<div> <div>
<img src="{{ $contact->image }}" alt="" class="u-photo"> <img src="{{ $image }}" alt="" class="u-photo">
</div> </div>
<div> <div>
<span class="p-name">{{ $contact->name }}</span> <a href="/contacts/{{ $contact->nick }}">{{ '@' . $contact->nick }}</a> <span class="p-name">{{ $contact->name }}</span> <a href="/contacts/{{ $contact->nick }}">{{ '@' . $contact->nick }}</a>

View file

@ -0,0 +1,44 @@
<?php
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class ContactsTest extends TestCase
{
/**
* Check the `/contatcs` page gives a good response.
*
* @return void
*/
public function test_contacts_page()
{
$response = $this->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');
}
}