Skip to content

Commit

Permalink
Add failing test for redirects to aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
dbosen committed May 7, 2024
1 parent 4a89652 commit 2e793f8
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 7 deletions.
42 changes: 42 additions & 0 deletions modules/thunder_gqls/tests/src/Functional/RedirectSchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check failure on line 58 in modules/thunder_gqls/tests/src/Functional/RedirectSchemaTest.php

View workflow job for this annotation

GitHub Actions / drupal-coder (drupal)

[drupal-coder (drupal)] modules/thunder_gqls/tests/src/Functional/RedirectSchemaTest.php#L58 <Drupal.Commenting.InlineComment.NotCapital>

Inline comments must start with a capital letter
Raw output
/github/workspace/modules/thunder_gqls/tests/src/Functional/RedirectSchemaTest.php:58:5: error: Inline comments must start with a capital letter (Drupal.Commenting.InlineComment.NotCapital)

Check failure on line 58 in modules/thunder_gqls/tests/src/Functional/RedirectSchemaTest.php

View workflow job for this annotation

GitHub Actions / drupal-coder (drupal)

[drupal-coder (drupal)] modules/thunder_gqls/tests/src/Functional/RedirectSchemaTest.php#L58 <Drupal.Commenting.InlineComment.InvalidEndChar>

Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
Raw output
/github/workspace/modules/thunder_gqls/tests/src/Functional/RedirectSchemaTest.php:58:5: error: Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses (Drupal.Commenting.InlineComment.InvalidEndChar)
$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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function setUp(): void {
$this->node = Node::create([
'title' => 'Title',
'type' => 'article',
'path' => ['alias' => '/article'],
]);

$this->node->save();
Expand All @@ -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']);
}

Expand Down

0 comments on commit 2e793f8

Please sign in to comment.