Skip to content

Commit b219c4e

Browse files
engcom-KiloMaciej Pawłowski
authored and
Maciej Pawłowski
committed
Added test for API functional. Check for non exist cookie PHPSESSID, for non exist session of REST call.
1 parent cfa889e commit b219c4e

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Webapi;
8+
9+
use Magento\TestFramework\Helper\Bootstrap;
10+
11+
/**
12+
* Class for RestSessionCookieTest
13+
*/
14+
class RestSessionCookieTest extends \Magento\TestFramework\TestCase\WebapiAbstract
15+
{
16+
17+
/**
18+
* Check for non exist cookie PHPSESSID
19+
*/
20+
public function testRestNoAcceptHeader()
21+
{
22+
$this->_markTestAsRestOnly();
23+
/** @var $curlClient CurlClientWithCookies */
24+
25+
$curlClient = Bootstrap::getObjectManager()
26+
->get(\Magento\TestFramework\TestCase\HttpClient\CurlClientWithCookies::class);
27+
$phpSessionCookieName =
28+
[
29+
'cookie_name' => 'PHPSESSID',
30+
];
31+
32+
$response = $curlClient->get('/rest/V1/directory/countries', []);
33+
34+
$cookie = $this->findCookie($phpSessionCookieName['cookie_name'], $response['cookies']);
35+
$this->assertNull($cookie);
36+
}
37+
38+
/**
39+
* Find cookie with given name in the list of cookies
40+
*
41+
* @param string $cookieName
42+
* @param array $cookies
43+
* @return $cookie|null
44+
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
45+
*/
46+
private function findCookie($cookieName, $cookies)
47+
{
48+
foreach ($cookies as $cookieIndex => $cookie) {
49+
if ($cookie['name'] === $cookieName) {
50+
return $cookie;
51+
}
52+
}
53+
return null;
54+
}
55+
}

0 commit comments

Comments
 (0)