@@ -29,6 +29,7 @@ public function setUp() {
29
29
]);
30
30
$ content_type ->save ();
31
31
32
+ // Published node and published translations.
32
33
$ this ->published_node = Node::create ([
33
34
'title ' => 'Test Event ' ,
34
35
'type ' => 'event ' ,
@@ -42,6 +43,7 @@ public function setUp() {
42
43
$ this ->translation_de_published = $ this ->published_node ->addTranslation ('de ' , ['title ' => 'Test Event DE ' ]);
43
44
$ this ->translation_de_published ->save ();
44
45
46
+ // Unpublished node and unpublished translations.
45
47
$ this ->unpublished_node = Node::create ([
46
48
'title ' => 'Test Unpublished Event ' ,
47
49
'type ' => 'event ' ,
@@ -50,18 +52,53 @@ public function setUp() {
50
52
$ this ->unpublished_node ->save ();
51
53
52
54
$ this ->translation_fr_unpublished = $ this ->unpublished_node ->addTranslation ('fr ' , ['title ' => 'Test Unpublished Event FR ' ]);
55
+ $ this ->translation_fr_unpublished ->status = NodeInterface::NOT_PUBLISHED ;
53
56
$ this ->translation_fr_unpublished ->save ();
54
57
55
58
$ this ->translation_de_unpublished = $ this ->unpublished_node ->addTranslation ('de ' , ['title ' => 'Test Unpublished Event DE ' ]);
59
+ $ this ->translation_de_unpublished ->status = NodeInterface::NOT_PUBLISHED ;
56
60
$ this ->translation_de_unpublished ->save ();
57
61
62
+ // Unpublished node to published translations.
63
+ $ this ->unpublished_to_published_node = Node::create ([
64
+ 'title ' => 'Test Unpublished to Published Event ' ,
65
+ 'type ' => 'event ' ,
66
+ 'status ' => NodeInterface::NOT_PUBLISHED ,
67
+ ]);
68
+ $ this ->unpublished_to_published_node ->save ();
69
+
70
+ $ this ->translation_fr_unpublished_to_published = $ this ->unpublished_to_published_node ->addTranslation ('fr ' , ['title ' => 'Test Unpublished to Published Event FR ' ]);
71
+ $ this ->translation_fr_unpublished_to_published ->status = NodeInterface::PUBLISHED ;
72
+ $ this ->translation_fr_unpublished_to_published ->save ();
73
+
74
+ $ this ->translation_de_unpublished_to_published = $ this ->unpublished_to_published_node ->addTranslation ('de ' , ['title ' => 'Test Unpublished to Published Event DE ' ]);
75
+ $ this ->translation_de_unpublished_to_published ->status = NodeInterface::PUBLISHED ;
76
+ $ this ->translation_de_unpublished_to_published ->save ();
77
+
78
+ // Published node to unpublished translations.
79
+ $ this ->published_to_unpublished_node = Node::create ([
80
+ 'title ' => 'Test Published to Unpublished Event ' ,
81
+ 'type ' => 'event ' ,
82
+ 'status ' => NodeInterface::PUBLISHED ,
83
+ ]);
84
+ $ this ->published_to_unpublished_node ->save ();
85
+
86
+ $ this ->translation_fr_published_to_unpublished = $ this ->published_to_unpublished_node ->addTranslation ('fr ' , ['title ' => 'Test Published to Unpublished Event FR ' ]);
87
+ $ this ->translation_fr_published_to_unpublished ->status = NodeInterface::NOT_PUBLISHED ;
88
+ $ this ->translation_fr_published_to_unpublished ->save ();
89
+
90
+ $ this ->translation_de_published_to_unpublished = $ this ->published_to_unpublished_node ->addTranslation ('de ' , ['title ' => 'Test Published to Unpublished Event DE ' ]);
91
+ $ this ->translation_de_published_to_unpublished ->status = NodeInterface::NOT_PUBLISHED ;
92
+ $ this ->translation_de_published_to_unpublished ->save ();
93
+
58
94
\Drupal::service ('content_translation.manager ' )->setEnabled ('node ' , 'event ' , TRUE );
59
95
}
60
96
61
97
/**
62
98
* @covers \Drupal\graphql\Plugin\GraphQL\DataProducer\Routing\RouteEntity::resolve
63
99
*/
64
100
public function testRouteEntity () {
101
+ // Published node to published translations.
65
102
$ url = Url::fromRoute ('entity.node.canonical ' , ['node ' => $ this ->published_node ->id ()]);
66
103
67
104
$ result = $ this ->executeDataProducer ('route_entity ' , [
@@ -87,8 +124,8 @@ public function testRouteEntity() {
87
124
$ this ->assertEquals ($ this ->translation_de_published ->id (), $ result ->id ());
88
125
$ this ->assertEquals ($ this ->translation_de_published ->label (), $ result ->label ());
89
126
90
- // Make sure we are not allowed to get the unpublished nodes or
91
- // translations.
127
+ // Unpublished node to unpublished translations. Make sure we are not
128
+ // allowed to get the unpublished nodes or translations.
92
129
$ url = Url::fromRoute ('entity.node.canonical ' , ['node ' => $ this ->unpublished_node ->id ()]);
93
130
foreach ([NULL , 'fr ' , 'de ' ] as $ lang ) {
94
131
$ result = $ this ->executeDataProducer ('route_entity ' , [
@@ -99,6 +136,52 @@ public function testRouteEntity() {
99
136
$ this ->assertNull ($ result );
100
137
}
101
138
139
+ // Unpublished node to published translations. Make sure we are not able to
140
+ // get unpublished source, but we are able to get published translations.
141
+ $ url = Url::fromRoute ('entity.node.canonical ' , ['node ' => $ this ->unpublished_to_published_node ->id ()]);
142
+
143
+ $ result = $ this ->executeDataProducer ('route_entity ' , [
144
+ 'url ' => $ url ,
145
+ ]);
146
+
147
+ $ this ->assertNull ($ result );
148
+
149
+ $ result = $ this ->executeDataProducer ('route_entity ' , [
150
+ 'url ' => $ url ,
151
+ 'language ' => 'fr ' ,
152
+ ]);
153
+
154
+ $ this ->assertEquals ($ this ->translation_fr_unpublished_to_published ->id (), $ result ->id ());
155
+ $ this ->assertEquals ($ this ->translation_fr_unpublished_to_published ->label (), $ result ->label ());
156
+
157
+ $ result = $ this ->executeDataProducer ('route_entity ' , [
158
+ 'url ' => $ url ,
159
+ 'language ' => 'de ' ,
160
+ ]);
161
+
162
+ $ this ->assertEquals ($ this ->translation_de_unpublished_to_published ->id (), $ result ->id ());
163
+ $ this ->assertEquals ($ this ->translation_de_unpublished_to_published ->label (), $ result ->label ());
164
+
165
+ // Published node to unpublished translations. Make sure we are able to get
166
+ // published source, but we are not able to get unpublished translations.
167
+ $ url = Url::fromRoute ('entity.node.canonical ' , ['node ' => $ this ->published_to_unpublished_node ->id ()]);
168
+
169
+ $ result = $ this ->executeDataProducer ('route_entity ' , [
170
+ 'url ' => $ url ,
171
+ ]);
172
+
173
+ $ this ->assertEquals ($ this ->published_to_unpublished_node ->id (), $ result ->id ());
174
+ $ this ->assertEquals ($ this ->published_to_unpublished_node ->label (), $ result ->label ());
175
+
176
+ foreach (['fr ' , 'de ' ] as $ lang ) {
177
+ $ result = $ this ->executeDataProducer ('route_entity ' , [
178
+ 'url ' => $ url ,
179
+ 'language ' => $ lang ,
180
+ ]);
181
+
182
+ $ this ->assertNull ($ result );
183
+ }
184
+
102
185
// Test with something which is not a URL.
103
186
$ this ->assertNull ($ this ->executeDataProducer ('route_entity ' , [
104
187
'url ' => 'not_a_url ' ,
0 commit comments