You are here

protected function FilterTest::queryConditionData in JSON:API 8.2

Same name and namespace in other branches
  1. 8 tests/src/Kernel/Query/FilterTest.php \Drupal\Tests\jsonapi\Kernel\Query\FilterTest::queryConditionData()

Simply provides test data to keep the actual test method tidy.

1 call to FilterTest::queryConditionData()
FilterTest::testQueryCondition in tests/src/Kernel/Query/FilterTest.php
@covers ::queryCondition

File

tests/src/Kernel/Query/FilterTest.php, line 180

Class

FilterTest
@coversDefaultClass \Drupal\jsonapi\Query\Filter @group jsonapi @group jsonapi_query @group legacy

Namespace

Drupal\Tests\jsonapi\Kernel\Query

Code

protected function queryConditionData() {

  // ((RED or CIRCLE) or (YELLOW and SQUARE))
  $query = $this->nodeStorage
    ->getQuery();
  $or_group = $query
    ->orConditionGroup();
  $nested_or_group = $query
    ->orConditionGroup();
  $nested_or_group
    ->condition('colors', 'red', 'CONTAINS');
  $nested_or_group
    ->condition('shapes', 'circle', 'CONTAINS');
  $or_group
    ->condition($nested_or_group);
  $nested_and_group = $query
    ->andConditionGroup();
  $nested_and_group
    ->condition('colors', 'yellow', 'CONTAINS');
  $nested_and_group
    ->condition('shapes', 'square', 'CONTAINS');
  $nested_and_group
    ->notExists('photo.alt');
  $or_group
    ->condition($nested_and_group);
  $query
    ->condition($or_group);
  return [
    [
      [
        'or-group' => [
          'group' => [
            'conjunction' => 'OR',
          ],
        ],
        'nested-or-group' => [
          'group' => [
            'conjunction' => 'OR',
            'memberOf' => 'or-group',
          ],
        ],
        'nested-and-group' => [
          'group' => [
            'conjunction' => 'AND',
            'memberOf' => 'or-group',
          ],
        ],
        'condition-0' => [
          'condition' => [
            'path' => 'colors.value',
            'value' => 'red',
            'operator' => 'CONTAINS',
            'memberOf' => 'nested-or-group',
          ],
        ],
        'condition-1' => [
          'condition' => [
            'path' => 'shapes.value',
            'value' => 'circle',
            'operator' => 'CONTAINS',
            'memberOf' => 'nested-or-group',
          ],
        ],
        'condition-2' => [
          'condition' => [
            'path' => 'colors.value',
            'value' => 'yellow',
            'operator' => 'CONTAINS',
            'memberOf' => 'nested-and-group',
          ],
        ],
        'condition-3' => [
          'condition' => [
            'path' => 'shapes.value',
            'value' => 'square',
            'operator' => 'CONTAINS',
            'memberOf' => 'nested-and-group',
          ],
        ],
        'condition-4' => [
          'condition' => [
            'path' => 'photo.meta.alt',
            'operator' => 'IS NULL',
            'memberOf' => 'nested-and-group',
          ],
        ],
      ],
      $query,
    ],
  ];
}