public function SchemaTest::testUnpublishedAccess in Thunder 6.2.x
Tests the article schema.
Throws
\GuzzleHttp\Exception\GuzzleException
File
- modules/
thunder_gqls/ tests/ src/ Functional/ SchemaTest.php, line 67
Class
- SchemaTest
- Test the schema.
Namespace
Drupal\Tests\thunder_gqls\FunctionalCode
public function testUnpublishedAccess() {
$node = Node::create([
'title' => 'Test node',
'type' => 'article',
'status' => Node::NOT_PUBLISHED,
]);
$node
->save();
$validToken = AccessToken::create([
'entity_type' => 'node',
'entity_id' => $node
->id(),
'value' => 'iAmValid',
'expire' => -1,
]);
$validToken
->save();
$query = <<<GQL
query (\$path: String!) {
page(path: \$path) {
name
}
}
GQL;
$variables = [
'path' => $node
->toUrl()
->toString(),
];
$response = $this
->query($query, Json::encode($variables));
$this
->assertEquals(200, $response
->getStatusCode(), 'Response not 200');
$this
->assertEmpty(json_decode($response
->getBody(), TRUE)['data']['page']);
$query = <<<GQL
query (\$path: String!, \$token: String!) {
accessUnpublishedToken (auHash: \$token)
page(path: \$path) {
name
}
}
GQL;
$variables = [
'path' => $node
->toUrl()
->toString(),
'token' => 'iAmValid',
];
$response = $this
->query($query, Json::encode($variables));
$this
->assertEquals(200, $response
->getStatusCode(), 'Response not 200');
$this
->assertEqualsCanonicalizing([
'name' => 'Test node',
], json_decode($response
->getBody(), TRUE)['data']['page']);
}