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());
37 * @runInSeparateProcess
38 * @preserveGlobalState disabled
40 public function testRedirect()
42 $header = file_get_contents(__DIR__ . '/../../datasets/curl/about.head');
43 $body = file_get_contents(__DIR__ . '/../../datasets/curl/about.body');
46 $curlResult = new CurlResult('https://test.local/test/it', $header . $body, [
48 'content_type' => 'text/html; charset=utf-8',
49 'url' => 'https://test.local/test/it',
50 'redirect_url' => 'https://test.other'
53 $this->assertTrue($curlResult->isSuccess());
54 $this->assertFalse($curlResult->isTimeout());
55 $this->assertTrue($curlResult->isRedirectUrl());
56 $this->assertSame($header, $curlResult->getHeader());
57 $this->assertSame($body, $curlResult->getBody());
58 $this->assertSame('text/html; charset=utf-8', $curlResult->getContentType());
59 $this->assertSame('https://test.local/test/it', $curlResult->getUrl());
60 $this->assertSame('https://test.other/test/it', $curlResult->getRedirectUrl());
66 public function testTimeout()
68 $header = file_get_contents(__DIR__ . '/../../datasets/curl/about.head');
69 $body = file_get_contents(__DIR__ . '/../../datasets/curl/about.body');
72 $curlResult = new CurlResult('https://test.local/test/it', $header . $body, [
74 'content_type' => 'text/html; charset=utf-8',
75 'url' => 'https://test.local/test/it',
76 'redirect_url' => 'https://test.other'
77 ], CURLE_OPERATION_TIMEDOUT, 'Tested error');
79 $this->assertFalse($curlResult->isSuccess());
80 $this->assertTrue($curlResult->isTimeout());
81 $this->assertFalse($curlResult->isRedirectUrl());
82 $this->assertSame($header, $curlResult->getHeader());
83 $this->assertSame($body, $curlResult->getBody());
84 $this->assertSame('text/html; charset=utf-8', $curlResult->getContentType());
85 $this->assertSame('https://test.local/test/it', $curlResult->getRedirectUrl());
86 $this->assertSame('Tested error', $curlResult->getError());
91 * @runInSeparateProcess
92 * @preserveGlobalState disabled
94 public function testRedirectHeader()
96 $header = file_get_contents(__DIR__ . '/../../datasets/curl/about.redirect');
97 $body = file_get_contents(__DIR__ . '/../../datasets/curl/about.body');
100 $curlResult = new CurlResult('https://test.local/test/it?key=value', $header . $body, [
102 'content_type' => 'text/html; charset=utf-8',
103 'url' => 'https://test.local/test/it?key=value',
106 $this->assertTrue($curlResult->isSuccess());
107 $this->assertFalse($curlResult->isTimeout());
108 $this->assertTrue($curlResult->isRedirectUrl());
109 $this->assertSame($header, $curlResult->getHeader());
110 $this->assertSame($body, $curlResult->getBody());
111 $this->assertSame('text/html; charset=utf-8', $curlResult->getContentType());
112 $this->assertSame('https://test.local/test/it?key=value', $curlResult->getUrl());
113 $this->assertSame('https://test.other/some/?key=value', $curlResult->getRedirectUrl());