本文整理汇总了PHP中Drupal\field\Tests\FieldUnitTestBase类的典型用法代码示例。如果您正苦于以下问题:PHP FieldUnitTestBase类的具体用法?PHP FieldUnitTestBase怎么用?PHP FieldUnitTestBase使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FieldUnitTestBase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
protected function setUp()
{
parent::setUp();
// Create a 'test_field' field and storage for validation.
entity_create('field_storage_config', array('field_name' => $this->field_name, 'entity_type' => 'entity_test', 'type' => 'test_field'))->save();
entity_create('field_config', array('entity_type' => 'entity_test', 'field_name' => $this->field_name, 'bundle' => 'entity_test'))->save();
}
示例2: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->installEntitySchema('entity_test_rev');
$this->storage = \Drupal::entityManager()->getStorage('entity_test');
$this->storage_rev = \Drupal::entityManager()->getStorage('entity_test_rev');
}
示例3: setUp
protected function setUp()
{
parent::setUp();
// Create a telephone field storage and field for validation.
entity_create('field_storage_config', array('field_name' => 'field_test', 'entity_type' => 'entity_test', 'type' => 'telephone'))->save();
entity_create('field_config', array('entity_type' => 'entity_test', 'field_name' => 'field_test', 'bundle' => 'entity_test'))->save();
}
示例4: setUp
/**
* {@inheritdoc}
*
* This sets up the entity_test and user types to use our example
* field plugins.
*/
protected function setUp()
{
array_unshift(self::$modules, 'field_permission_example');
parent::setUp();
// Tests for SimpleTest cannot usefully implement
// ContainerInjectionInterface the way PHPUnit tests do.
// We instead use KernelTest class' supplied container
// to get services we require.
$type_manager = $this->container->get('entity_type.manager');
// Set up our entity_type and user type for our new field:
$type_manager->getStorage('field_storage_config')->create(['field_name' => 'field_fieldnote', 'entity_type' => 'entity_test', 'type' => 'field_permission_example_fieldnote'])->save();
$type_manager->getStorage('field_config')->create(['entity_type' => 'entity_test', 'field_name' => 'field_fieldnote', 'bundle' => 'entity_test'])->save();
// Create a form display for the default form mode, and
// add our field type.
$type_manager->getStorage('entity_form_display')->create(['targetEntityType' => 'entity_test', 'bundle' => 'entity_test', 'mode' => 'default', 'status' => TRUE])->setComponent('field_fieldnote', ['type' => 'field_permission_example_widget'])->save();
// Now do this for the user type.
$type_manager->getStorage('field_storage_config')->create(['field_name' => 'user_fieldnote', 'entity_type' => 'user', 'type' => 'field_permission_example_fieldnote'])->save();
$type_manager->getStorage('field_config')->create(['entity_type' => 'user', 'field_name' => 'user_fieldnote', 'bundle' => 'user'])->save();
// Fetch a form display for a user. Most likely, this will already
// exist, so check as Core does.
// @see https://api.drupal.org/api/drupal/core%21includes%21entity.inc/function/entity_get_form_display/8
$entity_form_display = $type_manager->getStorage('entity_form_display')->load('user.user.default');
if (empty($entity_form_display)) {
$entity_form_display = $type_manager->getStorage('entity_form_display')->create(['targetEntityType' => 'user', 'bundle' => 'user', 'mode' => 'default', 'status' => TRUE]);
}
// And add our fancy field to that display:
$entity_form_display->setComponent('field_fieldnote', ['type' => 'field_permission_example_widget'])->save();
}
示例5: setUp
public function setUp()
{
parent::setUp();
// Create an link field and instance for validation.
entity_create('field_storage_config', array('name' => 'field_test', 'entity_type' => 'entity_test', 'type' => 'link'))->save();
entity_create('field_instance_config', array('entity_type' => 'entity_test', 'field_name' => 'field_test', 'bundle' => 'entity_test'))->save();
}
示例6: setUp
protected function setUp()
{
parent::setUp();
$this->container->get('router.builder')->rebuild();
$this->installEntitySchema('entity_test_rev');
$this->createFieldWithStorage();
}
示例7: setUp
/**
* Sets up the test.
*/
protected function setUp()
{
parent::setUp();
$this->installEntitySchema('entity_test_string_id');
$this->installEntitySchema('taxonomy_term');
$this->installEntitySchema('node');
$this->installEntitySchema('comment');
$this->installEntitySchema('file');
$this->installSchema('comment', ['comment_entity_statistics']);
$this->installSchema('node', ['node_access']);
$this->vocabulary = entity_create('taxonomy_vocabulary', array('name' => $this->randomMachineName(), 'vid' => Unicode::strtolower($this->randomMachineName()), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED));
$this->vocabulary->save();
$this->term = entity_create('taxonomy_term', array('name' => $this->randomMachineName(), 'vid' => $this->vocabulary->id(), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED));
$this->term->save();
$this->entityStringId = EntityTestStringId::create(['id' => $this->randomMachineName()]);
$this->entityStringId->save();
// Use the util to create an instance.
$this->createEntityReferenceField('entity_test', 'entity_test', 'field_test_taxonomy_term', 'Test content entity reference', 'taxonomy_term');
$this->createEntityReferenceField('entity_test', 'entity_test', 'field_test_entity_test_string_id', 'Test content entity reference with string ID', 'entity_test_string_id');
$this->createEntityReferenceField('entity_test', 'entity_test', 'field_test_taxonomy_vocabulary', 'Test config entity reference', 'taxonomy_vocabulary');
$this->createEntityReferenceField('entity_test', 'entity_test', 'field_test_node', 'Test node entity reference', 'node', 'default', [], FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
$this->createEntityReferenceField('entity_test', 'entity_test', 'field_test_user', 'Test user entity reference', 'user');
$this->createEntityReferenceField('entity_test', 'entity_test', 'field_test_comment', 'Test comment entity reference', 'comment');
$this->createEntityReferenceField('entity_test', 'entity_test', 'field_test_file', 'Test file entity reference', 'file');
}
示例8: setUp
function setUp()
{
parent::setUp();
$this->fieldStorageDefinition = array('field_name' => Unicode::strtolower($this->randomMachineName()), 'entity_type' => 'entity_test', 'type' => 'test_field');
$this->fieldStorage = entity_create('field_storage_config', $this->fieldStorageDefinition);
$this->fieldStorage->save();
$this->fieldDefinition = array('field_name' => $this->fieldStorage->getName(), 'entity_type' => 'entity_test', 'bundle' => 'entity_test');
}
示例9: setUp
protected function setUp()
{
parent::setUp();
$this->installEntitySchema('entity_test_rev');
// Create the necessary formats.
$this->installConfig(array('filter'));
entity_create('filter_format', array('format' => 'no_filters', 'filters' => array()))->save();
}
示例10: setUp
public function setUp()
{
parent::setUp();
// Create number fields and instances for validation.
foreach (array('integer', 'float', 'decimal') as $type) {
entity_create('field_storage_config', array('name' => 'field_' . $type, 'entity_type' => 'entity_test', 'type' => $type))->save();
entity_create('field_instance_config', array('entity_type' => 'entity_test', 'field_name' => 'field_' . $type, 'bundle' => 'entity_test'))->save();
}
}
示例11: setUp
public function setUp()
{
parent::setUp();
// Create a field with settings to validate.
$field_storage = entity_create('field_storage_config', array('name' => 'field_datetime', 'type' => 'datetime', 'entity_type' => 'entity_test', 'settings' => array('datetime_type' => 'date')));
$field_storage->save();
$instance = entity_create('field_instance_config', array('field_storage' => $field_storage, 'bundle' => 'entity_test', 'settings' => array('default_value' => 'blank')));
$instance->save();
}
示例12: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
entity_create('field_storage_config', ['field_name' => 'field_test', 'entity_type' => 'entity_test', 'type' => 'video_embed_field'])->save();
entity_create('field_config', ['entity_type' => 'entity_test', 'field_name' => 'field_test', 'bundle' => 'entity_test'])->save();
// Fake colorbox being enabled for the purposes of testing.
$module_handler = \Drupal::moduleHandler();
$module_handler->addModule('colorbox', NULL);
}
示例13: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
// Create a boolean field and storage for validation.
entity_create('field_storage_config', array('field_name' => 'field_boolean', 'entity_type' => 'entity_test', 'type' => 'boolean'))->save();
entity_create('field_config', array('entity_type' => 'entity_test', 'field_name' => 'field_boolean', 'bundle' => 'entity_test'))->save();
// Create a form display for the default form mode.
entity_get_form_display('entity_test', 'entity_test', 'default')->setComponent('field_boolean', array('type' => 'boolean_checkbox'))->save();
}
示例14: setUp
public function setUp()
{
parent::setUp();
// Create an email field and instance for validation.
entity_create('field_storage_config', array('name' => 'field_email', 'entity_type' => 'entity_test', 'type' => 'email'))->save();
entity_create('field_instance_config', array('entity_type' => 'entity_test', 'field_name' => 'field_email', 'bundle' => 'entity_test'))->save();
// Create a form display for the default form mode.
entity_get_form_display('entity_test', 'entity_test', 'default')->setComponent('field_email', array('type' => 'email_default'))->save();
}
示例15: setUp
/**
* {@inheritdoc}
*/
public function setUp()
{
parent::setUp();
$this->installSchema('system', array('router'));
$this->fieldStorageDefinition = array('name' => $this->fieldName, 'entity_type' => 'entity_test', 'type' => 'list_integer', 'cardinality' => 1, 'settings' => array('allowed_values' => array(1 => 'One', 2 => 'Two', 3 => 'Three')));
$this->fieldStorage = entity_create('field_storage_config', $this->fieldStorageDefinition);
$this->fieldStorage->save();
$this->instance = entity_create('field_instance_config', array('field_storage' => $this->fieldStorage, 'bundle' => 'entity_test'));
$this->instance->save();
entity_get_form_display('entity_test', 'entity_test', 'default')->setComponent($this->fieldName, array('type' => 'options_buttons'))->save();
}