]> git.mxchange.org Git - friendica.git/blob - tests/src/Network/CurlResultTest.php
Merge pull request #6209 from MrPetovan/task/move-config-to-php-array
[friendica.git] / tests / src / Network / CurlResultTest.php
1 <?php
2
3 namespace Friendica\Test\src\Network;
4
5 use Friendica\Network\CurlResult;
6 use PHPUnit\Framework\TestCase;
7
8 class CurlResultTest extends TestCase
9 {
10         /**
11          * @small
12          */
13         public function testNormal()
14         {
15                 $header = file_get_contents(__DIR__ . '/../../datasets/curl/about.head');
16                 $body = file_get_contents(__DIR__ . '/../../datasets/curl/about.body');
17
18
19                 $curlResult = new CurlResult('https://test.local', $header . $body, [
20                         'http_code' => 200,
21                         'content_type' => 'text/html; charset=utf-8',
22                         'url' => 'https://test.local'
23                 ]);
24
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());
33         }
34
35         /**
36          * @small
37          */
38         public function testRedirect()
39         {
40                 $header = file_get_contents(__DIR__ . '/../../datasets/curl/about.head');
41                 $body = file_get_contents(__DIR__ . '/../../datasets/curl/about.body');
42
43
44                 $curlResult = new CurlResult('https://test.local/test/it', $header . $body, [
45                         'http_code' => 301,
46                         'content_type' => 'text/html; charset=utf-8',
47                         'url' => 'https://test.local/test/it',
48                         'redirect_url' => 'https://test.other'
49                 ]);
50
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());
59         }
60
61         /**
62          * @small
63          */
64         public function testTimeout()
65         {
66                 $header = file_get_contents(__DIR__ . '/../../datasets/curl/about.head');
67                 $body = file_get_contents(__DIR__ . '/../../datasets/curl/about.body');
68
69
70                 $curlResult = new CurlResult('https://test.local/test/it', $header . $body, [
71                         'http_code' => 500,
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');
76
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());
85         }
86
87         /**
88          * @small
89          */
90         public function testRedirectHeader()
91         {
92                 $header = file_get_contents(__DIR__ . '/../../datasets/curl/about.redirect');
93                 $body = file_get_contents(__DIR__ . '/../../datasets/curl/about.body');
94
95
96                 $curlResult = new CurlResult('https://test.local/test/it?key=value', $header . $body, [
97                         'http_code' => 301,
98                         'content_type' => 'text/html; charset=utf-8',
99                         'url' => 'https://test.local/test/it?key=value',
100                 ]);
101
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());
110         }
111 }