Newer
Older
Alex Pott
committed
<?php
Alex Pott
committed
namespace Drupal\Tests\field\Kernel;
Alex Pott
committed
use Drupal\Core\Field\FieldDefinitionInterface;
Alex Pott
committed
use Drupal\Core\Field\FieldStorageDefinitionInterface;
/**
* Tests exposing field definitions for configurable fields.
*
* @group field
Alex Pott
committed
*/
Alex Pott
committed
class ConfigFieldDefinitionTest extends FieldKernelTestBase {
Alex Pott
committed
/**
* The entity manager service.
*
Lee Rowlands
committed
* @var \Drupal\Core\Entity\EntityManagerInterface
Alex Pott
committed
*/
protected $entityManager;
/**
* @var string
*/
private $entityType;
/**
* @var string
*/
private $bundle;
Alex Pott
committed
/**
* {@inheritdoc}
*/
Alex Pott
committed
protected function setUp() {
Alex Pott
committed
parent::setUp();
// Create a field and a storage of type 'test_field', on the 'entity_test'
Alex Pott
committed
// entity type.
$this->entityType = 'entity_test';
$this->bundle = 'entity_test';
$this->createFieldWithStorage('', $this->entityType, $this->bundle);
Alex Pott
committed
$this->entityManager = $this->container->get('entity.manager');
// Create a second field on 'entity_test_rev'.
$this->createFieldWithStorage('_rev', 'entity_test_rev', 'entity_test_rev');
Alex Pott
committed
}
/**
* Makes sure a field definition is exposed for a configurable field.
*/
public function testBundleFieldDefinition() {
$definitions = $this->entityManager->getFieldDefinitions($this->entityType, $this->bundle);
$this->assertTrue(isset($definitions[$this->fieldTestData->field->getName()]));
$this->assertTrue($definitions[$this->fieldTestData->field->getName()] instanceof FieldDefinitionInterface);
// Make sure fields on other entity types are not exposed.
$this->assertFalse(isset($definitions[$this->fieldTestData->field_rev->getName()]));
Alex Pott
committed
}
/**
* Makes sure a field storage definition is exposed for a configurable field.
*/
public function testFieldStorageDefinition() {
Alex Pott
committed
$field_storage_definitions = $this->entityManager->getFieldStorageDefinitions($this->entityType);
$this->assertTrue(isset($field_storage_definitions[$this->fieldTestData->field->getName()]));
$this->assertTrue($field_storage_definitions[$this->fieldTestData->field->getName()] instanceof FieldStorageDefinitionInterface);
// Make sure storages on other entity types are not exposed.
$this->assertFalse(isset($field_storage_definitions[$this->fieldTestData->field_rev->getName()]));