TypedDataEntityRelationshipPluginTest.php in Chaos Tool Suite (ctools) 8.3        
                          
                  
                        
  
  
  
  
  
File
  tests/src/Kernel/TypedDataEntityRelationshipPluginTest.php
  
    View source  
  <?php
namespace Drupal\Tests\ctools\Kernel;
use Drupal\node\Entity\NodeType;
use Drupal\user\Entity\User;
class TypedDataEntityRelationshipPluginTest extends RelationshipsTestBase {
  
  public function testRelationshipName() {
    
    $type_plugin = $this->relationshipManager
      ->createInstance('typed_data_entity_relationship:entity:node:type');
    $this
      ->assertSame('type', $type_plugin
      ->getName());
    
    $uid_plugin = $this->relationshipManager
      ->createInstance('typed_data_entity_relationship:entity:node:uid');
    $this
      ->assertSame('uid', $uid_plugin
      ->getName());
  }
  
  public function testRelationship() {
    
    $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());
    
    $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());
  }
}