/** * Asserts that a context for the given property path can be derived. * * @param \Drupal\Core\Entity\ContentEntityInterface $entity * The entity to test with. * @param $property_path * The property path to look for. * @param $expected_data_type * The expected data type. * * @return \Drupal\Core\Plugin\Context\ContextInterface * The context with a value. */ protected function assertPropertyPath(ContentEntityInterface $entity, $property_path, $expected_data_type) { $typed_data_entity = $entity->getTypedData(); $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; }