2017-11-10 17:02:59 +00:00
|
|
|
<?php
|
2017-11-17 01:51:03 +00:00
|
|
|
/** @license MIT
|
|
|
|
* Copyright 2017 J. King, Dustin Wilson et al.
|
|
|
|
* See LICENSE and AUTHORS files for details */
|
|
|
|
|
2017-11-10 17:02:59 +00:00
|
|
|
declare(strict_types=1);
|
2017-12-22 03:47:19 +00:00
|
|
|
namespace JKingWeb\Arsse\TestCase\REST\TinyTinyRSS;
|
2017-11-10 17:02:59 +00:00
|
|
|
|
2017-12-22 03:47:19 +00:00
|
|
|
use JKingWeb\Arsse\Arsse;
|
|
|
|
use JKingWeb\Arsse\Conf;
|
|
|
|
use JKingWeb\Arsse\User;
|
|
|
|
use JKingWeb\Arsse\Database;
|
|
|
|
use JKingWeb\Arsse\REST\TinyTinyRSS\Icon;
|
2017-11-10 17:02:59 +00:00
|
|
|
use JKingWeb\Arsse\REST\Request;
|
2018-01-04 04:13:08 +00:00
|
|
|
use Zend\Diactoros\Response\EmptyResponse as Response;
|
2017-11-10 17:02:59 +00:00
|
|
|
use Phake;
|
|
|
|
|
|
|
|
/** @covers \JKingWeb\Arsse\REST\TinyTinyRSS\Icon<extended> */
|
2017-12-22 03:47:19 +00:00
|
|
|
class TestIcon extends \JKingWeb\Arsse\Test\AbstractTest {
|
2017-11-10 17:02:59 +00:00
|
|
|
protected $h;
|
|
|
|
|
|
|
|
public function setUp() {
|
|
|
|
$this->clearData();
|
|
|
|
Arsse::$conf = new Conf();
|
|
|
|
// create a mock user manager
|
|
|
|
// create a mock database interface
|
|
|
|
Arsse::$db = Phake::mock(Database::class);
|
2017-12-22 03:47:19 +00:00
|
|
|
$this->h = new Icon();
|
2017-11-10 17:02:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function tearDown() {
|
|
|
|
$this->clearData();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRetrieveFavion() {
|
|
|
|
Phake::when(Arsse::$db)->subscriptionFavicon->thenReturn("");
|
|
|
|
Phake::when(Arsse::$db)->subscriptionFavicon(42)->thenReturn("http://example.com/favicon.ico");
|
|
|
|
Phake::when(Arsse::$db)->subscriptionFavicon(2112)->thenReturn("http://example.net/logo.png");
|
|
|
|
Phake::when(Arsse::$db)->subscriptionFavicon(1337)->thenReturn("http://example.org/icon.gif\r\nLocation: http://bad.example.com/");
|
|
|
|
// these requests should succeed
|
2018-01-04 04:13:08 +00:00
|
|
|
$exp = new Response(301, ['Location' => "http://example.com/favicon.ico"]);
|
|
|
|
$this->assertResponse($exp, $this->h->dispatch(new Request("GET", "42.ico")));
|
|
|
|
$exp = new Response(301, ['Location' => "http://example.net/logo.png"]);
|
|
|
|
$this->assertResponse($exp, $this->h->dispatch(new Request("GET", "2112.ico")));
|
|
|
|
$exp = new Response(301, ['Location' => "http://example.org/icon.gif"]);
|
|
|
|
$this->assertResponse($exp, $this->h->dispatch(new Request("GET", "1337.ico")));
|
2017-11-10 17:02:59 +00:00
|
|
|
// these requests should fail
|
|
|
|
$exp = new Response(404);
|
2018-01-04 04:13:08 +00:00
|
|
|
$this->assertResponse($exp, $this->h->dispatch(new Request("GET", "ook.ico")));
|
|
|
|
$this->assertResponse($exp, $this->h->dispatch(new Request("GET", "ook")));
|
|
|
|
$this->assertResponse($exp, $this->h->dispatch(new Request("GET", "47.ico")));
|
|
|
|
$this->assertResponse($exp, $this->h->dispatch(new Request("GET", "2112.png")));
|
2017-11-10 17:02:59 +00:00
|
|
|
// only GET is allowed
|
2018-01-04 04:13:08 +00:00
|
|
|
$exp = new Response(405, ['Allow' => "GET"]);
|
|
|
|
$this->assertResponse($exp, $this->h->dispatch(new Request("PUT", "2112.ico")));
|
2017-11-10 17:02:59 +00:00
|
|
|
}
|
|
|
|
}
|