getFormat example

return $this->getContentTypeFormat();
    }

    /** * Gets the usual name of the format associated with the request's media type (provided in the Content-Type header). * * @see Request::$formats */
    public function getContentTypeFormat(): ?string
    {
        return $this->getFormat($this->headers->get('CONTENT_TYPE', ''));
    }

    /** * Sets the default locale. * * @return void */
    public function setDefaultLocale(string $locale)
    {
        $this->defaultLocale = $locale;

        

  protected function assertEntity(int $id, string $expected_language, string $expected_label, string $expected_vid, ?string $expected_description = '', ?string $expected_format = NULL, int $expected_weight = 0, array $expected_parents = [], int $expected_field_integer_value = NULL, int $expected_term_reference_tid = NULL): void {
    /** @var \Drupal\taxonomy\TermInterface $entity */
    $entity = Term::load($id);
    $this->assertInstanceOf(TermInterface::class$entity);
    $this->assertSame($expected_language$entity->language()->getId());
    $this->assertSame($expected_label$entity->label());
    $this->assertSame($expected_vid$entity->bundle());
    $this->assertSame($expected_description$entity->getDescription());
    $this->assertSame($expected_format$entity->getFormat());
    $this->assertSame($expected_weight$entity->getWeight());
    $this->assertHierarchy($expected_vid$id$expected_parents);
  }

  /** * Asserts that a term is present in the tree storage, with the right parents. * * @param string $vid * Vocabulary ID. * @param int $tid * ID of the term to check. * @param array $parent_ids * The expected parent term IDs. * * @internal */
// check simple search without any restrictions             $criteria = new Criteria($data->prefixed('p'));
            $criteria->addState(Criteria::STATE_ELASTICSEARCH_AWARE);

            $criteria->addAggregation(
                new DateHistogramAggregation(
                    'release-histogram',
                    'product.releaseDate',
                    $case->getInterval(),
                    null,
                    null,
                    $case->getFormat(),
                    $case->getTimeZone()
                )
            );

            $result = $aggregator->aggregate($this->productDefinition, $criteria$context);

            static::assertTrue($result->has('release-histogram'));

            $histogram = $result->get('release-histogram');
            static::assertInstanceOf(DateHistogramResult::class$histogram);

            
return static::getDescriptionTestData(ObjectsProvider::getApplications());
    }

    abstract protected function getDescriptor();

    abstract protected static function getFormat();

    protected static function getDescriptionTestData(array $objects)
    {
        $data = [];
        foreach ($objects as $name => $object) {
            $description = file_get_contents(sprintf('%s/../Fixtures/%s.%s', __DIR__, $namestatic::getFormat()));
            $data[] = [$object$description];
        }

        return $data;
    }

    protected function assertDescription($expectedDescription$describedObject, array $options = [])
    {
        $output = new BufferedOutput(BufferedOutput::VERBOSITY_NORMAL, true);
        $this->getDescriptor()->describe($output$describedObject$options + ['raw_output' => true]);
        $this->assertEquals($this->normalizeOutput($expectedDescription)$this->normalizeOutput($output->fetch()));
    }
public function toString(): string
    {
        return 'format is '.($this->format ?? 'null');
    }

    /** * @param Response $response */
    protected function matches($response): bool
    {
        return $this->format === $this->request->getFormat($response->headers->get('Content-Type'));
    }

    /** * @param Response $response */
    protected function failureDescription($response): string
    {
        return 'the Response '.$this->toString();
    }

    /** * @param Response $response */

  protected function assertEntity(int $id, string $expected_language, string $expected_label, string $expected_vid, string $expected_description = '', string $expected_format = NULL, int $expected_weight = 0, array $expected_parents = [], int $expected_field_integer_value = NULL, int $expected_term_reference_tid = NULL): void {
    /** @var \Drupal\taxonomy\TermInterface $entity */
    $entity = Term::load($id);
    $this->assertInstanceOf(TermInterface::class$entity);
    $this->assertSame($expected_language$entity->language()->getId());
    $this->assertSame($expected_label$entity->label());
    $this->assertSame($expected_vid$entity->bundle());
    $this->assertSame($expected_description$entity->getDescription());
    $this->assertSame($expected_format$entity->getFormat());
    $this->assertSame($expected_weight$entity->getWeight());
    $this->assertHierarchy($expected_vid$id$expected_parents);
  }

  /** * Asserts that a term is present in the tree storage, with the right parents. * * @param string $vid * Vocabulary ID. * @param int $tid * ID of the term to check. * @param array $parent_ids * The expected parent term IDs. * * @internal */
