jonnybarnes.uk/tests/Unit/WebMentionTest.php

66 lines
2 KiB
PHP
Raw Normal View History

2017-02-18 16:38:18 +00:00
<?php
namespace Tests\Unit;
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;
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()
{
$webmention = new WebMention();
2017-02-18 16:38:18 +00:00
$homepage = 'https://example.org/profile.png';
$expected = 'https://example.org/profile.png';
$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()
{
$webmention = new WebMention();
2017-02-18 16:38:18 +00:00
$homepage = 'https://aaronparecki.com/profile.png';
$expected = '/assets/profile-images/aaronparecki.com/image';
$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()
{
$webmention = new WebMention();
2017-02-18 16:38:18 +00:00
$twitterProfileImage = 'http://pbs.twimg.com/1234';
$expected = 'https://pbs.twimg.com/1234';
$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()
{
$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);
$this->assertEquals($expected, $webmention->createPhotoLink($twitterURL));
2017-02-18 16:38:18 +00:00
}
}