X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=tests%2Fsrc%2FNetwork%2FCurlResultTest.php;h=775c4179f3a7139f5891cf5f86ff0520f7e7d9bb;hb=83f187a047419c521717c1715825955a6c344244;hp=79b950ca181a1e15d40d118122ee18bbd79a6cd5;hpb=00bf0c24b6cc4a4a1ee88e180eeae01386b414b0;p=friendica.git diff --git a/tests/src/Network/CurlResultTest.php b/tests/src/Network/CurlResultTest.php index 79b950ca18..775c4179f3 100644 --- a/tests/src/Network/CurlResultTest.php +++ b/tests/src/Network/CurlResultTest.php @@ -7,24 +7,105 @@ use PHPUnit\Framework\TestCase; class CurlResultTest extends TestCase { - public function setUp() + /** + * @small + */ + public function testNormal() { - parent::setUp(); // TODO: Change the autogenerated stub + $header = file_get_contents(__DIR__ . '/../../datasets/curl/about.head'); + $body = file_get_contents(__DIR__ . '/../../datasets/curl/about.body'); + - require_once __DIR__.'/../../../boot.php'; - require_once __DIR__.'/../../../include/text.php'; + $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()); } - public function testNormal() + /** + * @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', $header . $body, [ 'http_code' => 200 ]); + $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()); } -} \ No newline at end of file +}