|
| 1 | +<?php |
| 2 | +/************************************************************************ |
| 3 | + * |
| 4 | + * Copyright 2023 Adobe |
| 5 | + * All Rights Reserved. |
| 6 | + * |
| 7 | + * NOTICE: All information contained herein is, and remains |
| 8 | + * the property of Adobe and its suppliers, if any. The intellectual |
| 9 | + * and technical concepts contained herein are proprietary to Adobe |
| 10 | + * and its suppliers and are protected by all applicable intellectual |
| 11 | + * property laws, including trade secret and copyright laws. |
| 12 | + * Dissemination of this information or reproduction of this material |
| 13 | + * is strictly forbidden unless prior written permission is obtained |
| 14 | + * from Adobe. |
| 15 | + * ************************************************************************ |
| 16 | + */ |
| 17 | +declare(strict_types=1); |
| 18 | + |
| 19 | +namespace Magento\GraphQlCache\Controller\Plugin; |
| 20 | + |
| 21 | +use Magento\Framework\App\Request\Http as HttpRequest; |
| 22 | +use Magento\Framework\App\Response\HttpInterface as HttpResponse; |
| 23 | +use Magento\Customer\Test\Fixture\Customer; |
| 24 | +use Magento\GraphQl\Controller\GraphQl as GraphQlController; |
| 25 | +use Magento\TestFramework\Fixture\DataFixture; |
| 26 | +use Magento\TestFramework\Fixture\DataFixtureStorageManager; |
| 27 | +use Magento\TestFramework\Helper\Bootstrap; |
| 28 | +use PHPUnit\Framework\TestCase; |
| 29 | + |
| 30 | +class GraphQlTest extends TestCase |
| 31 | +{ |
| 32 | + #[ |
| 33 | + DataFixture(Customer::class, as: 'customer'), |
| 34 | + ] |
| 35 | + public function testMutation(): void |
| 36 | + { |
| 37 | + /** @var \Magento\Customer\Model\Customer $customer */ |
| 38 | + $customer = DataFixtureStorageManager::getStorage()->get('customer'); |
| 39 | + |
| 40 | + $response = $this->dispatch( |
| 41 | + [ |
| 42 | + 'query' => sprintf( |
| 43 | + 'mutation {generateCustomerToken(email:"%s",password:"%s"){token}}', |
| 44 | + $customer->getEmail(), |
| 45 | + $customer->getPassword() |
| 46 | + ) |
| 47 | + ] |
| 48 | + ); |
| 49 | + |
| 50 | + $this->assertEquals('no-cache', $response->getHeader('pragma')); |
| 51 | + $this->assertEquals('no-store, no-cache, must-revalidate, max-age=0', $response->getHeader('cache-control')); |
| 52 | + } |
| 53 | + |
| 54 | + private function dispatch(array $params): HttpResponse |
| 55 | + { |
| 56 | + $objectManager = Bootstrap::getObjectManager(); |
| 57 | + /** @var HttpRequest $request */ |
| 58 | + $request = $objectManager->create(HttpRequest::class); |
| 59 | + $request->setPathInfo('/graphql'); |
| 60 | + $request->setMethod('POST'); |
| 61 | + $request->setParams($params); |
| 62 | + |
| 63 | + // required for \Magento\Framework\App\PageCache\Identifier to generate the correct cache key |
| 64 | + $request->setUri(implode('?', [$request->getPathInfo(), http_build_query($params)])); |
| 65 | + |
| 66 | + return $objectManager->get(GraphQlController::class)->dispatch($request); |
| 67 | + } |
| 68 | +} |
0 commit comments