2014-12-24 03:28:26 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace PicoFeed\Client;
|
|
|
|
|
|
|
|
use PHPUnit_Framework_TestCase;
|
|
|
|
|
|
|
|
class ClientTest extends PHPUnit_Framework_TestCase
|
|
|
|
{
|
2015-03-19 23:26:02 +01:00
|
|
|
/**
|
|
|
|
* @group online
|
|
|
|
*/
|
2014-12-24 03:28:26 +01:00
|
|
|
public function testDownload()
|
|
|
|
{
|
|
|
|
$client = Client::getInstance();
|
|
|
|
$client->setUrl('http://php.net/robots.txt');
|
|
|
|
$client->execute();
|
|
|
|
|
|
|
|
$this->assertTrue($client->isModified());
|
|
|
|
$this->assertNotEmpty($client->getContent());
|
|
|
|
$this->assertNotEmpty($client->getEtag());
|
|
|
|
$this->assertNotEmpty($client->getLastModified());
|
|
|
|
}
|
|
|
|
|
2015-03-01 19:56:11 +01:00
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
2015-03-19 23:26:02 +01:00
|
|
|
* @group online
|
2015-03-01 19:56:11 +01:00
|
|
|
*/
|
|
|
|
public function testPassthrough()
|
|
|
|
{
|
|
|
|
$client = Client::getInstance();
|
2015-08-02 20:08:21 +02:00
|
|
|
$client->setUrl('https://miniflux.net/favicon.ico');
|
2015-03-01 19:56:11 +01:00
|
|
|
$client->enablePassthroughMode();
|
|
|
|
$client->execute();
|
|
|
|
|
|
|
|
$this->expectOutputString(file_get_contents('tests/fixtures/miniflux_favicon.ico'));
|
|
|
|
}
|
2015-02-06 03:16:34 +01:00
|
|
|
|
2015-03-19 23:26:02 +01:00
|
|
|
/**
|
|
|
|
* @group online
|
|
|
|
*/
|
2014-12-24 03:28:26 +01:00
|
|
|
public function testCacheBothHaveToMatch()
|
|
|
|
{
|
|
|
|
$client = Client::getInstance();
|
|
|
|
$client->setUrl('http://php.net/robots.txt');
|
|
|
|
$client->execute();
|
|
|
|
$etag = $client->getEtag();
|
|
|
|
|
|
|
|
$client = Client::getInstance();
|
|
|
|
$client->setUrl('http://php.net/robots.txt');
|
|
|
|
$client->setEtag($etag);
|
|
|
|
$client->execute();
|
|
|
|
|
|
|
|
$this->assertTrue($client->isModified());
|
|
|
|
}
|
|
|
|
|
2015-03-19 23:26:02 +01:00
|
|
|
/**
|
|
|
|
* @group online
|
|
|
|
*/
|
2014-12-24 03:28:26 +01:00
|
|
|
public function testCacheEtag()
|
|
|
|
{
|
|
|
|
$client = Client::getInstance();
|
|
|
|
$client->setUrl('http://php.net/robots.txt');
|
|
|
|
$client->execute();
|
|
|
|
$etag = $client->getEtag();
|
|
|
|
$lastModified = $client->getLastModified();
|
|
|
|
|
|
|
|
$client = Client::getInstance();
|
|
|
|
$client->setUrl('http://php.net/robots.txt');
|
|
|
|
$client->setEtag($etag);
|
|
|
|
$client->setLastModified($lastModified);
|
|
|
|
$client->execute();
|
|
|
|
|
|
|
|
$this->assertFalse($client->isModified());
|
|
|
|
}
|
|
|
|
|
2015-03-19 23:26:02 +01:00
|
|
|
/**
|
|
|
|
* @group online
|
|
|
|
*/
|
2014-12-24 03:28:26 +01:00
|
|
|
public function testCacheLastModified()
|
|
|
|
{
|
|
|
|
$client = Client::getInstance();
|
|
|
|
$client->setUrl('http://miniflux.net/humans.txt');
|
|
|
|
$client->execute();
|
|
|
|
$lastmod = $client->getLastModified();
|
|
|
|
|
|
|
|
$client = Client::getInstance();
|
|
|
|
$client->setUrl('http://miniflux.net/humans.txt');
|
|
|
|
$client->setLastModified($lastmod);
|
|
|
|
$client->execute();
|
|
|
|
|
|
|
|
$this->assertFalse($client->isModified());
|
|
|
|
}
|
|
|
|
|
2015-03-19 23:26:02 +01:00
|
|
|
/**
|
|
|
|
* @group online
|
|
|
|
*/
|
2014-12-24 03:28:26 +01:00
|
|
|
public function testCacheBoth()
|
|
|
|
{
|
|
|
|
$client = Client::getInstance();
|
|
|
|
$client->setUrl('http://miniflux.net/humans.txt');
|
|
|
|
$client->execute();
|
|
|
|
$lastmod = $client->getLastModified();
|
|
|
|
$etag = $client->getEtag();
|
|
|
|
|
|
|
|
$client = Client::getInstance();
|
|
|
|
$client->setUrl('http://miniflux.net/humans.txt');
|
|
|
|
$client->setLastModified($lastmod);
|
|
|
|
$client->setEtag($etag);
|
|
|
|
$client->execute();
|
|
|
|
|
|
|
|
$this->assertFalse($client->isModified());
|
|
|
|
}
|
|
|
|
|
2015-03-19 23:26:02 +01:00
|
|
|
/**
|
|
|
|
* @group online
|
|
|
|
*/
|
2014-12-24 03:28:26 +01:00
|
|
|
public function testCharset()
|
|
|
|
{
|
|
|
|
$client = Client::getInstance();
|
|
|
|
$client->setUrl('http://php.net/');
|
|
|
|
$client->execute();
|
|
|
|
$this->assertEquals('utf-8', $client->getEncoding());
|
|
|
|
|
|
|
|
$client = Client::getInstance();
|
|
|
|
$client->setUrl('http://php.net/robots.txt');
|
|
|
|
$client->execute();
|
|
|
|
$this->assertEquals('', $client->getEncoding());
|
|
|
|
}
|
|
|
|
|
2015-03-19 23:26:02 +01:00
|
|
|
/**
|
|
|
|
* @group online
|
|
|
|
*/
|
2014-12-24 03:28:26 +01:00
|
|
|
public function testContentType()
|
|
|
|
{
|
|
|
|
$client = Client::getInstance();
|
|
|
|
$client->setUrl('http://miniflux.net/assets/img/favicon.png');
|
|
|
|
$client->execute();
|
|
|
|
$this->assertEquals('image/png', $client->getContentType());
|
|
|
|
|
|
|
|
$client = Client::getInstance();
|
|
|
|
$client->setUrl('http://miniflux.net/');
|
|
|
|
$client->execute();
|
|
|
|
$this->assertEquals('text/html; charset=utf-8', $client->getContentType());
|
|
|
|
}
|
|
|
|
}
|