You are here

public function EntityFieldValueTest::testRawValues in GraphQL 8.3

Test if the basic fields are available on the interface.

@dataProvider nodeValuesProvider

Parameters

array $actualFieldValues:

array $expectedFieldValues:

File

modules/graphql_core/tests/src/Kernel/Entity/EntityFieldValueTest.php, line 197

Class

EntityFieldValueTest
Test basic entity fields.

Namespace

Drupal\Tests\graphql_core\Kernel\Entity

Code

public function testRawValues($actualFieldValues, $expectedFieldValues) {
  $this
    ->installEntitySchema('file');
  $this
    ->installSchema('file', [
    'file_usage',
  ]);
  $this
    ->addField('text', "field_text");
  $this
    ->addField('boolean', "field_boolean");
  $this
    ->addField('link', "field_link");
  $this
    ->addField('integer', "field_integer");
  $this
    ->addField('float', "field_float");
  $this
    ->addField('decimal', "field_decimal");
  $this
    ->addField('datetime', "field_datetime");
  $this
    ->addField('timestamp', "field_timestamp");
  $this
    ->addField('email', "field_email");
  $this
    ->addField('string', "field_string");
  $this
    ->addField('entity_reference', 'field_reference');
  $this
    ->addField('file', 'field_file');
  $this
    ->addField('image', 'field_image');

  // File 1
  file_put_contents('public://example.txt', $this
    ->randomMachineName());
  $this->testFile = File::create([
    'uri' => 'public://example.txt',
  ]);
  $this->testFile
    ->save();

  // File 2
  file_put_contents('public://example.png', $this
    ->randomMachineName());
  $this->testImage = File::create([
    'uri' => 'public://example.png',
  ]);
  $this->testImage
    ->save();
  $values = [
    'title' => 'Test',
    'type' => 'test',
  ];
  $node = $this
    ->createNode($values + $actualFieldValues);

  // Workaround for public file urls.
  $expectedFieldValues['fieldFile'][0]['entity']['url'] = file_create_url($this->testFile
    ->getFileUri());
  $expectedFieldValues['fieldFile'][1]['entity']['url'] = file_create_url($this->testImage
    ->getFileUri());
  $expectedFieldValues['fieldImage'][0]['entity']['url'] = file_create_url($this->testFile
    ->getFileUri());
  $expectedFieldValues['fieldImage'][1]['entity']['url'] = file_create_url($this->testImage
    ->getFileUri());
  $metadata = $this
    ->defaultCacheMetaData();
  $metadata
    ->addCacheTags([
    'node:1',
    'user:0',
    'file:1',
    'file:2',
  ]);
  $this
    ->assertResults($this
    ->getQueryFromFile('raw_field_values.gql'), [
    'path' => '/node/' . $node
      ->id(),
  ], [
    'route' => [
      'entity' => $expectedFieldValues,
    ],
  ], $metadata);
}