protected function tearDown(): void
    {
        putenv($this->colSize ? 'COLUMNS='.$this->colSize : 'COLUMNS');
    }

    /** @dataProvider getDescribeDefaultsTestData */
    public function testDescribeDefaults($object, array $options$fixtureName)
    {
        $describedObject = $this->getObjectDescription($object$options);
        $expectedDescription = $this->getExpectedDescription($fixtureName);

        if ('json' === $this->getFormat()) {
            $this->assertEquals(json_encode(json_decode($expectedDescription), \JSON_PRETTY_PRINT)json_encode(json_decode($describedObject), \JSON_PRETTY_PRINT));
        } else {
            $this->assertEquals(trim($expectedDescription)trim(str_replace(\PHP_EOL, "\n", $describedObject)));
        }
    }

    /** @dataProvider getDescribeResolvedFormTypeTestData */
    public function testDescribeResolvedFormType(ResolvedFormTypeInterface $type, array $options$fixtureName)
    {
        $describedObject = $this->getObjectDescription($type$options);
        $expectedDescription = $this->getExpectedDescription($fixtureName);

        
$criteria = new Criteria(
            $this->ids->getList(['p-1', 'p-2', 'p-3', 'p-4', 'p-5', 'p-6'])
        );

        $criteria->addAggregation(
            new DateHistogramAggregation(
                'release-histogram',
                'product.releaseDate',
                $case->getInterval(),
                null,
                null,
                $case->getFormat(),
                $case->getTimeZone()
            )
        );

        $result = $this->aggregator->aggregate($this->definition, $criteria$context);

        static::assertTrue($result->has('release-histogram'));

        $histogram = $result->get('release-histogram');
        static::assertInstanceOf(DateHistogramResult::class$histogram);

        

  protected function assertEntity(int $id, string $expected_language, string $expected_label, string $expected_vid, ?string $expected_description = '', ?string $expected_format = NULL, int $expected_weight = 0, array $expected_parents = [], int $expected_field_integer_value = NULL, int $expected_term_reference_tid = NULL): void {
    /** @var \Drupal\taxonomy\TermInterface $entity */
    $entity = Term::load($id);
    $this->assertInstanceOf(TermInterface::class$entity);
    $this->assertSame($expected_language$entity->language()->getId());
    $this->assertSame($expected_label$entity->label());
    $this->assertSame($expected_vid$entity->bundle());
    $this->assertSame($expected_description$entity->getDescription());
    $this->assertSame($expected_format$entity->getFormat());
    $this->assertSame($expected_weight$entity->getWeight());
    $this->assertHierarchy($expected_vid$id$expected_parents);
  }

  /** * Asserts that a term is present in the tree storage, with the right parents. * * @param string $vid * Vocabulary ID. * @param int $tid * ID of the term to check. * @param array $parent_ids * The expected parent term IDs. * * @internal */
public function toString(): string
    {
        return 'format is '.($this->format ?? 'null');
    }

    /** * @param Response $response */
    protected function matches($response): bool
    {
        return $this->format === $this->request->getFormat($response->headers->get('Content-Type'));
    }

    /** * @param Response $response */
    protected function failureDescription($response): string
    {
        return 'the Response '.$this->toString();
    }

    /** * @param Response $response */
abstract protected static function getDescriptor();

    abstract protected static function getFormat();

    private function assertDescription($expectedDescription$describedObject, array $options = [])
    {
        $options['is_debug'] = false;
        $options['raw_output'] = true;
        $options['raw_text'] = true;
        $output = new BufferedOutput(BufferedOutput::VERBOSITY_NORMAL, true);

        if ('txt' === $this->getFormat()) {
            $options['output'] = new SymfonyStyle(new ArrayInput([])$output);
        }

        $this->getDescriptor()->describe($output$describedObject$options);

        if ('json' === $this->getFormat()) {
            $this->assertEquals(json_encode(json_decode($expectedDescription), \JSON_PRETTY_PRINT)json_encode(json_decode($output->fetch()), \JSON_PRETTY_PRINT));
        } else {
            $this->assertEquals(trim($expectedDescription)trim(str_replace(\PHP_EOL, "\n", $output->fetch())));
        }
    }

    
'name' => $aggregation->getName(),
                'type' => 'filter',
                'filter' => $filters,
                'aggregation' => $this->aggregationToArray($aggregation->getAggregation()),
            ];
        }
        if ($aggregation instanceof DateHistogramAggregation) {
            $data = [
                'name' => $aggregation->getName(),
                'type' => 'histogram',
                'interval' => $aggregation->getInterval(),
                'format' => $aggregation->getFormat(),
                'field' => $aggregation->getField(),
                'timeZone' => $aggregation->getTimeZone(),
            ];

            if ($aggregation->getSorting()) {
                $data['sort'] = [
                    'order' => $aggregation->getSorting()->getDirection(),
                    'naturalSorting' => $aggregation->getSorting()->getNaturalSorting(),
                    'field' => $aggregation->getSorting()->getField(),
                ];
            }

            
foreach ($grouped as $value => $group) {
            $count = $group['count'];
            $nested = null;

            if ($aggregation->getAggregation()) {
                $nested = $this->hydrateResult($aggregation->getAggregation()$definition$group['buckets']$context);
            }

            $date = new \DateTime($value);

            if ($aggregation->getFormat()) {
                $value = $date->format($aggregation->getFormat());
            } else {
                $value = self::formatDate($aggregation->getInterval()$date);
            }

            $buckets[] = new Bucket($value$count$nested);
        }

        return new DateHistogramResult($aggregation->getName()$buckets);
    }

    

  protected function assertEntity(int $id, string $expected_language, string $expected_label, string $expected_vid, string $expected_description = '', string $expected_format = NULL, int $expected_weight = 0, array $expected_parents = [], int $expected_field_integer_value = NULL, int $expected_term_reference_tid = NULL): void {
    /** @var \Drupal\taxonomy\TermInterface $entity */
    $entity = Term::load($id);
    $this->assertInstanceOf(TermInterface::class$entity);
    $this->assertSame($expected_language$entity->language()->getId());
    $this->assertSame($expected_label$entity->label());
    $this->assertSame($expected_vid$entity->bundle());
    $this->assertSame($expected_description$entity->getDescription());
    $this->assertSame($expected_format$entity->getFormat());
    $this->assertSame($expected_weight$entity->getWeight());
    $this->assertHierarchy($expected_vid$id$expected_parents);
  }

  /** * Assert that a term is present in the tree storage, with the right parents. * * @param string $vid * Vocabulary ID. * @param int $tid * ID of the term to check. * @param array $parent_ids * The expected parent term IDs. * * @internal */

  protected function assertEntity(int $id, string $expected_language, string $expected_label, string $expected_vid, ?string $expected_description = '', ?string $expected_format = NULL, int $expected_weight = 0, array $expected_parents = [], int $expected_field_integer_value = NULL, int $expected_term_reference_tid = NULL, int|NULL $expected_container_flag = NULL): void {
    /** @var \Drupal\taxonomy\TermInterface $entity */
    $entity = Term::load($id);
    $this->assertInstanceOf(TermInterface::class$entity);
    $this->assertSame($expected_language$entity->language()->getId());
    $this->assertEquals($expected_label$entity->label());
    $this->assertEquals($expected_vid$entity->bundle());
    $this->assertEquals($expected_description$entity->getDescription());
    $this->assertEquals($expected_format$entity->getFormat());
    $this->assertEquals($expected_weight$entity->getWeight());
    $this->assertEquals($expected_parents$this->getParentIDs($id));
    $this->assertHierarchy($expected_vid$id$expected_parents);
    if (!is_null($expected_field_integer_value)) {
      $this->assertTrue($entity->hasField('field_integer'));
      $this->assertEquals($expected_field_integer_value$entity->field_integer->value);
    }
    if (!is_null($expected_term_reference_tid)) {
      $this->assertTrue($entity->hasField('field_integer'));
      $this->assertEquals($expected_term_reference_tid$entity->field_term_reference->target_id);
    }
    
Home | Imprint | This part of the site doesn't use cookies.