]> git.mxchange.org Git - friendica.git/blobdiff - tests/src/Network/CurlResultTest.php
Tests added
[friendica.git] / tests / src / Network / CurlResultTest.php
index b542371b3922432eda53ae84e2cb82e318de256c..62c21fa3fc78961f9708ab05250a10ac05a69da6 100644 (file)
@@ -2,10 +2,13 @@
 
 namespace Friendica\Test\src\Network;
 
-use Friendica\Core\Logger;
+use Dice\Dice;
+use Friendica\BaseObject;
 use Friendica\Network\CurlResult;
-use Friendica\Util\Logger\VoidLogger;
+use Mockery\MockInterface;
 use PHPUnit\Framework\TestCase;
+use Psr\Log\LoggerInterface;
+use Psr\Log\NullLogger;
 
 class CurlResultTest extends TestCase
 {
@@ -13,7 +16,17 @@ class CurlResultTest extends TestCase
        {
                parent::setUp();
 
-               Logger::init(new VoidLogger());
+
+               /** @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);
        }
 
        /**
@@ -121,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('vary', $curlResult->getHeader('wrongHeader'));
+       }
 }