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