Skip to content

Commit

Permalink
Updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pmzandbergen committed Aug 30, 2020
1 parent 9db1f83 commit e912bdf
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 163 deletions.
53 changes: 53 additions & 0 deletions lib/internal/Magento/Framework/HTTP/Test/Unit/Client/CurlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,57 @@ public function testInvalidProtocol()
$client = new Curl();
$client->get('telnet://127.0.0.1/test');
}

/**
* Check the HTTP client ability to parse headers case-insensitive.
*/
public function testParseHeaders()
{
// Prepare protected parseHeaders method
$curl = new Curl();
$parseHeaders = new \ReflectionMethod(
$curl,
'parseHeaders'
);
$parseHeaders->setAccessible(true);

// Parse headers
foreach ($this->headersDataProvider() as $header) {
$parseHeaders->invoke($curl, null, $header);
}

// Validate headers
$headers = $curl->getHeaders();
$this->assertIsArray($headers);
$this->assertEquals([
'Content-Type' => 'text/html; charset=utf-8',
'Set-Cookie' => [
'Normal=OK',
'Uppercase=OK',
'Lowercase=OK',
]
], $headers);

// Validate status
$status = $curl->getStatus();
$this->assertIsInt($status);
$this->assertEquals(200, $status);

// Validate cookies
$cookies = $curl->getCookies();
$this->assertIsArray($cookies);
$this->assertEquals([
'Normal' => 'OK',
'Uppercase' => 'OK',
'Lowercase' => 'OK',
], $cookies);
}

/**
* @return array
*/
public function headersDataProvider()
{
return array_filter(explode(PHP_EOL, file_get_contents(__DIR__ . '/_files/curl_headers.txt')));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Status: 200 OK
Content-Type: text/html; charset=utf-8
Set-Cookie: Normal=OK
SET-COOKIE: Uppercase=OK
set-cookie: Lowercase=OK

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit e912bdf

Please sign in to comment.