createFromQueryParameter example

$cache_context_manager->assertValidTokens(Argument::any())
      ->willReturn(TRUE);
    $container->set('cache_contexts_manager', $cache_context_manager->reveal());
    \Drupal::setContainer($container);
  }

  /** * @covers ::createFromQueryParameter * @dataProvider parameterProvider */
  public function testCreateFromQueryParameter($original$expected) {
    $actual = OffsetPage::createFromQueryParameter($original);
    $this->assertEquals($expected['offset']$actual->getOffset());
    $this->assertEquals($expected['limit']$actual->getSize());
  }

  /** * Data provider for testCreateFromQueryParameter. */
  public function parameterProvider() {
    return [
      [['offset' => 12, 'limit' => 20]['offset' => 12, 'limit' => 20]],
      [['offset' => 12, 'limit' => 60]['offset' => 12, 'limit' => 50]],
      [[
protected static function buildTree(array $root, array $items) {
    $id = $root['id'];

    // Recursively build a tree of denormalized conditions and condition groups.     $members = [];
    foreach ($items as $item) {
      if ($item[static::MEMBER_KEY] == $id) {
        if (isset($item[static::GROUP_KEY])) {
          array_push($membersstatic::buildTree($item$items));
        }
        elseif (isset($item[static::CONDITION_KEY])) {
          $condition = EntityCondition::createFromQueryParameter($item[static::CONDITION_KEY]);
          array_push($members$condition);
        }
      }
    }

    $root[static::GROUP_KEY]['members'] = $members;

    // Denormalize the root into a condition group.     return new EntityConditionGroup($root[static::GROUP_KEY]['conjunction']$root[static::GROUP_KEY]['members']);
  }

}
$cache_context_manager->assertValidTokens(Argument::any())
      ->willReturn(TRUE);
    $container->set('cache_contexts_manager', $cache_context_manager->reveal());
    \Drupal::setContainer($container);
  }

  /** * @covers ::createFromQueryParameter * @dataProvider parameterProvider */
  public function testCreateFromQueryParameter($input$expected) {
    $sort = Sort::createFromQueryParameter($input);
    foreach ($sort->fields() as $index => $sort_field) {
      $this->assertEquals($expected[$index]['path']$sort_field['path']);
      $this->assertEquals($expected[$index]['direction']$sort_field['direction']);
      $this->assertEquals($expected[$index]['langcode']$sort_field['langcode']);
    }
  }

  /** * Provides a suite of shortcut sort parameters and their expected expansions. */
  public function parameterProvider() {
    
$cache_context_manager->assertValidTokens(Argument::any())
      ->willReturn(TRUE);
    $container->set('cache_contexts_manager', $cache_context_manager->reveal());
    \Drupal::setContainer($container);
  }

  /** * @covers ::createFromQueryParameter * @dataProvider queryParameterProvider */
  public function testCreateFromQueryParameter($case) {
    $condition = EntityCondition::createFromQueryParameter($case);
    $this->assertEquals($case['path']$condition->field());
    $this->assertEquals($case['value']$condition->value());
    if (isset($case['operator'])) {
      $this->assertEquals($case['operator']$condition->operator());
    }
  }

  /** * Data provider for testDenormalize. */
  public function queryParameterProvider() {
    
$this->fieldResolver = $this->container->get('jsonapi.field_resolver');
    $this->resourceTypeRepository = $this->container->get('jsonapi.resource_type.repository');
  }

  /** * @covers ::queryCondition */
  public function testInvalidFilterPathDueToMissingPropertyName() {
    $this->expectException(CacheableBadRequestHttpException::class);
    $this->expectExceptionMessage('Invalid nested filtering. The field `colors`, given in the path `colors` is incomplete, it must end with one of the following specifiers: `value`, `format`, `processed`.');
    $resource_type = $this->resourceTypeRepository->get('node', 'painting');
    Filter::createFromQueryParameter(['colors' => '']$resource_type$this->fieldResolver);
  }

  /** * @covers ::queryCondition */
  public function testInvalidFilterPathDueToMissingPropertyNameReferenceFieldWithMetaProperties() {
    $this->expectException(CacheableBadRequestHttpException::class);
    $this->expectExceptionMessage('Invalid nested filtering. The field `photo`, given in the path `photo` is incomplete, it must end with one of the following specifiers: `id`, `meta.drupal_internal__target_id`, `meta.alt`, `meta.title`, `meta.width`, `meta.height`.');
    $resource_type = $this->resourceTypeRepository->get('node', 'painting');
    Filter::createFromQueryParameter(['photo' => '']$resource_type$this->fieldResolver);
  }

  

  protected function getJsonApiParams(Request $request, ResourceType $resource_type) {
    if ($request->query->has('filter')) {
      $params[Filter::KEY_NAME] = Filter::createFromQueryParameter($request->query->all('filter')$resource_type$this->fieldResolver);
    }
    if ($request->query->has('sort')) {
      $params[Sort::KEY_NAME] = Sort::createFromQueryParameter($request->query->all()['sort']);
    }
    if ($request->query->has('page')) {
      $params[OffsetPage::KEY_NAME] = OffsetPage::createFromQueryParameter($request->query->all('page'));
    }
    else {
      $params[OffsetPage::KEY_NAME] = OffsetPage::createFromQueryParameter(['page' => ['offset' => OffsetPage::DEFAULT_OFFSET, 'limit' => OffsetPage::SIZE_MAX]]);
    }
    return $params;
  }
Home | Imprint | This part of the site doesn't use cookies.