X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=tests%2Fsrc%2FNetwork%2FCurlResultTest.php;h=03e415a99b45a6b32f56765425b24436c9d55708;hb=36ba7fa79c7c2d4304f3423d84215771e3bb6a9f;hp=775c4179f3a7139f5891cf5f86ff0520f7e7d9bb;hpb=acaee626f5f23f4c1dc19c31896a0797a251b58f;p=friendica.git diff --git a/tests/src/Network/CurlResultTest.php b/tests/src/Network/CurlResultTest.php index 775c4179f3..03e415a99b 100644 --- a/tests/src/Network/CurlResultTest.php +++ b/tests/src/Network/CurlResultTest.php @@ -2,11 +2,33 @@ namespace Friendica\Test\src\Network; +use Dice\Dice; +use Friendica\BaseObject; use Friendica\Network\CurlResult; +use Mockery\MockInterface; use PHPUnit\Framework\TestCase; +use Psr\Log\LoggerInterface; +use Psr\Log\NullLogger; class CurlResultTest extends TestCase { + protected function setUp() + { + parent::setUp(); + + + /** @var Dice|MockInterface $dice */ + $dice = \Mockery::mock(Dice::class)->makePartial(); + $dice = $dice->addRules(include __DIR__ . '/../../../static/dependencies.config.php'); + + $logger = new NullLogger(); + $dice->shouldReceive('create') + ->with(LoggerInterface::class) + ->andReturn($logger); + + BaseObject::setDependencyInjection($dice); + } + /** * @small */ @@ -34,6 +56,8 @@ class CurlResultTest extends TestCase /** * @small + * @runInSeparateProcess + * @preserveGlobalState disabled */ public function testRedirect() { @@ -86,6 +110,8 @@ class CurlResultTest extends TestCase /** * @small + * @runInSeparateProcess + * @preserveGlobalState disabled */ public function testRedirectHeader() { @@ -108,4 +134,59 @@ class CurlResultTest extends TestCase $this->assertSame('https://test.local/test/it?key=value', $curlResult->getUrl()); $this->assertSame('https://test.other/some/?key=value', $curlResult->getRedirectUrl()); } + + /** + * @small + */ + public function testInHeader() + { + $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, + 'content_type' => 'text/html; charset=utf-8', + 'url' => 'https://test.local' + ]); + $this->assertTrue($curlResult->inHeader('vary')); + $this->assertFalse($curlResult->inHeader('wrongHeader')); + } + + /** + * @small + */ + public function testGetHeaderArray() + { + $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, + 'content_type' => 'text/html; charset=utf-8', + 'url' => 'https://test.local' + ]); + + $headers = $curlResult->getHeaderArray(); + + $this->assertNotEmpty($headers); + $this->assertArrayHasKey('vary', $headers); + } + + /** + * @small + */ + public function testGetHeaderWithParam() + { + $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, + 'content_type' => 'text/html; charset=utf-8', + 'url' => 'https://test.local' + ]); + + $this->assertNotEmpty($curlResult->getHeader()); + $this->assertEmpty($curlResult->getHeader('wrongHeader')); + } }