EntityConditionGroupNormalizerTest.php in JSON:API 8
File
tests/src/Kernel/Normalizer/EntityConditionGroupNormalizerTest.php
View source
<?php
namespace Drupal\Tests\jsonapi\Kernel\Normalizer;
use Drupal\KernelTests\KernelTestBase;
use Drupal\jsonapi\Query\EntityConditionGroup;
class EntityConditionGroupNormalizerTest extends KernelTestBase {
public static $modules = [
'serialization',
'system',
'jsonapi',
];
public function testDenormalize($case) {
$normalizer = $this->container
->get('serializer.normalizer.entity_condition_group.jsonapi');
$normalized = $normalizer
->denormalize($case, EntityConditionGroup::class);
$this
->assertEquals($case['conjunction'], $normalized
->conjunction());
foreach ($normalized
->members() as $key => $condition) {
$this
->assertEquals($case['members'][$key]['path'], $condition
->field());
$this
->assertEquals($case['members'][$key]['value'], $condition
->value());
}
}
public function testDenormalizeException() {
$normalizer = $this->container
->get('serializer.normalizer.entity_condition_group.jsonapi');
$data = [
'conjunction' => 'NOT_ALLOWED',
'members' => [],
];
$this
->setExpectedException(\InvalidArgumentException::class);
$normalized = $normalizer
->denormalize($data, EntityConditionGroup::class);
}
public function denormalizeProvider() {
return [
[
[
'conjunction' => 'AND',
'members' => [],
],
],
[
[
'conjunction' => 'OR',
'members' => [],
],
],
];
}
}