2
2
3
3
namespace Drupal \Tests \graphql \Kernel \DataProducer ;
4
4
5
+ use Drupal \node \Entity \Node ;
6
+ use Drupal \node \Entity \NodeType ;
5
7
use Drupal \Tests \graphql \Kernel \GraphQLTestBase ;
6
8
7
9
/**
11
13
*/
12
14
class RoutingTest extends GraphQLTestBase {
13
15
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
+
14
35
/**
15
36
* @covers \Drupal\graphql\Plugin\GraphQL\DataProducer\Routing\RouteLoad::resolve
16
37
*/
@@ -21,6 +42,42 @@ public function testRouteLoad(): void {
21
42
22
43
$ this ->assertNotNull ($ result );
23
44
$ 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. ' );
24
81
}
25
82
26
83
/**
0 commit comments