function TypedDataResolverTest::assertPropertyPath

Same name in other branches
  1. 8.x-3.x tests/src/Kernel/TypedDataResolverTest.php \Drupal\Tests\ctools\Kernel\TypedDataResolverTest::assertPropertyPath()

Asserts that a context for the given property path can be derived.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: The entity to test with.

string $property_path: The property path to look for.

$expected_data_type: The expected data type.

Return value

\Drupal\Core\Plugin\Context\ContextInterface The context with a value.

1 call to TypedDataResolverTest::assertPropertyPath()
TypedDataResolverTest::testGetContextFromProperty in tests/src/Kernel/TypedDataResolverTest.php
Tests context extraction from properties.

File

tests/src/Kernel/TypedDataResolverTest.php, line 88

Class

TypedDataResolverTest
@coversDefaultClass \Drupal\ctools\TypedDataResolver

Namespace

Drupal\Tests\ctools\Kernel

Code

protected function assertPropertyPath(ContentEntityInterface $entity, string $property_path, $expected_data_type) {
    $typed_data_entity = $entity->getTypedData();
    if (strpos($typed_data_entity->getDataDefinition()
        ->getDataType(), 'entity:') === 0) {
        $context_definition = new EntityContextDefinition($typed_data_entity->getDataDefinition()
            ->getDataType());
    }
    else {
        $context_definition = new ContextDefinition($typed_data_entity->getDataDefinition()
            ->getDataType());
    }
    $context_with_value = new Context($context_definition, $typed_data_entity);
    $context_without_value = new Context($context_definition);
    // Test the context without value.
    $property_context = $this->typedDataResolver
        ->getContextFromProperty($property_path, $context_without_value);
    $this->assertEquals($expected_data_type, $property_context->getContextDefinition()
        ->getDataType());
    // Test the context with value.
    $property_context = $this->typedDataResolver
        ->getContextFromProperty($property_path, $context_with_value);
    $this->assertEquals($expected_data_type, $property_context->getContextDefinition()
        ->getDataType());
    // Return the context with value so it can be asserted.
    return $property_context;
}