TypedDataRelationshipPluginTest.php in Chaos Tool Suite (ctools) 8.3
File
tests/src/Kernel/TypedDataRelationshipPluginTest.php
View source
<?php
namespace Drupal\Tests\ctools\Kernel;
use Drupal\Core\Plugin\Context\ContextInterface;
class TypedDataRelationshipPluginTest extends RelationshipsTestBase {
public function testRelationshipName() {
$nid_plugin = $this->relationshipManager
->createInstance('typed_data_relationship:entity:node:nid');
$this
->assertSame('nid', $nid_plugin
->getName());
$uuid_plugin = $this->relationshipManager
->createInstance('typed_data_relationship:entity:node:uuid');
$this
->assertSame('uuid', $uuid_plugin
->getName());
$title_plugin = $this->relationshipManager
->createInstance('typed_data_relationship:entity:node:title');
$this
->assertSame('title', $title_plugin
->getName());
$body_plugin = $this->relationshipManager
->createInstance('typed_data_relationship:entity:node:body');
$this
->assertSame('body', $body_plugin
->getName());
$uid_plugin = $this->relationshipManager
->createInstance('typed_data_relationship:entity:node:uid');
$this
->assertSame('uid', $uid_plugin
->getName());
$mail_plugin = $this->relationshipManager
->createInstance('typed_data_relationship:entity:user:mail');
$this
->assertSame('mail', $mail_plugin
->getName());
}
public function testRelationship() {
$nid_plugin = $this->relationshipManager
->createInstance('typed_data_relationship:entity:node:nid');
$nid_plugin
->setContextValue('base', $this->entities['node1']);
$relationship = $nid_plugin
->getRelationship();
$this
->assertTrue($relationship instanceof ContextInterface);
$this
->assertTrue($relationship
->getContextDefinition()
->getDataType() == 'integer');
$this
->assertTrue($relationship
->hasContextValue());
$this
->assertTrue($relationship
->getContextValue() == $this->entities['node1']
->id());
$uuid_plugin = $this->relationshipManager
->createInstance('typed_data_relationship:entity:node:uuid');
$uuid_plugin
->setContextValue('base', $this->entities['node1']);
$relationship = $uuid_plugin
->getRelationship();
$this
->assertTrue($relationship instanceof ContextInterface);
$this
->assertTrue($relationship
->getContextDefinition()
->getDataType() == 'string');
$this
->assertTrue($relationship
->hasContextValue());
$this
->assertTrue($relationship
->getContextValue() == $this->entities['node1']
->uuid());
$title_plugin = $this->relationshipManager
->createInstance('typed_data_relationship:entity:node:title');
$title_plugin
->setContextValue('base', $this->entities['node1']);
$relationship = $title_plugin
->getRelationship();
$this
->assertTrue($relationship instanceof ContextInterface);
$this
->assertTrue($relationship
->getContextDefinition()
->getDataType() == 'string');
$this
->assertTrue($relationship
->hasContextValue());
$this
->assertTrue($relationship
->getContextValue() == $this->entities['node1']
->label());
$body_plugin = $this->relationshipManager
->createInstance('typed_data_relationship:entity:node:body');
$body_plugin
->setContextValue('base', $this->entities['node1']);
$relationship = $body_plugin
->getRelationship();
$this
->assertTrue($relationship instanceof ContextInterface);
$this
->assertTrue($relationship
->getContextDefinition()
->getDataType() == 'string');
$this
->assertTrue($relationship
->hasContextValue());
$this
->assertTrue($relationship
->getContextValue() == $this->entities['node1']
->get('body')
->first()
->get('value')
->getValue());
$uid_plugin = $this->relationshipManager
->createInstance('typed_data_relationship:entity:node:uid');
$uid_plugin
->setContextValue('base', $this->entities['node3']);
$relationship = $uid_plugin
->getRelationship();
$this
->assertTrue($relationship instanceof ContextInterface);
$this
->assertTrue($relationship
->getContextDefinition()
->getDataType() == 'integer');
$this
->assertTrue($relationship
->hasContextValue());
$this
->assertTrue($relationship
->getContextValue() == $this->entities['node3']
->getOwnerId());
$mail_plugin = $this->relationshipManager
->createInstance('typed_data_relationship:entity:user:mail');
$mail_plugin
->setContextValue('base', $this->entities['user']);
$relationship = $mail_plugin
->getRelationship();
$this
->assertTrue($relationship instanceof ContextInterface);
$this
->assertTrue($relationship
->getContextDefinition()
->getDataType() == 'email');
$this
->assertTrue($relationship
->hasContextValue());
$this
->assertTrue($relationship
->getContextValue() == $this->entities['user']
->getEmail());
}
}