|
| 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\Framework\Module\Manager; |
| 10 | +use Magento\TestFramework\Helper\Bootstrap; |
| 11 | + |
| 12 | +/** |
| 13 | + * Class for RestSessionCookieTest |
| 14 | + */ |
| 15 | +class RestSessionCookieTest extends \Magento\TestFramework\TestCase\WebapiAbstract |
| 16 | +{ |
| 17 | + |
| 18 | + private $moduleManager; |
| 19 | + private $objectManager; |
| 20 | + |
| 21 | + /** |
| 22 | + * @inheritdoc |
| 23 | + */ |
| 24 | + protected function setUp(): void |
| 25 | + { |
| 26 | + $this->objectManager = Bootstrap::getObjectManager(); |
| 27 | + $this->moduleManager = $this->objectManager->get(Manager::class); |
| 28 | + if ($this->moduleManager->isEnabled('Magento_B2b')) { |
| 29 | + $this->markTestSkipped('Skipped, because this logic is rewritten on B2B.'); |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * Check for non exist cookie PHPSESSID |
| 35 | + */ |
| 36 | + public function testRestSessionNoCookie() |
| 37 | + { |
| 38 | + $this->_markTestAsRestOnly(); |
| 39 | + /** @var $curlClient CurlClientWithCookies */ |
| 40 | + |
| 41 | + $curlClient = $this->objectManager |
| 42 | + ->get(\Magento\TestFramework\TestCase\HttpClient\CurlClientWithCookies::class); |
| 43 | + $phpSessionCookieName = |
| 44 | + [ |
| 45 | + 'cookie_name' => 'PHPSESSID', |
| 46 | + ]; |
| 47 | + |
| 48 | + $response = $curlClient->get('/rest/V1/directory/countries', []); |
| 49 | + |
| 50 | + $cookie = $this->findCookie($phpSessionCookieName['cookie_name'], $response['cookies']); |
| 51 | + $this->assertNull($cookie); |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * Find cookie with given name in the list of cookies |
| 56 | + * |
| 57 | + * @param string $cookieName |
| 58 | + * @param array $cookies |
| 59 | + * @return $cookie|null |
| 60 | + * @SuppressWarnings(PHPMD.UnusedLocalVariable) |
| 61 | + */ |
| 62 | + private function findCookie($cookieName, $cookies) |
| 63 | + { |
| 64 | + foreach ($cookies as $cookieIndex => $cookie) { |
| 65 | + if ($cookie['name'] === $cookieName) { |
| 66 | + return $cookie; |
| 67 | + } |
| 68 | + } |
| 69 | + return null; |
| 70 | + } |
| 71 | +} |
0 commit comments