function setUp()
 {
     parent::setUp();
     // Add two new languages.
     ConfigurableLanguage::createFromLangcode('fr')->save();
     ConfigurableLanguage::createFromLangcode('es')->save();
     // Set up term names.
     $this->termNames = array('en' => 'Food in Paris', 'es' => 'Comida en Paris', 'fr' => 'Nouriture en Paris');
     // Create a vocabulary.
     $this->vocabulary = Vocabulary::create(['name' => 'Views testing tags', 'vid' => 'views_testing_tags']);
     $this->vocabulary->save();
     // Add a translatable field to the vocabulary.
     $field = FieldStorageConfig::create(array('field_name' => 'field_foo', 'entity_type' => 'taxonomy_term', 'type' => 'text'));
     $field->save();
     FieldConfig::create(['field_name' => 'field_foo', 'entity_type' => 'taxonomy_term', 'label' => 'Foo', 'bundle' => 'views_testing_tags'])->save();
     // Create term with translations.
     $taxonomy = $this->createTermWithProperties(array('name' => $this->termNames['en'], 'langcode' => 'en', 'description' => $this->termNames['en'], 'field_foo' => $this->termNames['en']));
     foreach (array('es', 'fr') as $langcode) {
         $translation = $taxonomy->addTranslation($langcode, array('name' => $this->termNames[$langcode]));
         $translation->description->value = $this->termNames[$langcode];
         $translation->field_foo->value = $this->termNames[$langcode];
     }
     $taxonomy->save();
     Views::viewsData()->clear();
     ViewTestData::createTestViews(get_class($this), array('taxonomy_test_views'));
     $this->container->get('router.builder')->rebuild();
 }
 /**
  * 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 = Vocabulary::create(['name' => $this->randomMachineName(), 'vid' => Unicode::strtolower($this->randomMachineName()), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED]);
     $this->vocabulary->save();
     $this->term = Term::create(['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');
 }
 /**
  * {@inheritdoc}
  */
 protected function setupBundle()
 {
     parent::setupBundle();
     // Create a vocabulary.
     $this->vocabulary = Vocabulary::create(['name' => $this->bundle, 'description' => $this->randomMachineName(), 'vid' => $this->bundle, 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, 'weight' => mt_rand(0, 10)]);
     $this->vocabulary->save();
 }
 protected function setUp()
 {
     parent::setUp();
     // Create the vocabulary for the tag field.
     $this->vocabulary = entity_create('taxonomy_vocabulary', array('name' => 'Views testing tags', 'vid' => 'views_testing_tags'));
     $this->vocabulary->save();
     $this->term1 = $this->createTerm('term');
     $this->term2 = $this->createTerm('another');
 }
 /**
  * Sets up the test.
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('taxonomy_term');
     $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();
     // 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_taxonomy_vocabulary', 'Test config entity reference', 'taxonomy_vocabulary');
 }
示例#6
0
 /**
  * Provides a workaround for the inability to use the standard profile.
  *
  * @see http://drupal.org/node/1708692
  */
 protected function mockStandardInstall()
 {
     $this->drupalCreateContentType(array('type' => 'article'));
     // Create the vocabulary for the tag field.
     $this->vocabulary = entity_create('taxonomy_vocabulary', array('name' => 'Views testing tags', 'vid' => 'views_testing_tags'));
     $this->vocabulary->save();
     $field_name = 'field_' . $this->vocabulary->id();
     $handler_settings = array('target_bundles' => array($this->vocabulary->id() => $this->vocabulary->id()), 'auto_create' => TRUE);
     $this->createEntityReferenceField('node', 'article', $field_name, 'Tags', 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
     entity_get_form_display('node', 'article', 'default')->setComponent($field_name, array('type' => 'entity_reference_autocomplete_tags', 'weight' => -4))->save();
     entity_get_display('node', 'article', 'default')->setComponent($field_name, array('type' => 'entity_reference_label', 'weight' => 10))->save();
     entity_get_display('node', 'article', 'teaser')->setComponent($field_name, array('type' => 'entity_reference_label', 'weight' => 10))->save();
 }
 /**
  * Provides a workaround for the inability to use the standard profile.
  *
  * @see http://drupal.org/node/1708692
  */
 protected function mockStandardInstall()
 {
     $this->drupalCreateContentType(array('type' => 'article'));
     // Create the vocabulary for the tag field.
     $this->vocabulary = entity_create('taxonomy_vocabulary', array('name' => 'Views testing tags', 'vid' => 'views_testing_tags'));
     $this->vocabulary->save();
     $field_name = 'field_' . $this->vocabulary->id();
     entity_create('field_storage_config', array('field_name' => $field_name, 'entity_type' => 'node', 'type' => 'taxonomy_term_reference', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, 'settings' => array('allowed_values' => array(array('vocabulary' => $this->vocabulary->id(), 'parent' => 0)))))->save();
     entity_create('field_config', array('field_name' => $field_name, 'entity_type' => 'node', 'label' => 'Tags', 'bundle' => 'article'))->save();
     entity_get_form_display('node', 'article', 'default')->setComponent($field_name, array('type' => 'taxonomy_autocomplete', 'weight' => -4))->save();
     entity_get_display('node', 'article', 'default')->setComponent($field_name, array('type' => 'taxonomy_term_reference_link', 'weight' => 10))->save();
     entity_get_display('node', 'article', 'teaser')->setComponent($field_name, array('type' => 'taxonomy_term_reference_link', 'weight' => 10))->save();
 }
示例#8
0
 protected function setUp()
 {
     parent::setUp();
     // Create two content types. One will have an autocomplete tagging field,
     // and one won't.
     $this->nodeTypeWithTags = $this->drupalCreateContentType();
     $this->nodeTypeWithoutTags = $this->drupalCreateContentType();
     // Create the vocabulary for the tag field.
     $this->tagVocabulary = entity_create('taxonomy_vocabulary', array('name' => 'Views testing tags', 'vid' => 'views_testing_tags'));
     $this->tagVocabulary->save();
     // Create the tag field itself.
     $this->tagFieldName = 'field_views_testing_tags';
     $handler_settings = array('target_bundles' => array($this->tagVocabulary->id() => $this->tagVocabulary->id()), 'auto_create' => TRUE);
     $this->createEntityReferenceField('node', $this->nodeTypeWithTags->id(), $this->tagFieldName, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
     entity_get_form_display('node', $this->nodeTypeWithTags->id(), 'default')->setComponent($this->tagFieldName, array('type' => 'entity_reference_autocomplete_tags'))->save();
     entity_get_display('node', $this->nodeTypeWithTags->id(), 'default')->setComponent($this->tagFieldName, array('type' => 'entity_reference_label', 'weight' => 10))->save();
     entity_get_display('node', $this->nodeTypeWithTags->id(), 'teaser')->setComponent('field_views_testing_tags', array('type' => 'entity_reference_label', 'weight' => 10))->save();
 }
 /**
  * Prepares the testing environment
  */
 public function setUp()
 {
     parent::setUp();
     // Create Basic page and Article node types.
     if ($this->profile != 'standard') {
         $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic Page'));
         $this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article'));
         $this->addDefaultCommentField('node', 'article');
     }
     // Creating a vocabulary to associate taxonomy terms generated.
     $this->vocabulary = entity_create('taxonomy_vocabulary', array('name' => $this->randomMachineName(), 'description' => $this->randomMachineName(), 'vid' => Unicode::strtolower($this->randomMachineName()), 'langcode' => Language::LANGCODE_NOT_SPECIFIED, 'weight' => mt_rand(0, 10)));
     $this->vocabulary->save();
     // Creates a field of an entity reference field storage on article.
     $field_name = 'taxonomy_' . $this->vocabulary->id();
     $handler_settings = array('target_bundles' => array($this->vocabulary->id() => $this->vocabulary->id()), 'auto_create' => TRUE);
     $this->createEntityReferenceField('node', 'article', $field_name, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
     entity_get_form_display('node', 'article', 'default')->setComponent($field_name, array('type' => 'options_select'))->save();
     entity_get_display('node', 'article', 'default')->setComponent($field_name, array('type' => 'entity_reference_label'))->save();
     $admin_user = $this->drupalCreateUser(array('administer devel_generate'));
     $this->drupalLogin($admin_user);
 }
 protected function setUp()
 {
     parent::setUp();
     $type = $this->drupalCreateContentType(array('type' => 'article'));
     // Create the vocabulary for the tag field.
     $this->vocabulary = entity_create('taxonomy_vocabulary', array('name' => 'quickedit testing tags', 'vid' => 'quickedit_testing_tags'));
     $this->vocabulary->save();
     $this->field_name = 'field_' . $this->vocabulary->id();
     entity_create('field_storage_config', array('name' => $this->field_name, 'entity_type' => 'node', 'type' => 'taxonomy_term_reference', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, 'settings' => array('allowed_values' => array(array('vocabulary' => $this->vocabulary->id(), 'parent' => 0)))))->save();
     entity_create('field_instance_config', array('field_name' => $this->field_name, 'entity_type' => 'node', 'label' => 'Tags', 'bundle' => 'article'))->save();
     entity_get_form_display('node', 'article', 'default')->setComponent($this->field_name, array('type' => 'taxonomy_autocomplete', 'weight' => -4))->save();
     entity_get_display('node', 'article', 'default')->setComponent($this->field_name, array('type' => 'taxonomy_term_reference_link', 'weight' => 10))->save();
     entity_get_display('node', 'article', 'teaser')->setComponent($this->field_name, array('type' => 'taxonomy_term_reference_link', 'weight' => 10))->save();
     $this->term1 = $this->createTerm();
     $this->term2 = $this->createTerm();
     $node = array();
     $node['type'] = 'article';
     $node[$this->field_name][]['target_id'] = $this->term1->id();
     $node[$this->field_name][]['target_id'] = $this->term2->id();
     $this->node = $this->drupalCreateNode($node);
     $this->editor_user = $this->drupalCreateUser(array('access content', 'create article content', 'edit any article content', 'access in-place editing'));
 }
 protected function setUp()
 {
     parent::setUp();
     $this->drupalCreateContentType(array('type' => 'article'));
     // Create the vocabulary for the tag field.
     $this->vocabulary = entity_create('taxonomy_vocabulary', ['name' => 'quickedit testing tags', 'vid' => 'quickedit_testing_tags']);
     $this->vocabulary->save();
     $this->fieldName = 'field_' . $this->vocabulary->id();
     $handler_settings = array('target_bundles' => array($this->vocabulary->id() => $this->vocabulary->id()), 'auto_create' => TRUE);
     $this->createEntityReferenceField('node', 'article', $this->fieldName, 'Tags', 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
     entity_get_form_display('node', 'article', 'default')->setComponent($this->fieldName, ['type' => 'entity_reference_autocomplete_tags', 'weight' => -4])->save();
     entity_get_display('node', 'article', 'default')->setComponent($this->fieldName, ['type' => 'entity_reference_label', 'weight' => 10])->save();
     entity_get_display('node', 'article', 'teaser')->setComponent($this->fieldName, ['type' => 'entity_reference_label', 'weight' => 10])->save();
     $this->term1 = $this->createTerm();
     $this->term2 = $this->createTerm();
     $node = array();
     $node['type'] = 'article';
     $node[$this->fieldName][]['target_id'] = $this->term1->id();
     $node[$this->fieldName][]['target_id'] = $this->term2->id();
     $this->node = $this->drupalCreateNode($node);
     $this->editorUser = $this->drupalCreateUser(['access content', 'create article content', 'edit any article content', 'access in-place editing']);
 }
示例#12
0
 protected function setUp()
 {
     parent::setUp();
     // Create two content types. One will have an autocomplete tagging field,
     // and one won't.
     $this->nodeTypeWithTags = $this->drupalCreateContentType();
     $this->nodeTypeWithoutTags = $this->drupalCreateContentType();
     // Create the vocabulary for the tag field.
     $this->tagVocabulary = entity_create('taxonomy_vocabulary', array('name' => 'Views testing tags', 'vid' => 'views_testing_tags'));
     $this->tagVocabulary->save();
     // Create the tag field itself.
     $this->tagFieldName = 'field_views_testing_tags';
     $this->tagFieldStorage = entity_create('field_storage_config', array('field_name' => $this->tagFieldName, 'entity_type' => 'node', 'type' => 'taxonomy_term_reference', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, 'settings' => array('allowed_values' => array(array('vocabulary' => $this->tagVocabulary->id(), 'parent' => 0)))));
     $this->tagFieldStorage->save();
     // Create an instance of the tag field on one of the content types, and
     // configure it to display an autocomplete widget.
     $this->tagField = array('field_storage' => $this->tagFieldStorage, 'bundle' => $this->nodeTypeWithTags->id());
     entity_create('field_config', $this->tagField)->save();
     entity_get_form_display('node', $this->nodeTypeWithTags->id(), 'default')->setComponent('field_views_testing_tags', array('type' => 'taxonomy_autocomplete'))->save();
     entity_get_display('node', $this->nodeTypeWithTags->id(), 'default')->setComponent('field_views_testing_tags', array('type' => 'taxonomy_term_reference_link', 'weight' => 10))->save();
     entity_get_display('node', $this->nodeTypeWithTags->id(), 'teaser')->setComponent('field_views_testing_tags', array('type' => 'taxonomy_term_reference_link', 'weight' => 10))->save();
 }
示例#13
0
 /**
  * Tests that vocabulary machine name changes are mirrored in field definitions.
  */
 function testTaxonomyTermFieldChangeMachineName()
 {
     // Add several entries in the 'allowed_values' setting, to make sure that
     // they all get updated.
     $this->fieldStorage->setSetting('allowed_values', [array('vocabulary' => $this->vocabulary->id(), 'parent' => '0'), array('vocabulary' => $this->vocabulary->id(), 'parent' => '0'), array('vocabulary' => 'foo', 'parent' => '0')]);
     $this->fieldStorage->save();
     // Change the machine name.
     $new_name = Unicode::strtolower($this->randomMachineName());
     $this->vocabulary->set('vid', $new_name);
     $this->vocabulary->save();
     // Check that the field is still attached to the vocabulary.
     $field_storage = FieldStorageConfig::loadByName('entity_test', $this->fieldName);
     $allowed_values = $field_storage->getSetting('allowed_values');
     $this->assertEqual($allowed_values[0]['vocabulary'], $new_name, 'Index 0: Machine name was updated correctly.');
     $this->assertEqual($allowed_values[1]['vocabulary'], $new_name, 'Index 1: Machine name was updated correctly.');
     $this->assertEqual($allowed_values[2]['vocabulary'], 'foo', 'Index 2: Machine name was left untouched.');
 }