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 = Vocabulary::create(['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 = Term::create(['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 = EntityTest::create(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');
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     FilterFormat::create(array('format' => 'my_text_format', 'name' => 'My text format', 'filters' => array('filter_autop' => array('module' => 'filter', 'status' => TRUE))))->save();
     FieldStorageConfig::create(array('field_name' => 'formatted_text', 'entity_type' => $this->entityType, 'type' => 'text', 'settings' => array()))->save();
     FieldConfig::create(['entity_type' => $this->entityType, 'bundle' => $this->bundle, 'field_name' => 'formatted_text', 'label' => 'Filtered text'])->save();
 }
 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');
 }
 /**
  * {@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);
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installConfig(array('user'));
     $this->user = $this->createUser();
     \Drupal::service('current_user')->setAccount($this->user);
 }
 /**
  * {@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();
 }
 /**
  * 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();
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     // Enable an additional language.
     ConfigurableLanguage::createFromLangcode('de')->save();
     $this->installEntitySchema('entity_test_mul');
 }
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('entity_test_mulrev');
     $this->installEntitySchema('configurable_language');
     ConfigurableLanguage::createFromLangcode('es')->save();
 }
 protected function setUp()
 {
     parent::setUp();
     $this->entityStorage = $this->entityManager->getStorage('entity_test');
     $this->factory = $this->container->get('entity.query');
     // Add some fieldapi fields to be used in the test.
     for ($i = 1; $i <= 2; $i++) {
         $field_name = 'field_test_' . $i;
         FieldStorageConfig::create(array('field_name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'integer', 'cardinality' => 2))->save();
         FieldConfig::create(['field_name' => $field_name, 'entity_type' => 'entity_test', 'bundle' => 'entity_test'])->save();
     }
     $entity = $this->entityStorage->create(array('id' => 1, 'user_id' => 1, 'field_test_1' => 1, 'field_test_2' => 2));
     $entity->enforceIsNew();
     $entity->save();
     $entity = $this->entityStorage->create(array('id' => 2, 'user_id' => 2, 'field_test_1' => 1, 'field_test_2' => 7));
     $entity->enforceIsNew();
     $entity->save();
     $entity = $this->entityStorage->create(array('id' => 3, 'user_id' => 2, 'field_test_1' => 2, 'field_test_2' => 1));
     $entity->enforceIsNew();
     $entity->save();
     $entity = $this->entityStorage->create(array('id' => 4, 'user_id' => 2, 'field_test_1' => 2, 'field_test_2' => 8));
     $entity->enforceIsNew();
     $entity->save();
     $entity = $this->entityStorage->create(array('id' => 5, 'user_id' => 3, 'field_test_1' => 2, 'field_test_2' => 2));
     $entity->enforceIsNew();
     $entity->save();
     $entity = $this->entityStorage->create(array('id' => 6, 'user_id' => 3, 'field_test_1' => 3, 'field_test_2' => 8));
     $entity->enforceIsNew();
     $entity->save();
 }
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('entity_test_mulrev');
     $this->installConfig(array('language'));
     $figures = Unicode::strtolower($this->randomMachineName());
     $greetings = Unicode::strtolower($this->randomMachineName());
     foreach (array($figures => 'shape', $greetings => 'text') as $field_name => $field_type) {
         $field_storage = FieldStorageConfig::create(array('field_name' => $field_name, 'entity_type' => 'entity_test_mulrev', 'type' => $field_type, 'cardinality' => 2));
         $field_storage->save();
         $field_storages[] = $field_storage;
     }
     $bundles = array();
     for ($i = 0; $i < 2; $i++) {
         // For the sake of tablesort, make sure the second bundle is higher than
         // the first one. Beware: MySQL is not case sensitive.
         do {
             $bundle = $this->randomMachineName();
         } while ($bundles && strtolower($bundles[0]) >= strtolower($bundle));
         entity_test_create_bundle($bundle);
         foreach ($field_storages as $field_storage) {
             FieldConfig::create(['field_storage' => $field_storage, 'bundle' => $bundle])->save();
         }
         $bundles[] = $bundle;
     }
     // Each unit is a list of field name, langcode and a column-value array.
     $units[] = array($figures, 'en', array('color' => 'red', 'shape' => 'triangle'));
     $units[] = array($figures, 'en', array('color' => 'blue', 'shape' => 'circle'));
     // To make it easier to test sorting, the greetings get formats according
     // to their langcode.
     $units[] = array($greetings, 'tr', array('value' => 'merhaba', 'format' => 'format-tr'));
     $units[] = array($greetings, 'pl', array('value' => 'siema', 'format' => 'format-pl'));
     // Make these languages available to the greetings field.
     ConfigurableLanguage::createFromLangcode('tr')->save();
     ConfigurableLanguage::createFromLangcode('pl')->save();
     // Calculate the cartesian product of the unit array by looking at the
     // bits of $i and add the unit at the bits that are 1. For example,
     // decimal 13 is binary 1101 so unit 3,2 and 0 will be added to the
     // entity.
     for ($i = 1; $i <= 15; $i++) {
         $entity = EntityTestMulRev::create(array('type' => $bundles[$i & 1], 'name' => $this->randomMachineName(), 'langcode' => 'en'));
         // Make sure the name is set for every language that we might create.
         foreach (array('tr', 'pl') as $langcode) {
             $entity->addTranslation($langcode)->name = $this->randomMachineName();
         }
         foreach (array_reverse(str_split(decbin($i))) as $key => $bit) {
             if ($bit) {
                 list($field_name, $langcode, $values) = $units[$key];
                 $entity->getTranslation($langcode)->{$field_name}[] = $values;
             }
         }
         $entity->save();
     }
     $this->bundles = $bundles;
     $this->figures = $figures;
     $this->greetings = $greetings;
     $this->factory = \Drupal::service('entity.query');
 }
 protected function setUp()
 {
     parent::setUp();
     // Install default system configuration.
     $this->installConfig(array('system'));
     \Drupal::service('router.builder')->rebuild();
     $this->interfaceLanguage = \Drupal::languageManager()->getCurrentLanguage();
     $this->tokenService = \Drupal::token();
 }
Beispiel #13
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     // Create the test field.
     module_load_install('entity_test');
     entity_test_install();
     // Install required default configuration for filter module.
     $this->installConfig(array('system', 'filter'));
 }
 protected function setUp()
 {
     parent::setUp();
     $this->installSchema('user', array('users_data'));
     $this->installSchema('file', array('file_usage'));
     $this->installSchema('node', array('node_access'));
     $this->installSchema('comment', array('comment_entity_statistics'));
     $this->installConfig(['node', 'comment']);
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     // Enable an additional language.
     ConfigurableLanguage::createFromLangcode('de')->save();
     ConfigurableLanguage::createFromLangcode('fr')->save();
     $this->installEntitySchema('entity_test_field_methods');
     $this->entityTestFieldMethodsStorage = $this->entityManager->getStorage('entity_test_field_methods');
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     // Setup some fields for entity_test_extra to create.
     $definitions['multivalued_base_field'] = BaseFieldDefinition::create('string')->setName('multivalued_base_field')->setTargetEntityTypeId('entity_test_mulrev')->setTargetBundle('entity_test_mulrev')->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
     $this->state->set('entity_test_mulrev.additional_base_field_definitions', $definitions);
     $this->entityManager->clearCachedDefinitions();
     $this->tableMapping = $this->entityManager->getStorage('entity_test_mulrev')->getTableMapping();
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->role1 = Role::create(array('id' => strtolower($this->randomMachineName(8)), 'label' => $this->randomMachineName(8)));
     $this->role1->save();
     $this->role2 = Role::create(array('id' => strtolower($this->randomMachineName(8)), 'label' => $this->randomMachineName(8)));
     $this->role2->save();
     $this->createEntityReferenceField('user', 'user', 'user_reference', 'User reference', 'user');
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     foreach (entity_test_entity_types() as $entity_type_id) {
         // The entity_test schema is installed by the parent.
         if ($entity_type_id != 'entity_test') {
             $this->installEntitySchema($entity_type_id);
         }
     }
 }
 protected function setUp()
 {
     parent::setUp();
     // Create an Article node type.
     $article = NodeType::create(array('type' => 'article'));
     $article->save();
     // Test as a non-admin.
     $normal_user = $this->createUser(array(), array('access content'));
     \Drupal::currentUser()->setAccount($normal_user);
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     // Enable an additional language.
     ConfigurableLanguage::createFromLangcode('de')->save();
     $this->installEntitySchema('entity_test_mulrev');
     $this->installEntitySchema('entity_test_rev');
     $this->mulRev = $this->entityManager->getStorage('entity_test_mulrev');
     $this->rev = $this->entityManager->getStorage('entity_test_rev');
 }
Beispiel #21
0
 protected function setUp()
 {
     parent::setUp();
     // Create the node bundles required for testing.
     $type = NodeType::create(array('type' => 'page', 'name' => 'page'));
     $type->save();
     // Enable two additional languages.
     ConfigurableLanguage::createFromLangcode('de')->save();
     ConfigurableLanguage::createFromLangcode('it')->save();
     $this->installSchema('node', 'node_access');
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->entityDefinitionUpdateManager = $this->container->get('entity.definition_update_manager');
     $this->database = $this->container->get('database');
     // Install every entity type's schema that wasn't installed in the parent
     // method.
     foreach (array_diff_key($this->entityManager->getDefinitions(), array_flip(array('user', 'entity_test'))) as $entity_type_id => $entity_type) {
         $this->installEntitySchema($entity_type_id);
     }
 }
Beispiel #23
0
 protected function setUp()
 {
     parent::setUp();
     // Create the node bundles required for testing.
     $type = NodeType::create(['type' => 'page', 'name' => 'page']);
     $type->save();
     $type = NodeType::create(['type' => 'article', 'name' => 'article']);
     $type->save();
     $type = NodeType::create(['type' => 'test', 'name' => 'test']);
     $type->save();
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installSchema('user', 'users_data');
     $this->entityDefinitionUpdateManager = $this->container->get('entity.definition_update_manager');
     // Setup some fields for entity_test_extra to create.
     $definitions['extra_base_field'] = BaseFieldDefinition::create('string')->setName('extra_base_field')->setTargetEntityTypeId('entity_test')->setTargetBundle('entity_test');
     $this->state->set('entity_test.additional_base_field_definitions', $definitions);
     $definitions['extra_bundle_field'] = FieldStorageDefinition::create('string')->setName('extra_bundle_field')->setTargetEntityTypeId('entity_test')->setTargetBundle('entity_test');
     $this->state->set('entity_test.additional_field_storage_definitions', $definitions);
     $this->state->set('entity_test.entity_test.additional_bundle_field_definitions', $definitions);
     $this->entityManager->clearCachedDefinitions();
 }
Beispiel #25
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->container->get('state')->set('entity_test.field_test_item', TRUE);
     $this->entityManager->clearCachedDefinitions();
     $entity_type_id = 'entity_test_mulrev';
     $this->installEntitySchema($entity_type_id);
     $this->fieldName = Unicode::strtolower($this->randomMachineName());
     /** @var \Drupal\field\Entity\FieldStorageConfig $field_storage */
     FieldStorageConfig::create(['field_name' => $this->fieldName, 'type' => 'field_test', 'entity_type' => $entity_type_id, 'cardinality' => 1])->save();
     FieldConfig::create(['entity_type' => $entity_type_id, 'field_name' => $this->fieldName, 'bundle' => $entity_type_id, 'label' => 'Test field'])->save();
     $this->entityManager->clearCachedDefinitions();
     $definitions = $this->entityManager->getFieldStorageDefinitions($entity_type_id);
     $this->assertTrue(!empty($definitions[$this->fieldName]));
 }
 protected function setUp()
 {
     parent::setUp();
     foreach (entity_test_entity_types() as $entity_type_id) {
         // The entity_test schema is installed by the parent.
         if ($entity_type_id != 'entity_test') {
             $this->installEntitySchema($entity_type_id);
         }
     }
     // Create the test field.
     module_load_install('entity_test');
     entity_test_install();
     // Install required default configuration for filter module.
     $this->installConfig(array('system', 'filter'));
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installSchema('system', ['key_value_expire']);
     \Drupal::service('router.builder')->rebuild();
     $this->testUser = User::create(array('name' => 'foobar1', 'mail' => '*****@*****.**'));
     $this->testUser->save();
     \Drupal::service('current_user')->setAccount($this->testUser);
     $this->testAutocreateUser = User::create(array('name' => 'foobar2', 'mail' => '*****@*****.**'));
     $this->testAutocreateUser->save();
     for ($i = 1; $i < 3; $i++) {
         $entity = EntityTest::create(array('name' => $this->randomMachineName()));
         $entity->save();
         $this->referencedEntities[] = $entity;
     }
 }
