本文整理汇总了PHP中Drupal\system\Tests\Entity\EntityUnitTestBase类的典型用法代码示例。如果您正苦于以下问题:PHP EntityUnitTestBase类的具体用法?PHP EntityUnitTestBase怎么用?PHP EntityUnitTestBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EntityUnitTestBase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->installEntitySchema('entity_test_rev');
// Create a field.
$this->createEntityReferenceField($this->entityType, $this->bundle, $this->fieldName, 'Field test', $this->referencedEntityType, 'default', array('target_bundles' => array($this->bundle)), FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
}
示例2: setUp
protected function setUp()
{
parent::setUp();
$this->languageManager = $this->container->get('language_manager');
$this->installEntitySchema('entity_test_rev');
$this->installEntitySchema('entity_test_mul');
$this->installEntitySchema('entity_test_mulrev');
$this->installConfig(array('language'));
// Create the test field.
entity_test_install();
// Enable translations for the test entity type.
$this->state->set('entity_test.translation', TRUE);
// Create a translatable test field.
$this->field_name = drupal_strtolower($this->randomMachineName() . '_field_name');
// Create an untranslatable test field.
$this->untranslatable_field_name = drupal_strtolower($this->randomMachineName() . '_field_name');
// Create field fields in all entity variations.
foreach (entity_test_entity_types() as $entity_type) {
entity_create('field_storage_config', array('field_name' => $this->field_name, 'entity_type' => $entity_type, 'type' => 'text', 'cardinality' => 4))->save();
entity_create('field_config', array('field_name' => $this->field_name, 'entity_type' => $entity_type, 'bundle' => $entity_type, 'translatable' => TRUE))->save();
$this->field[$entity_type] = entity_load('field_config', $entity_type . '.' . $entity_type . '.' . $this->field_name);
entity_create('field_storage_config', array('field_name' => $this->untranslatable_field_name, 'entity_type' => $entity_type, 'type' => 'text', 'cardinality' => 4))->save();
entity_create('field_config', array('field_name' => $this->untranslatable_field_name, 'entity_type' => $entity_type, 'bundle' => $entity_type, 'translatable' => FALSE))->save();
}
// Create the default languages.
$this->installConfig(array('language'));
// Create test languages.
$this->langcodes = array();
for ($i = 0; $i < 3; ++$i) {
$language = ConfigurableLanguage::create(array('id' => 'l' . $i, 'label' => $this->randomString(), 'weight' => $i));
$this->langcodes[$i] = $language->getId();
$language->save();
}
}
示例3: setUp
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->installSchema('search_api', array('search_api_item', 'search_api_task'));
$this->installSchema('system', array('router'));
$this->installSchema('user', array('users_data'));
$this->setUpExampleStructure();
$this->installConfig(array('search_api_test_db'));
$this->insertExampleContent();
// Create a test server.
$this->server = Server::create(array(
'name' => $this->randomString(),
'id' => $this->randomMachineName(),
'status' => 1,
'backend' => 'search_api_test_backend',
));
$this->server->save();
$this->index = Index::load('database_search_index');
$this->index->setServer($this->server);
}
示例4: setUp
/**
* Set the default field storage backend for fields created during tests.
*/
protected function setUp()
{
parent::setUp();
// Create a node type for testing.
$type = entity_create('node_type', array('type' => 'page', 'name' => 'page'));
$type->save();
}
示例5: setUp
protected function setUp()
{
parent::setUp();
// Use Classy theme for testing markup output.
\Drupal::service('theme_handler')->install(['classy']);
\Drupal::service('theme_handler')->setDefault('classy');
// Grant the 'view test entity' permission.
$this->installConfig(array('user'));
Role::load(RoleInterface::ANONYMOUS_ID)->grantPermission('view test entity')->save();
// The label formatter rendering generates links, so build the router.
$this->container->get('router.builder')->rebuild();
$this->createEntityReferenceField($this->entityType, $this->bundle, $this->fieldName, 'Field test', $this->entityType, 'default', array(), FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
// Set up a field, so that the entity that'll be referenced bubbles up a
// cache tag when rendering it entirely.
FieldStorageConfig::create(array('field_name' => 'body', 'entity_type' => $this->entityType, 'type' => 'text', 'settings' => array()))->save();
FieldConfig::create(['entity_type' => $this->entityType, 'bundle' => $this->bundle, 'field_name' => 'body', 'label' => 'Body'])->save();
entity_get_display($this->entityType, $this->bundle, 'default')->setComponent('body', array('type' => 'text_default', 'settings' => array()))->save();
FilterFormat::create(array('format' => 'full_html', 'name' => 'Full HTML'))->save();
// Create the entity to be referenced.
$this->referencedEntity = $this->container->get('entity_type.manager')->getStorage($this->entityType)->create(array('name' => $this->randomMachineName()));
$this->referencedEntity->body = array('value' => '<p>Hello, world!</p>', 'format' => 'full_html');
$this->referencedEntity->save();
// Create another entity to be referenced but do not save it.
$this->unsavedReferencedEntity = $this->container->get('entity_type.manager')->getStorage($this->entityType)->create(array('name' => $this->randomMachineName()));
$this->unsavedReferencedEntity->body = array('value' => '<p>Hello, unsaved world!</p>', 'format' => 'full_html');
}
示例6: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$session = new Session();
$request = Request::create('/');
$request->setSession($session);
/** @var RequestStack $stack */
$stack = $this->container->get('request_stack');
$stack->pop();
$stack->push($request);
// Set the current user to one that can access comments. Specifically, this
// user does not have access to the 'administer comments' permission, to
// ensure only published comments are visible to the end user.
$current_user = $this->container->get('current_user');
$current_user->setAccount($this->createUser(array(), array('access comments')));
// Install tables and config needed to render comments.
$this->installSchema('comment', array('comment_entity_statistics'));
$this->installConfig(array('system', 'filter', 'comment'));
// Comment rendering generates links, so build the router.
$this->installSchema('system', array('router'));
$this->container->get('router.builder')->rebuild();
// Set up a field, so that the entity that'll be referenced bubbles up a
// cache tag when rendering it entirely.
$this->addDefaultCommentField('entity_test', 'entity_test');
}
示例7: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
entity_create('filter_format', array('format' => 'my_text_format', 'name' => 'My text format', 'filters' => array('filter_autop' => array('module' => 'filter', 'status' => TRUE))))->save();
entity_create('field_storage_config', array('field_name' => 'formatted_text', 'entity_type' => $this->entityType, 'type' => 'text', 'settings' => array()))->save();
entity_create('field_config', array('entity_type' => $this->entityType, 'bundle' => $this->bundle, 'field_name' => 'formatted_text', 'label' => 'Filtered text'))->save();
}
示例8: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->installConfig(array('user', 'entity_test'));
// Give anonymous users permission to view test entities.
Role::load(RoleInterface::ANONYMOUS_ID)->grantPermission('view test entity')->save();
}
示例9: setUp
protected function setUp()
{
parent::setUp();
$this->installEntitySchema('entity_test_rev');
$this->installEntitySchema('entity_test_mul');
$this->installEntitySchema('entity_test_mulrev');
}
示例10: setUp
protected function setUp()
{
parent::setUp();
$this->installEntitySchema('taxonomy_term');
// We want an entity reference field. It needs a vocabulary, terms, a field
// storage and a field. First, create the vocabulary.
$vocabulary = entity_create('taxonomy_vocabulary', array('vid' => Unicode::strtolower($this->randomMachineName())));
$vocabulary->save();
// Second, create the field.
entity_test_create_bundle('test_bundle');
$this->fieldName = strtolower($this->randomMachineName());
$handler_settings = array('target_bundles' => array($vocabulary->id() => $vocabulary->id()), 'auto_create' => TRUE);
$this->createEntityReferenceField('entity_test', 'test_bundle', $this->fieldName, NULL, 'taxonomy_term', 'default', $handler_settings);
// Create two terms and also two accounts.
for ($i = 0; $i <= 1; $i++) {
$term = entity_create('taxonomy_term', array('name' => $this->randomMachineName(), 'vid' => $vocabulary->id()));
$term->save();
$this->terms[] = $term;
$this->accounts[] = $this->createUser();
}
// Create three entity_test entities, the 0th entity will point to the
// 0th account and 0th term, the 1st and 2nd entity will point to the
// 1st account and 1st term.
for ($i = 0; $i <= 2; $i++) {
$entity = entity_create('entity_test', array('type' => 'test_bundle'));
$entity->name->value = $this->randomMachineName();
$index = $i ? 1 : 0;
$entity->user_id->target_id = $this->accounts[$index]->id();
$entity->{$this->fieldName}->target_id = $this->terms[$index]->id();
$entity->save();
$this->entities[] = $entity;
}
$this->factory = \Drupal::service('entity.query');
}
示例11: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
// Enable an additional language.
ConfigurableLanguage::createFromLangcode('de')->save();
$this->installEntitySchema('entity_test_mulrev');
}
示例12: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->installConfig(array('user'));
$this->installEntitySchema('comment');
$this->installSchema('comment', array('comment_entity_statistics'));
}
示例13: setUp
protected function setUp()
{
parent::setUp();
$this->installEntitySchema('taxonomy_term');
// We want a taxonomy term reference field. It needs a vocabulary, terms,
// a field storage and a field. First, create the vocabulary.
$vocabulary = entity_create('taxonomy_vocabulary', array('vid' => Unicode::strtolower($this->randomMachineName())));
$vocabulary->save();
// Second, create the field.
$this->fieldName = strtolower($this->randomMachineName());
entity_create('field_storage_config', array('field_name' => $this->fieldName, 'entity_type' => 'entity_test', 'type' => 'taxonomy_term_reference', 'settings' => array('allowed_values' => array(array('vocabulary' => $vocabulary->id())))))->save();
entity_test_create_bundle('test_bundle');
// Third, create the instance.
entity_create('field_config', array('entity_type' => 'entity_test', 'field_name' => $this->fieldName, 'bundle' => 'test_bundle'))->save();
// Create two terms and also two accounts.
for ($i = 0; $i <= 1; $i++) {
$term = entity_create('taxonomy_term', array('name' => $this->randomMachineName(), 'vid' => $vocabulary->id()));
$term->save();
$this->terms[] = $term;
$this->accounts[] = $this->createUser();
}
// Create three entity_test entities, the 0th entity will point to the
// 0th account and 0th term, the 1st and 2nd entity will point to the
// 1st account and 1st term.
for ($i = 0; $i <= 2; $i++) {
$entity = entity_create('entity_test', array('type' => 'test_bundle'));
$entity->name->value = $this->randomMachineName();
$index = $i ? 1 : 0;
$entity->user_id->target_id = $this->accounts[$index]->id();
$entity->{$this->fieldName}->target_id = $this->terms[$index]->id();
$entity->save();
$this->entities[] = $entity;
}
$this->factory = \Drupal::service('entity.query');
}
示例14: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->installConfig(array('user'));
$this->user = $this->createUser();
\Drupal::service('current_user')->setAccount($this->user);
}
示例15: setUp
/**
* Set the default field storage backend for fields created during tests.
*/
protected function setUp()
{
parent::setUp();
// Create a node type for testing.
$type = NodeType::create(['type' => 'page', 'name' => 'page']);
$type->save();
}