RelationshipManagerTest.php in Chaos Tool Suite (ctools) 8.3
File
tests/src/Kernel/RelationshipManagerTest.php
View source
<?php
namespace Drupal\Tests\ctools\Kernel;
use Drupal\Core\Plugin\Context\Context;
use Drupal\Core\Plugin\Context\EntityContextDefinition;
class RelationshipManagerTest extends RelationshipsTestBase {
public function testRelationshipConstraints() {
$definitions = $this->relationshipManager
->getDefinitions();
$expected = [
'Bundle' => [
0 => "page",
1 => "foo",
],
];
$this
->assertSame($expected, $definitions['typed_data_relationship:entity:node:body']['context_definitions']['base']
->getConstraints());
$this
->assertSame('Body from Page and Foo', (string) $definitions['typed_data_relationship:entity:node:body']['label']);
$this
->assertSame('Authored by Entity from Content', (string) $definitions['typed_data_entity_relationship:entity:node:uid']['label']);
$this
->assertSame('Language Language from Content', (string) $definitions['typed_data_language_relationship:entity:node:langcode']['label']);
}
public function testRelationshipPluginAvailability() {
$context_definition = new EntityContextDefinition('entity:node');
$contexts = [
'node' => new Context($context_definition, $this->entities['node1']),
];
$definitions = $this->relationshipManager
->getDefinitionsForContexts($contexts);
$context_definition = new EntityContextDefinition('entity:node');
$contexts = [
'node' => new Context($context_definition, $this->entities['node2']),
];
$definitions = $this->relationshipManager
->getDefinitionsForContexts($contexts);
$this
->assertFalse(isset($definitions['typed_data_relationship:entity:node:body']));
$context_definition = new EntityContextDefinition('entity:node');
$contexts = [
'node' => new Context($context_definition, $this->entities['node3']),
];
$definitions = $this->relationshipManager
->getDefinitionsForContexts($contexts);
}
}