mirror of
https://github.com/friendica/friendica
synced 2025-04-26 02:30:11 +00:00
CurlResult Tests & RegEx fix
This commit is contained in:
parent
00bf0c24b6
commit
b099cba4b4
3 changed files with 116 additions and 5 deletions
|
@ -9,22 +9,111 @@ class CurlResultTest extends TestCase
|
|||
{
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp(); // TODO: Change the autogenerated stub
|
||||
parent::setUp();
|
||||
|
||||
require_once __DIR__.'/../../../boot.php';
|
||||
require_once __DIR__.'/../../../include/text.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @small
|
||||
*/
|
||||
public function testNormal()
|
||||
{
|
||||
$header = file_get_contents(__DIR__ . '/../../datasets/curl/about.head');
|
||||
$body = file_get_contents(__DIR__ . '/../../datasets/curl/about.body');
|
||||
|
||||
|
||||
$curlResult = new CurlResult('https://test.local', $header . $body, [ 'http_code' => 200 ]);
|
||||
$curlResult = new CurlResult('https://test.local', $header . $body, [
|
||||
'http_code' => 200,
|
||||
'content_type' => 'text/html; charset=utf-8',
|
||||
'url' => 'https://test.local'
|
||||
]);
|
||||
|
||||
$this->assertTrue($curlResult->isSuccess());
|
||||
$this->assertFalse($curlResult->isTimeout());
|
||||
$this->assertFalse($curlResult->isRedirectUrl());
|
||||
$this->assertSame($header, $curlResult->getHeader());
|
||||
$this->assertSame($body, $curlResult->getBody());
|
||||
$this->assertSame('text/html; charset=utf-8', $curlResult->getContentType());
|
||||
$this->assertSame('https://test.local', $curlResult->getUrl());
|
||||
$this->assertSame('https://test.local', $curlResult->getRedirectUrl());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @small
|
||||
*/
|
||||
public function testRedirect()
|
||||
{
|
||||
$header = file_get_contents(__DIR__ . '/../../datasets/curl/about.head');
|
||||
$body = file_get_contents(__DIR__ . '/../../datasets/curl/about.body');
|
||||
|
||||
|
||||
$curlResult = new CurlResult('https://test.local/test/it', $header . $body, [
|
||||
'http_code' => 301,
|
||||
'content_type' => 'text/html; charset=utf-8',
|
||||
'url' => 'https://test.local/test/it',
|
||||
'redirect_url' => 'https://test.other'
|
||||
]);
|
||||
|
||||
$this->assertTrue($curlResult->isSuccess());
|
||||
$this->assertFalse($curlResult->isTimeout());
|
||||
$this->assertTrue($curlResult->isRedirectUrl());
|
||||
$this->assertSame($header, $curlResult->getHeader());
|
||||
$this->assertSame($body, $curlResult->getBody());
|
||||
$this->assertSame('text/html; charset=utf-8', $curlResult->getContentType());
|
||||
$this->assertSame('https://test.local/test/it', $curlResult->getUrl());
|
||||
$this->assertSame('https://test.other/test/it', $curlResult->getRedirectUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
* @small
|
||||
*/
|
||||
public function testTimeout()
|
||||
{
|
||||
$header = file_get_contents(__DIR__ . '/../../datasets/curl/about.head');
|
||||
$body = file_get_contents(__DIR__ . '/../../datasets/curl/about.body');
|
||||
|
||||
|
||||
$curlResult = new CurlResult('https://test.local/test/it', $header . $body, [
|
||||
'http_code' => 500,
|
||||
'content_type' => 'text/html; charset=utf-8',
|
||||
'url' => 'https://test.local/test/it',
|
||||
'redirect_url' => 'https://test.other'
|
||||
], CURLE_OPERATION_TIMEDOUT, 'Tested error');
|
||||
|
||||
$this->assertFalse($curlResult->isSuccess());
|
||||
$this->assertTrue($curlResult->isTimeout());
|
||||
$this->assertFalse($curlResult->isRedirectUrl());
|
||||
$this->assertSame($header, $curlResult->getHeader());
|
||||
$this->assertSame($body, $curlResult->getBody());
|
||||
$this->assertSame('text/html; charset=utf-8', $curlResult->getContentType());
|
||||
$this->assertSame('https://test.local/test/it', $curlResult->getRedirectUrl());
|
||||
$this->assertSame('Tested error', $curlResult->getError());
|
||||
}
|
||||
|
||||
/**
|
||||
* @small
|
||||
*/
|
||||
public function testRedirectHeader()
|
||||
{
|
||||
$header = file_get_contents(__DIR__ . '/../../datasets/curl/about.redirect');
|
||||
$body = file_get_contents(__DIR__ . '/../../datasets/curl/about.body');
|
||||
|
||||
|
||||
$curlResult = new CurlResult('https://test.local/test/it?key=value', $header . $body, [
|
||||
'http_code' => 301,
|
||||
'content_type' => 'text/html; charset=utf-8',
|
||||
'url' => 'https://test.local/test/it?key=value',
|
||||
]);
|
||||
|
||||
$this->assertTrue($curlResult->isSuccess());
|
||||
$this->assertFalse($curlResult->isTimeout());
|
||||
$this->assertTrue($curlResult->isRedirectUrl());
|
||||
$this->assertSame($header, $curlResult->getHeader());
|
||||
$this->assertSame($body, $curlResult->getBody());
|
||||
$this->assertSame('text/html; charset=utf-8', $curlResult->getContentType());
|
||||
$this->assertSame('https://test.local/test/it?key=value', $curlResult->getUrl());
|
||||
$this->assertSame('https://test.other/some/?key=value', $curlResult->getRedirectUrl());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue