2
2
3
3
namespace Drupal \Tests \graphql \Kernel \DataProducer ;
4
4
5
+ use Drupal \Core \Session \AccountInterface ;
6
+ use Drupal \graphql \GraphQL \Execution \FieldContext ;
7
+ use Drupal \graphql \Plugin \GraphQL \DataProducer \Entity \EntityLoad ;
8
+ use Drupal \media_test_source \Plugin \media \Source \Test ;
5
9
use Drupal \Tests \graphql \Kernel \GraphQLTestBase ;
10
+ use GraphQL \Deferred ;
11
+ use PHPUnit \Framework \Assert ;
6
12
7
13
/**
8
14
* Context default value test.
@@ -24,4 +30,32 @@ public function testEntityLoadDefaultValue(): void {
24
30
$ this ->assertSame ('view ' , $ context_values ['access_operation ' ]);
25
31
}
26
32
33
+ /**
34
+ * Test that the legacy dataproducer_populate_default_values setting works.
35
+ */
36
+ public function testLegacyDefaultValueSetting (): void {
37
+ $ this ->container ->get ('config.factory ' )->getEditable ('graphql.settings ' )
38
+ ->set ('dataproducer_populate_default_values ' , FALSE )
39
+ ->save ();
40
+ $ manager = $ this ->container ->get ('plugin.manager.graphql.data_producer ' );
41
+
42
+ // Manipulate the plugin definitions to use our test class for entity_load.
43
+ $ definitions = $ manager ->getDefinitions ();
44
+ $ definitions ['entity_load ' ]['class ' ] = TestLegacyEntityLoad::class;
45
+ $ reflection = new \ReflectionClass ($ manager );
46
+ $ property = $ reflection ->getProperty ('definitions ' );
47
+ $ property ->setAccessible (TRUE );
48
+ $ property ->setValue ($ manager , $ definitions );
49
+
50
+ $ this ->executeDataProducer ('entity_load ' , ['type ' => 'node ' ]);
51
+ }
52
+
53
+ }
54
+
55
+ class TestLegacyEntityLoad extends EntityLoad {
56
+ public function resolve ($ type , $ id , ?string $ language , ?array $ bundles , ?bool $ access , ?AccountInterface $ accessUser , ?string $ accessOperation , FieldContext $ context ): ?Deferred {
57
+ Assert::assertNull ($ access );
58
+ Assert::assertNull ($ accessOperation );
59
+ return NULL ;
60
+ }
27
61
}
0 commit comments