Add Notes tests
This commit is contained in:
parent
c1e72be0c3
commit
ce19713c99
4 changed files with 233 additions and 0 deletions
71
tests/Unit/NotesControllerTest.php
Normal file
71
tests/Unit/NotesControllerTest.php
Normal 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
70
tests/Unit/NotesTest.php
Normal 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 contact’s 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 contact’s 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 there’s 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);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue