2017-06-03 13:06:30 +00:00
|
|
|
<?php
|
2017-11-17 01:23:18 +00:00
|
|
|
/** @license MIT
|
|
|
|
* Copyright 2017 J. King, Dustin Wilson et al.
|
|
|
|
* See LICENSE and AUTHORS files for details */
|
|
|
|
|
2017-06-03 13:06:30 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
namespace JKingWeb\Arsse;
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
use Phake;
|
2017-06-03 13:06:30 +00:00
|
|
|
|
2017-12-20 03:19:42 +00:00
|
|
|
/**
|
|
|
|
* @covers \JKingWeb\Arsse\Feed
|
2017-12-17 01:03:04 +00:00
|
|
|
* @group slow */
|
2017-07-08 01:06:38 +00:00
|
|
|
class TestFeedFetching extends Test\AbstractTest {
|
2017-06-03 13:06:30 +00:00
|
|
|
protected static $host = "http://localhost:8000/";
|
|
|
|
protected $base = "";
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function setUp() {
|
|
|
|
if (!extension_loaded('curl')) {
|
2017-06-03 13:06:30 +00:00
|
|
|
$this->markTestSkipped("Feed fetching tests are only accurate with curl enabled.");
|
2017-08-29 14:50:31 +00:00
|
|
|
} elseif (!@file_get_contents(self::$host."IsUp")) {
|
2017-06-03 13:06:30 +00:00
|
|
|
$this->markTestSkipped("Test Web server is not accepting requests");
|
|
|
|
}
|
|
|
|
$this->base = self::$host."Feed/";
|
|
|
|
$this->clearData();
|
2017-07-17 11:47:57 +00:00
|
|
|
Arsse::$conf = new Conf();
|
2017-06-03 13:06:30 +00:00
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testHandle400() {
|
2017-06-03 13:06:30 +00:00
|
|
|
$this->assertException("unsupportedFeedFormat", "Feed");
|
|
|
|
new Feed(null, $this->base."Fetching/Error?code=400");
|
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testHandle401() {
|
2017-06-03 13:06:30 +00:00
|
|
|
$this->assertException("unauthorized", "Feed");
|
|
|
|
new Feed(null, $this->base."Fetching/Error?code=401");
|
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testHandle403() {
|
2017-06-03 13:06:30 +00:00
|
|
|
$this->assertException("forbidden", "Feed");
|
|
|
|
new Feed(null, $this->base."Fetching/Error?code=403");
|
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testHandle404() {
|
2017-06-03 13:06:30 +00:00
|
|
|
$this->assertException("invalidUrl", "Feed");
|
|
|
|
new Feed(null, $this->base."Fetching/Error?code=404");
|
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testHandle500() {
|
2017-06-03 13:06:30 +00:00
|
|
|
$this->assertException("unsupportedFeedFormat", "Feed");
|
|
|
|
new Feed(null, $this->base."Fetching/Error?code=500");
|
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testHandleARedirectLoop() {
|
2017-06-03 13:06:30 +00:00
|
|
|
$this->assertException("maxRedirect", "Feed");
|
|
|
|
new Feed(null, $this->base."Fetching/EndlessLoop?i=0");
|
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testHandleAnOverlyLargeFeed() {
|
2017-07-17 11:47:57 +00:00
|
|
|
Arsse::$conf->fetchSizeLimit = 512;
|
2017-06-03 13:06:30 +00:00
|
|
|
$this->assertException("maxSize", "Feed");
|
|
|
|
new Feed(null, $this->base."Fetching/TooLarge");
|
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function testHandleACertificateError() {
|
2017-06-03 13:06:30 +00:00
|
|
|
$this->assertException("invalidCertificate", "Feed");
|
|
|
|
new Feed(null, "https://localhost:8000/");
|
|
|
|
}
|
2017-12-16 22:21:23 +00:00
|
|
|
|
|
|
|
public function testHandleATimeout() {
|
|
|
|
Arsse::$conf->fetchTimeout = 1;
|
|
|
|
$this->assertException("timeout", "Feed");
|
|
|
|
new Feed(null, $this->base."Fetching/Timeout");
|
|
|
|
}
|
2017-08-29 14:50:31 +00:00
|
|
|
}
|