2016-04-25 16:50:03 +03:00
|
|
|
<?php
|
|
|
|
namespace GraphQL\Tests\Validator;
|
|
|
|
|
2017-08-18 16:48:27 +03:00
|
|
|
use GraphQL\Validator\DocumentValidator;
|
|
|
|
use GraphQL\Validator\Rules\QueryComplexity;
|
|
|
|
|
2017-07-03 14:04:32 +03:00
|
|
|
class ValidationTest extends TestCase
|
2016-04-25 16:50:03 +03:00
|
|
|
{
|
|
|
|
// Validate: Supports full validation
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @it validates queries
|
|
|
|
*/
|
|
|
|
public function testValidatesQueries()
|
|
|
|
{
|
|
|
|
$this->expectPassesCompleteValidation('
|
|
|
|
query {
|
|
|
|
catOrDog {
|
|
|
|
... on Cat {
|
|
|
|
furColor
|
|
|
|
}
|
|
|
|
... on Dog {
|
|
|
|
isHousetrained
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
');
|
|
|
|
}
|
2017-08-18 16:48:27 +03:00
|
|
|
/*
|
|
|
|
public function testAllowsSettingRulesGlobally()
|
|
|
|
{
|
|
|
|
$rule = new QueryComplexity(0);
|
2017-07-12 22:38:31 +03:00
|
|
|
|
2017-08-18 16:48:27 +03:00
|
|
|
DocumentValidator::addRule($rule);
|
|
|
|
$instance = DocumentValidator::getRule(QueryComplexity::class);
|
|
|
|
$this->assertSame($rule, $instance);
|
|
|
|
}
|
|
|
|
*/
|
2017-07-12 22:38:31 +03:00
|
|
|
public function testPassesValidationWithEmptyRules()
|
|
|
|
{
|
|
|
|
$query = '{invalid}';
|
|
|
|
|
|
|
|
$expectedError = [
|
|
|
|
'message' => 'Cannot query field "invalid" on type "QueryRoot".',
|
|
|
|
'locations' => [ ['line' => 1, 'column' => 2] ]
|
|
|
|
];
|
|
|
|
$this->expectFailsCompleteValidation($query, [$expectedError]);
|
2018-02-11 15:15:51 +03:00
|
|
|
$this->expectValid($this->getTestSchema(), [], $query);
|
2017-07-12 22:38:31 +03:00
|
|
|
}
|
2016-04-25 16:50:03 +03:00
|
|
|
}
|