22
33namespace Drupal \Tests \graphql \Kernel \DataProducer ;
44
5+ use Drupal \node \Entity \Node ;
6+ use Drupal \node \Entity \NodeType ;
57use Drupal \Tests \graphql \Kernel \GraphQLTestBase ;
68
79/**
1113 */
1214class RoutingTest extends GraphQLTestBase {
1315
16+ /**
17+ * {@inheritdoc}
18+ */
19+ protected static $ modules = [
20+ 'redirect ' ,
21+ 'views ' ,
22+ 'path_alias ' ,
23+ ];
24+
25+ /**
26+ * {@inheritdoc}
27+ */
28+ public function setUp (): void {
29+ parent ::setUp ();
30+
31+ $ this ->installEntitySchema ('redirect ' );
32+ $ this ->installConfig (['redirect ' ]);
33+ }
34+
1435 /**
1536 * @covers \Drupal\graphql\Plugin\GraphQL\DataProducer\Routing\RouteLoad::resolve
1637 */
@@ -21,6 +42,42 @@ public function testRouteLoad(): void {
2142
2243 $ this ->assertNotNull ($ result );
2344 $ this ->assertEquals ('user.logout ' , $ result ->getRouteName ());
45+
46+ // Test route_load with redirect to an internal URL.
47+ NodeType::create ([
48+ 'type ' => 'test ' ,
49+ 'name ' => 'Test ' ,
50+ ])->save ();
51+ $ node = Node::create ([
52+ 'title ' => 'Node ' ,
53+ 'type ' => 'test ' ,
54+ ]);
55+ $ node ->save ();
56+ $ nodeUrl = $ node ->toUrl ()->toString ();
57+
58+ /** @var \Drupal\redirect\Entity\Redirect $redirect */
59+ $ redirect = $ this ->container ->get ('entity_type.manager ' )->getStorage ('redirect ' )->create ();
60+ $ redirect ->setSource ('internal-url ' );
61+ $ redirect ->setRedirect ($ nodeUrl );
62+ $ redirect ->save ();
63+
64+ /** @var \Drupal\Core\Url $result */
65+ $ result = $ this ->executeDataProducer ('route_load ' , [
66+ 'path ' => 'internal-url ' ,
67+ ]);
68+
69+ $ this ->assertNotNull ($ result );
70+ $ this ->assertEquals ($ nodeUrl , $ result ->toString ());
71+
72+ $ redirect ->setSource ('external-url ' );
73+ $ redirect ->setRedirect ('https://example.com ' );
74+ $ redirect ->save ();
75+
76+ $ result = $ this ->executeDataProducer ('route_load ' , [
77+ 'path ' => 'external-url ' ,
78+ ]);
79+
80+ $ this ->assertNull ($ result , 'Route to external URL should not be found. ' );
2481 }
2582
2683 /**
0 commit comments