3 namespace Friendica\Test\src\Network;
5 use Friendica\Network\CurlResult;
6 use PHPUnit\Framework\TestCase;
8 class CurlResultTest extends TestCase
13 public function testNormal()
15 $header = file_get_contents(__DIR__ . '/../../datasets/curl/about.head');
16 $body = file_get_contents(__DIR__ . '/../../datasets/curl/about.body');
19 $curlResult = new CurlResult('https://test.local', $header . $body, [
21 'content_type' => 'text/html; charset=utf-8',
22 'url' => 'https://test.local'
25 $this->assertTrue($curlResult->isSuccess());
26 $this->assertFalse($curlResult->isTimeout());
27 $this->assertFalse($curlResult->isRedirectUrl());
28 $this->assertSame($header, $curlResult->getHeader());
29 $this->assertSame($body, $curlResult->getBody());
30 $this->assertSame('text/html; charset=utf-8', $curlResult->getContentType());
31 $this->assertSame('https://test.local', $curlResult->getUrl());
32 $this->assertSame('https://test.local', $curlResult->getRedirectUrl());
38 public function testRedirect()
40 $header = file_get_contents(__DIR__ . '/../../datasets/curl/about.head');
41 $body = file_get_contents(__DIR__ . '/../../datasets/curl/about.body');
44 $curlResult = new CurlResult('https://test.local/test/it', $header . $body, [
46 'content_type' => 'text/html; charset=utf-8',
47 'url' => 'https://test.local/test/it',
48 'redirect_url' => 'https://test.other'
51 $this->assertTrue($curlResult->isSuccess());
52 $this->assertFalse($curlResult->isTimeout());
53 $this->assertTrue($curlResult->isRedirectUrl());
54 $this->assertSame($header, $curlResult->getHeader());
55 $this->assertSame($body, $curlResult->getBody());
56 $this->assertSame('text/html; charset=utf-8', $curlResult->getContentType());
57 $this->assertSame('https://test.local/test/it', $curlResult->getUrl());
58 $this->assertSame('https://test.other/test/it', $curlResult->getRedirectUrl());
64 public function testTimeout()
66 $header = file_get_contents(__DIR__ . '/../../datasets/curl/about.head');
67 $body = file_get_contents(__DIR__ . '/../../datasets/curl/about.body');
70 $curlResult = new CurlResult('https://test.local/test/it', $header . $body, [
72 'content_type' => 'text/html; charset=utf-8',
73 'url' => 'https://test.local/test/it',
74 'redirect_url' => 'https://test.other'
75 ], CURLE_OPERATION_TIMEDOUT, 'Tested error');
77 $this->assertFalse($curlResult->isSuccess());
78 $this->assertTrue($curlResult->isTimeout());
79 $this->assertFalse($curlResult->isRedirectUrl());
80 $this->assertSame($header, $curlResult->getHeader());
81 $this->assertSame($body, $curlResult->getBody());
82 $this->assertSame('text/html; charset=utf-8', $curlResult->getContentType());
83 $this->assertSame('https://test.local/test/it', $curlResult->getRedirectUrl());
84 $this->assertSame('Tested error', $curlResult->getError());
90 public function testRedirectHeader()
92 $header = file_get_contents(__DIR__ . '/../../datasets/curl/about.redirect');
93 $body = file_get_contents(__DIR__ . '/../../datasets/curl/about.body');
96 $curlResult = new CurlResult('https://test.local/test/it?key=value', $header . $body, [
98 'content_type' => 'text/html; charset=utf-8',
99 'url' => 'https://test.local/test/it?key=value',
102 $this->assertTrue($curlResult->isSuccess());
103 $this->assertFalse($curlResult->isTimeout());
104 $this->assertTrue($curlResult->isRedirectUrl());
105 $this->assertSame($header, $curlResult->getHeader());
106 $this->assertSame($body, $curlResult->getBody());
107 $this->assertSame('text/html; charset=utf-8', $curlResult->getContentType());
108 $this->assertSame('https://test.local/test/it?key=value', $curlResult->getUrl());
109 $this->assertSame('https://test.other/some/?key=value', $curlResult->getRedirectUrl());