You are here

public function EntityConditionTest::validationProvider in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/jsonapi/tests/src/Unit/Query/EntityConditionTest.php \Drupal\Tests\jsonapi\Unit\Query\EntityConditionTest::validationProvider()

Data provider for testValidation.

File

core/modules/jsonapi/tests/src/Unit/Query/EntityConditionTest.php, line 88

Class

EntityConditionTest
@coversDefaultClass \Drupal\jsonapi\Query\EntityCondition @group jsonapi

Namespace

Drupal\Tests\jsonapi\Unit\Query

Code

public function validationProvider() {
  return [
    [
      [
        'path' => 'some_field',
        'value' => 'some_value',
      ],
      NULL,
    ],
    [
      [
        'path' => 'some_field',
        'value' => 'some_value',
        'operator' => '=',
      ],
      NULL,
    ],
    [
      [
        'path' => 'some_field',
        'operator' => 'IS NULL',
      ],
      NULL,
    ],
    [
      [
        'path' => 'some_field',
        'operator' => 'IS NOT NULL',
      ],
      NULL,
    ],
    [
      [
        'path' => 'some_field',
        'operator' => 'IS',
        'value' => 'some_value',
      ],
      new BadRequestHttpException("The 'IS' operator is not allowed in a filter parameter."),
    ],
    [
      [
        'path' => 'some_field',
        'operator' => 'NOT_ALLOWED',
        'value' => 'some_value',
      ],
      new BadRequestHttpException("The 'NOT_ALLOWED' operator is not allowed in a filter parameter."),
    ],
    [
      [
        'path' => 'some_field',
        'operator' => 'IS NULL',
        'value' => 'should_not_be_here',
      ],
      new BadRequestHttpException("Filters using the 'IS NULL' operator should not provide a value."),
    ],
    [
      [
        'path' => 'some_field',
        'operator' => 'IS NOT NULL',
        'value' => 'should_not_be_here',
      ],
      new BadRequestHttpException("Filters using the 'IS NOT NULL' operator should not provide a value."),
    ],
    [
      [
        'path' => 'path_only',
      ],
      new BadRequestHttpException("Filter parameter is missing a '" . EntityCondition::VALUE_KEY . "' key."),
    ],
    [
      [
        'value' => 'value_only',
      ],
      new BadRequestHttpException("Filter parameter is missing a '" . EntityCondition::PATH_KEY . "' key."),
    ],
  ];
}