Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dbosen committed Oct 9, 2024
1 parent 2387034 commit d619f9f
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,46 @@ public function setUp(): void {
$node3->save();

$this->parent = $parent;

$schema = <<<GQL
type Query {
articles: EntityList
}
type EntityList {
total: Int!
}
GQL;

$this->setUpSchema($schema);
}

/**
* Test cache metadata for the query.
*/
public function testQueryCacheMetadata(): void {
$query = <<<GQL
query {
articles {
total
}
}
GQL;

$this->mockResolver('Query', 'articles',
$this->builder->produce('entities_with_term')
->map('term', $this->builder->fromValue($this->parent))
->map('type', $this->builder->fromValue('node'))
->map('field', $this->builder->fromValue(self::TAXONOMY_FIELD_NAME))
);
$this->mockResolver('EntityList', 'total', $this->builder->fromValue(1));

$metadata = $this->defaultCacheMetaData();
$metadata->setCacheContexts(['user.permissions', 'user.node_grants:view']);
$metadata->addCacheTags(['node_list', 'taxonomy_term:' . $this->parent->id()]);

$this->assertResults($query, [], [
'articles' => ['total' => '1'],
], $metadata);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace Drupal\Tests\thunder_gqls\Kernel\DataProducer;

use Drupal\Tests\graphql\Kernel\GraphQLTestBase;

/**
* Test entities_with_term data producer.
*
* @group Thunder
*/
class ThunderEntityListTest extends GraphQLTestBase {

/**
* {@inheritdoc}
*/
protected static $modules = [
'text',
'thunder_gqls',
];

/**
* {@inheritdoc}
*/
public function setUp(): void {
parent::setUp();

$schema = <<<GQL
type Query {
articles: EntityList
}
type EntityList {
total: Int!
}
GQL;

$this->setUpSchema($schema);
}

/**
* Test cache metadata for the query.
*/
public function testQueryCacheMetadata(): void {
$query = <<<GQL
query {
articles {
total
}
}
GQL;

$this->mockResolver('Query', 'articles',
$this->builder->produce('thunder_entity_list')
->map('type', $this->builder->fromValue('node'))
);
$this->mockResolver('EntityList', 'total', $this->builder->fromValue(1));

$metadata = $this->defaultCacheMetaData();
$metadata->setCacheContexts(['user.permissions', 'user.node_grants:view']);
$metadata->addCacheTags(['node_list']);

$this->assertResults($query, [], [
'articles' => ['total' => '1'],
], $metadata);
}

}

0 comments on commit d619f9f

Please sign in to comment.