diff --git a/modules/thunder_gqls/tests/src/Functional/RedirectSchemaTest.php b/modules/thunder_gqls/tests/src/Functional/RedirectSchemaTest.php index 46b8d0688..2a898cc97 100644 --- a/modules/thunder_gqls/tests/src/Functional/RedirectSchemaTest.php +++ b/modules/thunder_gqls/tests/src/Functional/RedirectSchemaTest.php @@ -28,6 +28,48 @@ protected function setUp(): void { $this->unpublishedEntity->set('moderation_state', 'unpublished')->save(); } + /** + * Test redirect to alias, depending on redirect settings. + */ + public function testAlias(): void { + $query = $this->getQueryFromFile('redirect'); + $path = '/node/' . $this->loadNodeByUuid('36b2e2b2-3df0-43eb-a282-d792b0999c07')->id(); + $variables = Json::encode(['path' => $path]); + + $this->config('redirect.settings') + ->set('route_normalizer_enabled', TRUE) + ->save(); + + $response = $this->query($query, $variables); + $this->assertEquals(200, $response->getStatusCode(), 'Response not 200'); + + $redirectResponseData = Json::decode($response->getBody())['data']['redirect']; + $expectedResponse = [ + 'url' => '/come-drupalcon-new-orleans', + 'status' => 301, + ]; + + $this->assertEqualsCanonicalizing($expectedResponse, $redirectResponseData, 'Not redirected to alias'); + + $this->config('redirect.settings') + ->set('route_normalizer_enabled', FALSE) + ->save(); + + // rebuild caches + $this->container->get('cache.graphql.results')->deleteAll(); + + $response = $this->query($query, $variables); + $this->assertEquals(200, $response->getStatusCode(), 'Response not 200'); + + $redirectResponseData = Json::decode($response->getBody())['data']['redirect']; + $expectedResponse = [ + 'url' => $path, + 'status' => 200, + ]; + + $this->assertEqualsCanonicalizing($expectedResponse, $redirectResponseData, 'False redirect to alias'); + } + /** * Tests the jsonld extension. * diff --git a/modules/thunder_gqls/tests/src/Kernel/DataProducer/ThunderRedirectTest.php b/modules/thunder_gqls/tests/src/Kernel/DataProducer/ThunderRedirectTest.php index cd72e851e..6e591dd06 100644 --- a/modules/thunder_gqls/tests/src/Kernel/DataProducer/ThunderRedirectTest.php +++ b/modules/thunder_gqls/tests/src/Kernel/DataProducer/ThunderRedirectTest.php @@ -49,6 +49,7 @@ public function setUp(): void { $this->node = Node::create([ 'title' => 'Title', 'type' => 'article', + 'path' => ['alias' => '/article'], ]); $this->node->save(); @@ -59,27 +60,28 @@ public function setUp(): void { * Test simple redirect and redirect with query string. */ public function testRedirect(): void { - $redirectPath = 'redirect-test-path'; + $redirectSource = 'redirect-test-source'; + $redirectDestination = '/redirect-test-destination'; /** @var \Drupal\redirect\Entity\Redirect $redirect */ $redirect = $this->storage->create(); - $redirect->setSource($redirectPath); - $redirect->setRedirect('node/' . $this->node->id()); + $redirect->setSource($redirectSource); + $redirect->setRedirect($redirectDestination); $redirect->setStatusCode(301); $redirect->save(); $result = $this->executeDataProducer('thunder_redirect', [ - 'path' => $redirectPath, + 'path' => $redirectSource, ]); - $this->assertEquals('/node/1', $result['url']); + $this->assertEquals($redirectDestination, $result['url']); $this->assertEquals('301', $result['status']); $result = $this->executeDataProducer('thunder_redirect', [ - 'path' => $redirectPath . '?test=1', + 'path' => $redirectSource . '?test=1', ]); - $this->assertEquals('/node/1?test=1', $result['url']); + $this->assertEquals($redirectDestination . '?test=1', $result['url']); $this->assertEquals('301', $result['status']); }