Add Notes tests

This commit is contained in:
Jonny Barnes 2017-02-18 16:38:18 +00:00
parent c1e72be0c3
commit ce19713c99
4 changed files with 233 additions and 0 deletions

View file

@ -0,0 +1,35 @@
<?php
namespace Tests\Browser;
use Tests\DuskTestCase;
use Illuminate\Foundation\Testing\DatabaseMigrations;
class NotesTest extends DuskTestCase
{
/**
* Look for the client name after the note.
*
* @return void
*/
public function test_client_name_displayed()
{
$this->browse(function ($browser) {
$browser->visit('/notes/D')
->assertSee('JBL5');
});
}
/**
* Look for the client URL after the note.
*
* @return void
*/
public function test_client_url_displayed()
{
$this->browse(function ($browser) {
$browser->visit('/notes/E')
->assertSee('quill.p3k.io');
});
}
}

View file

@ -0,0 +1,57 @@
<?php
namespace Tests\Feature;
use App\Note;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class NotesControllerTest extends TestCase
{
/**
* Test the `/notes` page returns 200, this should
* mean the database is being hit.
*
* @return void
*/
public function test_notes_page()
{
$response = $this->get('/notes');
$response->assertStatus(200);
}
/**
* Test a specific note.
*
* @return void
*/
public function test_specific_note()
{
$response = $this->get('/notes/D');
$response->assertViewHas('note');
}
/**
* Test that `/note/{decID}` redirects to `/notes/{nb60id}`.
*
* @return void
*/
public function test_dec_id_redirect()
{
$response = $this->get('/note/11');
$response->assertRedirect(config('app.url') . '/notes/B');
}
/**
* Visit the tagged page and check the tag view data.
*
* @return void
*/
public function test_tagged_notes_page()
{
$response = $this->get('/notes/tagged/beer');
$response->assertViewHas('tag', 'beer');
}
}

View file

@ -0,0 +1,71 @@
<?php
namespace Tests\Unit;
use Tests\TestCase;
use Illuminate\Support\Facades\Cache;
use App\Http\Controllers\NotesController;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class NotesControllerTest extends TestCase
{
protected $notesController;
public function __construct()
{
$this->notesController = new NotesController();
}
/**
* Test a correct profile link is formed from a generic URL.
*
* @return void
*/
public function test_create_photo_link_with_non_cached_image()
{
$notesController = new \App\Http\Controllers\NotesController();
$homepage = 'https://example.org/profile.png';
$expected = 'https://example.org/profile.png';
$this->assertEquals($expected, $this->notesController->createPhotoLink($homepage));
}
/**
* Test a correct profile link is formed from a generic URL (cached).
*
* @return void
*/
public function test_create_photo_link_with_cached_image()
{
$notesController = new \App\Http\Controllers\NotesController();
$homepage = 'https://aaronparecki.com/profile.png';
$expected = '/assets/profile-images/aaronparecki.com/image';
$this->assertEquals($expected, $this->notesController->createPhotoLink($homepage));
}
/**
* Test a correct profile link is formed from a twitter URL.
*
* @return void
*/
public function test_create_photo_link_with_twimg_profile_image_url()
{
$notesController = new \App\Http\Controllers\NotesController();
$twitterProfileImage = 'http://pbs.twimg.com/1234';
$expected = 'https://pbs.twimg.com/1234';
$this->assertEquals($expected, $this->notesController->createPhotoLink($twitterProfileImage));
}
/**
* Test `null` is returned for a twitter profile.
*
* @return void
*/
public function test_create_photo_link_with_cached_twitter_url()
{
$twitterURL = 'https://twitter.com/example';
$expected = 'https://pbs.twimg.com/static_profile_link.jpg';
Cache::put($twitterURL, $expected, 1);
$this->assertEquals($expected, $this->notesController->createPhotoLink($twitterURL));
}
}

70
tests/Unit/NotesTest.php Normal file
View file

@ -0,0 +1,70 @@
<?php
namespace Tests\Unit;
use App\Note;
use Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class NotesTest extends TestCase
{
/**
* Test the getNoteAttribute method. This note will check the markdown,
* emoji-a11y, and hashtag sub-methods.
*
* @return void
*/
public function test_get_note_attribute_method()
{
$expected = '<p>Having a <a rel="tag" class="p-category" href="/notes/tagged/beer">#beer</a> at the local. <span role="img" aria-label="beer mug">🍺</span></p>' . PHP_EOL;
$note = Note::find(11);
$this->assertEquals($expected, $note->note);
}
/**
* Look for a default image in the contacts h-card for the makeHCards method.
*
* @return void
*/
public function test_default_image_used_in_makehcards_method()
{
$expected = '<p>Hi <span class="u-category h-card">
<a class="mini-h-card u-url p-name" href="http://tantek.com">
<img class="u-photo" alt="" src="/assets/profile-images/default-image">
Tantek Çelik
</a>
<a class="u-url" href="https://twitter.com/t"></a></span></p>' . PHP_EOL;
$note = Note::find(12);
$this->assertEquals($expected, $note->note);
}
/**
* Look for a specific profile image in the contacts h-card.
*
* @return void
*/
public function test_specific_profile_image_used_in_makehcards_method()
{
$expected = '<p>Hi <span class="u-category h-card">
<a class="mini-h-card u-url p-name" href="https://aaronparecki.com">
<img class="u-photo" alt="" src="/assets/profile-images/aaronparecki.com/image">
Aaron Parecki
</a>
<a class="u-url" href="https://twitter.com/aaronpk"></a></span></p>' . PHP_EOL;
$note = Note::find(13);
$this->assertEquals($expected, $note->note);
}
/**
* Look for twitter URL when theres no associated contact.
*
* @return void
*/
public function test_twitter_link_created_when_no_contact_found()
{
$expected = '<p>Hi <a href="https://twitter.com/bob">@bob</a></p>' . PHP_EOL;
$note = Note::find(14);
$this->assertEquals($expected, $note->note);
}
}