3 namespace Friendica\Test\src\Network;
5 use Friendica\Network\CurlResult;
6 use PHPUnit\Framework\TestCase;
8 class CurlResultTest extends TestCase
10 public function setUp()
14 require_once __DIR__.'/../../../boot.php';
15 require_once __DIR__.'/../../../include/text.php';
21 public function testNormal()
23 $header = file_get_contents(__DIR__ . '/../../datasets/curl/about.head');
24 $body = file_get_contents(__DIR__ . '/../../datasets/curl/about.body');
27 $curlResult = new CurlResult('https://test.local', $header . $body, [
29 'content_type' => 'text/html; charset=utf-8',
30 'url' => 'https://test.local'
33 $this->assertTrue($curlResult->isSuccess());
34 $this->assertFalse($curlResult->isTimeout());
35 $this->assertFalse($curlResult->isRedirectUrl());
36 $this->assertSame($header, $curlResult->getHeader());
37 $this->assertSame($body, $curlResult->getBody());
38 $this->assertSame('text/html; charset=utf-8', $curlResult->getContentType());
39 $this->assertSame('https://test.local', $curlResult->getUrl());
40 $this->assertSame('https://test.local', $curlResult->getRedirectUrl());
46 public function testRedirect()
48 $header = file_get_contents(__DIR__ . '/../../datasets/curl/about.head');
49 $body = file_get_contents(__DIR__ . '/../../datasets/curl/about.body');
52 $curlResult = new CurlResult('https://test.local/test/it', $header . $body, [
54 'content_type' => 'text/html; charset=utf-8',
55 'url' => 'https://test.local/test/it',
56 'redirect_url' => 'https://test.other'
59 $this->assertTrue($curlResult->isSuccess());
60 $this->assertFalse($curlResult->isTimeout());
61 $this->assertTrue($curlResult->isRedirectUrl());
62 $this->assertSame($header, $curlResult->getHeader());
63 $this->assertSame($body, $curlResult->getBody());
64 $this->assertSame('text/html; charset=utf-8', $curlResult->getContentType());
65 $this->assertSame('https://test.local/test/it', $curlResult->getUrl());
66 $this->assertSame('https://test.other/test/it', $curlResult->getRedirectUrl());
72 public function testTimeout()
74 $header = file_get_contents(__DIR__ . '/../../datasets/curl/about.head');
75 $body = file_get_contents(__DIR__ . '/../../datasets/curl/about.body');
78 $curlResult = new CurlResult('https://test.local/test/it', $header . $body, [
80 'content_type' => 'text/html; charset=utf-8',
81 'url' => 'https://test.local/test/it',
82 'redirect_url' => 'https://test.other'
83 ], CURLE_OPERATION_TIMEDOUT, 'Tested error');
85 $this->assertFalse($curlResult->isSuccess());
86 $this->assertTrue($curlResult->isTimeout());
87 $this->assertFalse($curlResult->isRedirectUrl());
88 $this->assertSame($header, $curlResult->getHeader());
89 $this->assertSame($body, $curlResult->getBody());
90 $this->assertSame('text/html; charset=utf-8', $curlResult->getContentType());
91 $this->assertSame('https://test.local/test/it', $curlResult->getRedirectUrl());
92 $this->assertSame('Tested error', $curlResult->getError());
98 public function testRedirectHeader()
100 $header = file_get_contents(__DIR__ . '/../../datasets/curl/about.redirect');
101 $body = file_get_contents(__DIR__ . '/../../datasets/curl/about.body');
104 $curlResult = new CurlResult('https://test.local/test/it?key=value', $header . $body, [
106 'content_type' => 'text/html; charset=utf-8',
107 'url' => 'https://test.local/test/it?key=value',
110 $this->assertTrue($curlResult->isSuccess());
111 $this->assertFalse($curlResult->isTimeout());
112 $this->assertTrue($curlResult->isRedirectUrl());
113 $this->assertSame($header, $curlResult->getHeader());
114 $this->assertSame($body, $curlResult->getBody());
115 $this->assertSame('text/html; charset=utf-8', $curlResult->getContentType());
116 $this->assertSame('https://test.local/test/it?key=value', $curlResult->getUrl());
117 $this->assertSame('https://test.other/some/?key=value', $curlResult->getRedirectUrl());