Skip to content

Commit 937667d

Browse files
committed
test 1
1 parent 6a6bf30 commit 937667d

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/src/Kernel/DataProducer/DefaultValueTest.php

+34
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22

33
namespace Drupal\Tests\graphql\Kernel\DataProducer;
44

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;
59
use Drupal\Tests\graphql\Kernel\GraphQLTestBase;
10+
use GraphQL\Deferred;
11+
use PHPUnit\Framework\Assert;
612

713
/**
814
* Context default value test.
@@ -24,4 +30,32 @@ public function testEntityLoadDefaultValue(): void {
2430
$this->assertSame('view', $context_values['access_operation']);
2531
}
2632

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+
}
2761
}

0 commit comments

Comments
 (0)