jonnybarnes.uk/tests/Unit/BookmarksTest.php
Jonny Barnes 8b5b3204c1 Feature, upload media to S3 as part of micropub request
Squashed commit of the following:

commit 1f1175a4d944f573868dc2282e62fbd1b4e88b6a
Author: Jonny Barnes <jonny@jonnybarnes.uk>
Date:   Sun Apr 22 18:46:02 2018 +0100

    Fix file upload tests to reflect that we have now inlined the file upload to S3

commit 40d2af5b76e8f390d0275830390dd89ab4d12f54
Author: Jonny Barnes <jonny@jonnybarnes.uk>
Date:   Sun Apr 22 18:45:20 2018 +0100

    Markup the bookmrark test that uses puppeteer, doesn’t play nicely with my old MacBook and let’s me skip that one test

commit bbae1557c87d4d8f3b324abda1a6b8bf66acb8d8
Author: Jonny Barnes <jonny@jonnybarnes.uk>
Date:   Sun Apr 22 17:56:25 2018 +0100

    Inline the S3 upload for media

    Smaller images can then be uploaded by the ProcessMedia job. Inline-ing
    the upload prevents an S3 URL being sent that will initially 404.
2018-04-22 18:53:26 +01:00

62 lines
1.9 KiB
PHP

<?php
namespace Tests\Unit;
use Tests\TestCase;
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use App\Services\BookmarkService;
use GuzzleHttp\Handler\MockHandler;
class BookmarksTest extends TestCase
{
/**
* @group puppeteer
*/
public function test_screenshot_of_google()
{
$uuid = (new BookmarkService())->saveScreenshot('https://www.google.co.uk');
$this->assertTrue(file_exists(public_path() . '/assets/img/bookmarks/' . $uuid . '.png'));
}
public function test_archive_link_method()
{
$mock = new MockHandler([
new Response(200, ['Content-Location' => '/web/1234/example.org']),
]);
$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]);
$this->app->instance(Client::class, $client);
$url = (new BookmarkService())->getArchiveLink('https://example.org');
$this->assertEquals('/web/1234/example.org', $url);
}
/**
* @expectedException App\Exceptions\InternetArchiveException
*/
public function test_archive_link_method_archive_site_error_exception()
{
$mock = new MockHandler([
new Response(403),
]);
$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]);
$this->app->instance(Client::class, $client);
$url = (new BookmarkService())->getArchiveLink('https://example.org');
}
/**
* @expectedException App\Exceptions\InternetArchiveException
*/
public function test_archive_link_method_archive_site_no_location_exception()
{
$mock = new MockHandler([
new Response(200),
]);
$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]);
$this->app->instance(Client::class, $client);
$url = (new BookmarkService())->getArchiveLink('https://example.org');
}
}