|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Drupal\Tests\jsonapi_frontend\Functional; |
| 6 | + |
| 7 | +use Drupal\node\Entity\Node; |
| 8 | +use Drupal\node\Entity\NodeType; |
| 9 | +use Drupal\Tests\BrowserTestBase; |
| 10 | +use Drupal\user\Entity\Role; |
| 11 | +use Drupal\user\RoleInterface; |
| 12 | + |
| 13 | +/** |
| 14 | + * Smoke tests for the settings form + resolver endpoint. |
| 15 | + * |
| 16 | + * @group jsonapi_frontend |
| 17 | + */ |
| 18 | +#[\PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses] |
| 19 | +final class SmokeTest extends BrowserTestBase { |
| 20 | + |
| 21 | + /** |
| 22 | + * {@inheritdoc} |
| 23 | + */ |
| 24 | + protected static $modules = [ |
| 25 | + 'system', |
| 26 | + 'user', |
| 27 | + 'field', |
| 28 | + 'text', |
| 29 | + 'filter', |
| 30 | + 'file', |
| 31 | + 'node', |
| 32 | + 'path', |
| 33 | + 'path_alias', |
| 34 | + 'serialization', |
| 35 | + 'jsonapi', |
| 36 | + 'jsonapi_frontend', |
| 37 | + ]; |
| 38 | + |
| 39 | + /** |
| 40 | + * {@inheritdoc} |
| 41 | + */ |
| 42 | + protected $defaultTheme = 'stark'; |
| 43 | + |
| 44 | + public function testSettingsSaveAndResolverResponse(): void { |
| 45 | + $anonymous = Role::load(RoleInterface::ANONYMOUS_ID); |
| 46 | + $anonymous?->grantPermission('access content'); |
| 47 | + $anonymous?->save(); |
| 48 | + |
| 49 | + NodeType::create([ |
| 50 | + 'type' => 'page', |
| 51 | + 'name' => 'Page', |
| 52 | + ])->save(); |
| 53 | + |
| 54 | + $node = Node::create([ |
| 55 | + 'type' => 'page', |
| 56 | + 'title' => 'About Us', |
| 57 | + 'status' => 1, |
| 58 | + 'path' => ['alias' => '/about-us'], |
| 59 | + ]); |
| 60 | + $node->save(); |
| 61 | + |
| 62 | + $admin = $this->createUser(['administer jsonapi frontend']); |
| 63 | + $this->drupalLogin($admin); |
| 64 | + |
| 65 | + $this->drupalGet('/admin/config/services/jsonapi-frontend'); |
| 66 | + $this->assertSession()->statusCodeEquals(200); |
| 67 | + |
| 68 | + $this->submitForm([ |
| 69 | + 'enable_all' => FALSE, |
| 70 | + 'headless_bundles[node][page]' => TRUE, |
| 71 | + 'resolver_cache_max_age' => 60, |
| 72 | + 'resolver_langcode_fallback' => 'site_default', |
| 73 | + ], 'Save configuration'); |
| 74 | + |
| 75 | + $this->assertSession()->statusCodeEquals(200); |
| 76 | + $this->assertSession()->pageTextContains('The configuration options have been saved.'); |
| 77 | + |
| 78 | + $this->drupalLogout(); |
| 79 | + |
| 80 | + $this->drupalGet('/jsonapi/resolve', [ |
| 81 | + 'query' => [ |
| 82 | + 'path' => '/about-us', |
| 83 | + '_format' => 'json', |
| 84 | + ], |
| 85 | + ]); |
| 86 | + $this->assertSession()->statusCodeEquals(200); |
| 87 | + |
| 88 | + $payload = json_decode($this->getSession()->getPage()->getContent(), TRUE); |
| 89 | + $this->assertIsArray($payload); |
| 90 | + $this->assertTrue($payload['resolved']); |
| 91 | + $this->assertSame('entity', $payload['kind']); |
| 92 | + $this->assertSame('node--page', $payload['entity']['type']); |
| 93 | + $this->assertSame($node->uuid(), $payload['entity']['id']); |
| 94 | + $this->assertSame(TRUE, $payload['headless']); |
| 95 | + $this->assertIsString($payload['jsonapi_url']); |
| 96 | + $this->assertStringContainsString('/jsonapi/node/page/', $payload['jsonapi_url']); |
| 97 | + } |
| 98 | + |
| 99 | +} |
0 commit comments