Fix tests for the relocated createPhotoLink method

This commit is contained in:
Jonny Barnes 2017-06-22 16:41:27 +01:00
commit 005685ed42
3 changed files with 12 additions and 40 deletions

View file

@ -261,29 +261,6 @@ class Note extends Model
return; return;
} }
/*
* Get the relavent client name assocaited with the client id.
*
* @return string|null
*
public function getClientNameAttribute()
{
if ($this->client_id == null) {
return;
}
$name = MicropubClient::where('client_url', $this->client_id)->value('client_name');
if ($name == null) {
$url = parse_url($this->client_id);
if (isset($url['path'])) {
return $url['host'] . $url['path'];
}
return $url['host'];
}
return $name;
}*/
public function getTwitterAttribute() public function getTwitterAttribute()
{ {
if ($this->in_reply_to == null || mb_substr($this->in_reply_to, 0, 20, 'UTF-8') !== 'https://twitter.com/') { if ($this->in_reply_to == null || mb_substr($this->in_reply_to, 0, 20, 'UTF-8') !== 'https://twitter.com/') {

View file

@ -2,6 +2,7 @@
namespace App; namespace App;
use Cache;
use Twitter; use Twitter;
use HTMLPurifier; use HTMLPurifier;
use Carbon\Carbon; use Carbon\Carbon;

View file

@ -0,0 +1,65 @@
<?php
namespace Tests\Unit;
use Cache;
use App\WebMention;
use Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class WebMentionTest extends TestCase
{
/**
* Test a correct profile link is formed from a generic URL.
*
* @return void
*/
public function test_create_photo_link_with_non_cached_image()
{
$webmention = new WebMention();
$homepage = 'https://example.org/profile.png';
$expected = 'https://example.org/profile.png';
$this->assertEquals($expected, $webmention->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()
{
$webmention = new WebMention();
$homepage = 'https://aaronparecki.com/profile.png';
$expected = '/assets/profile-images/aaronparecki.com/image';
$this->assertEquals($expected, $webmention->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()
{
$webmention = new WebMention();
$twitterProfileImage = 'http://pbs.twimg.com/1234';
$expected = 'https://pbs.twimg.com/1234';
$this->assertEquals($expected, $webmention->createPhotoLink($twitterProfileImage));
}
/**
* Test `null` is returned for a twitter profile.
*
* @return void
*/
public function test_create_photo_link_with_cached_twitter_url()
{
$webmention = new WebMention();
$twitterURL = 'https://twitter.com/example';
$expected = 'https://pbs.twimg.com/static_profile_link.jpg';
Cache::put($twitterURL, $expected, 1);
$this->assertEquals($expected, $webmention->createPhotoLink($twitterURL));
}
}