function TypedDataEntityRelationshipPluginTest::testRelationship

Same name in other branches
  1. 4.0.x tests/src/Kernel/TypedDataEntityRelationshipPluginTest.php \Drupal\Tests\ctools\Kernel\TypedDataEntityRelationshipPluginTest::testRelationship()

@covers ::getRelationship

File

tests/src/Kernel/TypedDataEntityRelationshipPluginTest.php, line 30

Class

TypedDataEntityRelationshipPluginTest
@coversDefaultClass \Drupal\ctools\Plugin\Relationship\TypedDataEntityRelationship @group CTools

Namespace

Drupal\Tests\ctools\Kernel

Code

public function testRelationship() {
    
    /** @var \Drupal\ctools\Plugin\RelationshipInterface $type_plugin */
    $type_plugin = $this->relationshipManager
        ->createInstance('typed_data_entity_relationship:entity:node:type');
    $type_plugin->setContextValue('base', $this->entities['node1']);
    $relationship = $type_plugin->getRelationship();
    $this->assertTrue($relationship->getContextValue() instanceof NodeType);
    $this->assertSame('entity:node_type', $relationship->getContextDefinition()
        ->getDataType());
    
    /** @var \Drupal\ctools\Plugin\RelationshipInterface $uid_plugin */
    $uid_plugin = $this->relationshipManager
        ->createInstance('typed_data_entity_relationship:entity:node:uid');
    $uid_plugin->setContextValue('base', $this->entities['node3']);
    $relationship = $uid_plugin->getRelationship();
    $this->assertTrue($relationship->getContextValue() instanceof User);
    $this->assertSame('entity:user', $relationship->getContextDefinition()
        ->getDataType());
    
    /** @var \Drupal\ctools\Plugin\RelationshipInterface $uid_plugin */
    $uid_plugin = $this->relationshipManager
        ->createInstance('typed_data_entity_relationship:entity:node:uid');
    $uid_plugin->setContextValue('base', $this->entities['node4']);
    $relationship = $uid_plugin->getRelationship();
    $this->assertFalse($relationship->hasContextValue());
    $this->assertSame('entity:user', $relationship->getContextDefinition()
        ->getDataType());
}