Beispiel #28
0
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('entity_test_rev');
     $entity_type = 'entity_test_rev';
     $this->fieldName = strtolower($this->randomMachineName());
     $this->fieldCardinality = 4;
     $this->fieldStorage = FieldStorageConfig::create(array('field_name' => $this->fieldName, 'entity_type' => $entity_type, 'type' => 'test_field', 'cardinality' => $this->fieldCardinality));
     $this->fieldStorage->save();
     $this->field = FieldConfig::create(['field_storage' => $this->fieldStorage, 'bundle' => $entity_type]);
     $this->field->save();
     /** @var \Drupal\Core\Entity\Sql\DefaultTableMapping $table_mapping */
     $table_mapping = \Drupal::entityManager()->getStorage($entity_type)->getTableMapping();
     $this->tableMapping = $table_mapping;
     $this->table = $table_mapping->getDedicatedDataTableName($this->fieldStorage);
     $this->revisionTable = $table_mapping->getDedicatedRevisionTableName($this->fieldStorage);
 }
Beispiel #29
0
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('file');
     $this->installSchema('node', array('node_access'));
     $this->installSchema('file', array('file_usage'));
     $this->installConfig(['node']);
     // Add text formats.
     $filtered_html_format = FilterFormat::create(array('format' => 'filtered_html', 'name' => 'Filtered HTML', 'weight' => 0, 'filters' => array()));
     $filtered_html_format->save();
     // Set cardinality for body field.
     FieldStorageConfig::loadByName('node', 'body')->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)->save();
     // Set up text editor.
     $editor = Editor::create(['format' => 'filtered_html', 'editor' => 'unicorn']);
     $editor->save();
     // Create a node type for testing.
     $type = NodeType::create(['type' => 'page', 'name' => 'page']);
     $type->save();
     node_add_body_field($type);
 }
 /**
  * Sets up the test.
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('file');
     $this->installSchema('system', ['key_value_expire']);
     $this->installSchema('node', array('node_access'));
     $this->installSchema('file', array('file_usage'));
     $this->installConfig(['node']);
     // Add text formats.
     $this->format = FilterFormat::create(['format' => 'filtered_html', 'name' => 'Filtered HTML', 'weight' => 0, 'filters' => ['filter_align' => ['status' => TRUE], 'filter_caption' => ['status' => TRUE]]]);
     $this->format->save();
     // Set up text editor.
     $editor = Editor::create(['format' => 'filtered_html', 'editor' => 'unicorn', 'image_upload' => ['max_size' => 100, 'scheme' => 'public', 'directory' => '', 'status' => TRUE]]);
     $editor->save();
     // Create a node type for testing.
     $type = NodeType::create(['type' => 'page', 'name' => 'page']);
     $type->save();
     node_add_body_field($type);
     $this->installEntitySchema('user');
     \Drupal::service('router.builder')->rebuild();
 }