Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->drupalPlaceBlock('system_breadcrumb_block');
     $this->drupalPlaceBlock('local_actions_block');
     $this->drupalPlaceBlock('local_tasks_block');
     $this->drupalPlaceBlock('page_title_block');
     // Create a test user.
     $admin_user = $this->drupalCreateUser(array('access content', 'administer content types', 'administer node fields', 'administer node form display', 'administer node display', 'administer taxonomy', 'administer taxonomy_term fields', 'administer taxonomy_term display', 'administer users', 'administer account settings', 'administer user display', 'bypass node access'));
     $this->drupalLogin($admin_user);
     // Create content type, with underscores.
     $type_name = strtolower($this->randomMachineName(8)) . '_test';
     $type = $this->drupalCreateContentType(array('name' => $type_name, 'type' => $type_name));
     $this->contentType = $type->id();
     // Create random field name with markup to test escaping.
     $this->fieldLabel = '<em>' . $this->randomMachineName(8) . '</em>';
     $this->fieldNameInput = strtolower($this->randomMachineName(8));
     $this->fieldName = 'field_' . $this->fieldNameInput;
     // Create Basic page and Article node types.
     $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
     $this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article'));
     // Create a vocabulary named "Tags".
     $vocabulary = Vocabulary::create(array('name' => 'Tags', 'vid' => 'tags', 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED));
     $vocabulary->save();
     $handler_settings = array('target_bundles' => array($vocabulary->id() => $vocabulary->id()));
     $this->createEntityReferenceField('node', 'article', 'field_' . $vocabulary->id(), 'Tags', 'taxonomy_term', 'default', $handler_settings);
     entity_get_form_display('node', 'article', 'default')->setComponent('field_' . $vocabulary->id())->save();
 }
 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');
 }
 protected function setUp()
 {
     parent::setUp();
     $this->drupalPlaceBlock('page_title_block');
     // Create Basic page node type.
     $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
     $vocabulary = Vocabulary::create(['name' => $this->randomMachineName(), 'description' => $this->randomMachineName(), 'vid' => Unicode::strtolower($this->randomMachineName()), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, 'help' => '', 'nodes' => array('page' => 'page'), 'weight' => mt_rand(0, 10)]);
     $vocabulary->save();
     // Create a field.
     $field_name = Unicode::strtolower($this->randomMachineName());
     $handler_settings = array('target_bundles' => array($vocabulary->id() => $vocabulary->id()), 'auto_create' => TRUE);
     $this->createEntityReferenceField('node', 'page', $field_name, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
     // Create a time in the past for the archive.
     $time = REQUEST_TIME - 3600;
     $this->addDefaultCommentField('node', 'page');
     for ($i = 0; $i <= 10; $i++) {
         $user = $this->drupalCreateUser();
         $term = $this->createTerm($vocabulary);
         $values = array('created' => $time, 'type' => 'page');
         $values[$field_name][]['target_id'] = $term->id();
         // Make every other node promoted.
         if ($i % 2) {
             $values['promote'] = TRUE;
         }
         $values['body'][]['value'] = \Drupal::l('Node ' . 1, new Url('entity.node.canonical', ['node' => 1]));
         $node = $this->drupalCreateNode($values);
         $comment = array('uid' => $user->id(), 'status' => CommentInterface::PUBLISHED, 'entity_id' => $node->id(), 'entity_type' => 'node', 'field_name' => 'comment');
         Comment::create($comment)->save();
     }
     // Some views, such as the "Who's Online" view, only return results if at
     // least one user is logged in.
     $account = $this->drupalCreateUser(array());
     $this->drupalLogin($account);
 }
Esempio n. 4
0
 protected function setUp()
 {
     parent::setUp();
     $this->addDefaultCommentField('node', 'page');
     $web_user = $this->drupalCreateUser(array('edit own page content', 'create page content'));
     $this->drupalLogin($web_user);
     // Add a vocabulary so we can test different view modes.
     $vocabulary = Vocabulary::create(['name' => $this->randomMachineName(), 'description' => $this->randomMachineName(), 'vid' => $this->randomMachineName(), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, 'help' => '']);
     $vocabulary->save();
     $this->vocabulary = $vocabulary;
     // Add a term to the vocabulary.
     $term = Term::create(['name' => $this->randomMachineName(), 'description' => $this->randomMachineName(), 'vid' => $this->vocabulary->id(), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED]);
     $term->save();
     $this->term = $term;
     // Create an image field.
     FieldStorageConfig::create(['field_name' => 'field_image', 'entity_type' => 'node', 'type' => 'image', 'settings' => [], 'cardinality' => FieldStorageConfig::CARDINALITY_UNLIMITED])->save();
     $field_config = FieldConfig::create(['field_name' => 'field_image', 'label' => 'Images', 'entity_type' => 'node', 'bundle' => 'page', 'required' => FALSE, 'settings' => []]);
     $field_config->save();
     // Create a field.
     $this->fieldName = Unicode::strtolower($this->randomMachineName());
     $handler_settings = array('target_bundles' => array($this->vocabulary->id() => $this->vocabulary->id()), 'auto_create' => TRUE);
     $this->createEntityReferenceField('node', 'page', $this->fieldName, 'Tags', 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
     entity_get_form_display('node', 'page', 'default')->setComponent($this->fieldName, array('type' => 'entity_reference_autocomplete_tags'))->save();
     // Show on default display and teaser.
     entity_get_display('node', 'page', 'default')->setComponent($this->fieldName, array('type' => 'entity_reference_label'))->save();
     entity_get_display('node', 'page', 'teaser')->setComponent($this->fieldName, array('type' => 'entity_reference_label'))->save();
     entity_get_form_display('node', 'page', 'default')->setComponent('field_image', array('type' => 'image_image', 'settings' => []))->save();
     entity_get_display('node', 'page', 'default')->setComponent('field_image')->save();
 }
Esempio n. 5
0
 /**
  * Returns a new vocabulary with random properties.
  */
 function createVocabulary()
 {
     // Create a vocabulary.
     $vocabulary = Vocabulary::create(['name' => $this->randomMachineName(), 'description' => $this->randomMachineName(), 'vid' => Unicode::strtolower($this->randomMachineName()), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, 'weight' => mt_rand(0, 10)]);
     $vocabulary->save();
     return $vocabulary;
 }
Esempio n. 6
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->drupalPlaceBlock('system_breadcrumb_block');
     $this->drupalPlaceBlock('local_tasks_block');
     // Create a test user.
     $this->adminUser = $this->drupalCreateUser(array('access content', 'admin classes', 'admin display suite', 'admin fields', 'administer nodes', 'view all revisions', 'administer content types', 'administer node fields', 'administer node form display', 'administer node display', 'administer taxonomy', 'administer taxonomy_term fields', 'administer taxonomy_term display', 'administer users', 'administer permissions', 'administer account settings', 'administer user display', 'administer software updates', 'access site in maintenance mode', 'administer site configuration', 'bypass node access', 'ds switch view mode'));
     $this->drupalLogin($this->adminUser);
     // Create random field name.
     $this->fieldLabel = $this->randomMachineName(8);
     $this->fieldNameInput = strtolower($this->randomMachineName(8));
     $this->fieldName = 'field_' . $this->fieldNameInput;
     // Create Article node type.
     $this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article', 'revision' => TRUE));
     $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Page', 'revision' => TRUE));
     // Create a vocabulary named "Tags".
     $this->vocabulary = Vocabulary::create(array('name' => 'Tags', 'vid' => 'tags', 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED));
     $this->vocabulary->save();
     $term1 = Term::create(array('name' => 'Tag 1', 'vid' => 'tags', 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED));
     $term1->save();
     $term2 = Term::create(array('name' => 'Tag 2', 'vid' => 'tags', 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED));
     $term2->save();
     $handler_settings = array('target_bundles' => array($this->vocabulary->id() => $this->vocabulary->id()), 'auto_create' => TRUE);
     $this->createEntityReferenceField('node', 'article', 'field_' . $this->vocabulary->id(), 'Tags', 'taxonomy_term', 'default', $handler_settings, 10);
     entity_get_form_display('node', 'article', 'default')->setComponent('field_' . $this->vocabulary->id())->save();
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('node');
     $this->installEntitySchema('comment');
     $this->installEntitySchema('taxonomy_term');
     CommentType::create(['id' => 'comment_node_page', 'label' => $this->randomMachineName()])->save();
     CommentType::create(['id' => 'comment_node_article', 'label' => $this->randomMachineName()])->save();
     CommentType::create(['id' => 'comment_node_blog', 'label' => $this->randomMachineName()])->save();
     CommentType::create(['id' => 'comment_node_book', 'label' => $this->randomMachineName()])->save();
     CommentType::create(['id' => 'comment_node_forum', 'label' => $this->randomMachineName()])->save();
     CommentType::create(['id' => 'comment_node_test_content_type', 'label' => $this->randomMachineName()])->save();
     NodeType::create(['type' => 'page', 'label' => $this->randomMachineName()])->save();
     NodeType::create(['type' => 'article', 'label' => $this->randomMachineName()])->save();
     NodeType::create(['type' => 'blog', 'label' => $this->randomMachineName()])->save();
     NodeType::create(['type' => 'book', 'label' => $this->randomMachineName()])->save();
     NodeType::create(['type' => 'forum', 'label' => $this->randomMachineName()])->save();
     NodeType::create(['type' => 'test_content_type', 'label' => $this->randomMachineName()])->save();
     Vocabulary::create(['vid' => 'test_vocabulary'])->save();
     // Give one unfortunate field instance invalid display settings to ensure
     // that the migration provides an empty array as a default (thus avoiding
     // an "unsupported operand types" fatal).
     Database::getConnection('default', 'migrate')->update('field_config_instance')->fields(array('data' => serialize(array('label' => 'Body', 'widget' => array('type' => 'text_textarea_with_summary', 'settings' => array('rows' => 20, 'summary_rows' => 5), 'weight' => -4, 'module' => 'text'), 'settings' => array('display_summary' => TRUE, 'text_processing' => 1, 'user_register_form' => FALSE), 'display' => array('default' => array('label' => 'hidden', 'type' => 'text_default', 'settings' => array(), 'module' => 'text', 'weight' => 0), 'teaser' => array('label' => 'hidden', 'type' => 'text_summary_or_trimmed', 'settings' => NULL, 'module' => 'text', 'weight' => 0)), 'required' => FALSE, 'description' => ''))))->condition('entity_type', 'node')->condition('bundle', 'article')->condition('field_name', 'body')->execute();
     $this->executeMigrations(['d7_field', 'd7_field_instance', 'd7_view_modes', 'd7_field_formatter_settings']);
 }
 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();
 }
Esempio n. 9
0
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('taxonomy_term');
     // Create the default tags vocabulary.
     $vocabulary = Vocabulary::create(['name' => 'Tags', 'vid' => 'tags']);
     $vocabulary->save();
     $this->vocab = $vocabulary;
 }
Esempio n. 10
0
 /**
  * {@inheritdoc}
  */
 protected function createEntity()
 {
     // Create a "Camelids" vocabulary.
     $vocabulary = Vocabulary::create(['name' => 'Camelids', 'vid' => 'camelids']);
     $vocabulary->save();
     // Create a "Llama" taxonomy term.
     $term = Term::create(['name' => 'Llama', 'vid' => $vocabulary->id()]);
     $term->save();
     return $term;
 }
Esempio n. 11
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('taxonomy_vocabulary');
     $this->installEntitySchema('taxonomy_term');
     $this->installConfig(['taxonomy']);
     // Set up two vocabularies (taxonomy bundles).
     Vocabulary::create(['vid' => 'tags', 'name' => 'Tags']);
     Vocabulary::create(['vid' => 'categories', 'name' => 'Categories']);
 }
Esempio n. 12
0
 protected function setUp()
 {
     parent::setUp();
     // Create a Tags vocabulary for the Article node type.
     $vocabulary = Vocabulary::create(['name' => t('Tags'), 'vid' => 'tags']);
     $vocabulary->save();
     // Create and log in user.
     $web_user = $this->drupalCreateUser(array('administer url aliases', 'administer taxonomy', 'access administration pages'));
     $this->drupalLogin($web_user);
 }
Esempio n. 13
0
 protected function setUp()
 {
     parent::setUp();
     // Create a tags vocabulary for the 'article' content type.
     $vocabulary = Vocabulary::create(['name' => 'Tags', 'vid' => 'tags']);
     $vocabulary->save();
     $field_name = 'field_' . $vocabulary->id();
     $handler_settings = array('target_bundles' => array($vocabulary->id() => $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'))->save();
     $this->drupalLogin($this->drupalCreateUser(['administer taxonomy', 'administer nodes', 'bypass node access']));
 }
Esempio n. 14
0
 protected function setUp()
 {
     parent::setUp();
     $this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
     Vocabulary::create(['vid' => 'tags', 'name' => 'Tags'])->save();
     FieldStorageConfig::create(['field_name' => 'field_tags', 'entity_type' => 'node', 'type' => 'entity_reference', 'settings' => ['target_type' => 'taxonomy_term'], 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED])->save();
     FieldConfig::create(['label' => 'Tags', 'description' => '', 'field_name' => 'field_tags', 'entity_type' => 'node', 'bundle' => 'article', 'settings' => ['handler_settings' => ['target_bundles' => ['tags' => 'tags']]]])->save();
     $web_user = $this->drupalCreateUser(['administer feeds', 'bypass node access']);
     $this->drupalLogin($web_user);
     $this->type = entity_create('feeds_feed_type', ['id' => Unicode::strtolower($this->randomMachineName()), 'mappings' => [['target' => 'title', 'map' => ['value' => 'title']], ['target' => 'body', 'map' => ['value' => 'description']], ['target' => 'feeds_item', 'map' => ['guid' => 'guid', 'url' => 'url'], 'unique' => ['guid' => TRUE]], ['target' => 'created', 'map' => ['value' => 'timestamp']], ['target' => 'field_tags', 'map' => ['target_id' => 'tags'], 'settings' => ['autocreate' => TRUE]]], 'processor' => 'entity:node', 'processor_configuration' => ['values' => ['type' => 'article']], 'import_period' => FeedTypeInterface::SCHEDULE_NEVER]);
     $this->type->save();
 }
 /**
  * Provides a workaround for the inability to use the standard profile.
  *
  * @see https://www.drupal.org/node/1708692
  */
 protected function mockStandardInstall()
 {
     $this->drupalCreateContentType(array('type' => 'article'));
     // Create the vocabulary for the tag field.
     $this->vocabulary = Vocabulary::create(['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();
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installConfig(static::$modules);
     $this->createType('page');
     $this->createType('article');
     $this->createType('blog');
     $this->createType('book');
     $this->createType('forum');
     $this->createType('test_content_type');
     Vocabulary::create(['vid' => 'test_vocabulary'])->save();
     $this->executeMigrations(['d7_field', 'd7_field_instance']);
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setup();
     $this->installEntitySchema('node');
     $this->installEntitySchema('taxonomy_term');
     $this->installEntitySchema('entity_test');
     $this->nodeType = NodeType::create(['type' => Unicode::strtolower($this->randomMachineName()), 'name' => $this->randomString()]);
     $this->nodeType->save();
     $this->vocabulary = Vocabulary::create(['vid' => Unicode::strtolower($this->randomMachineName()), 'name' => $this->randomString()]);
     $this->vocabulary->save();
     // Create a custom bundle.
     $this->customBundle = 'test_bundle_' . Unicode::strtolower($this->randomMachineName());
     entity_test_create_bundle($this->customBundle, NULL, 'entity_test');
 }
Esempio n. 18
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     // Prepare to migrate user pictures as well.
     $this->installEntitySchema('file');
     $this->createType('page');
     $this->createType('article');
     $this->createType('blog');
     $this->createType('book');
     $this->createType('forum');
     $this->createType('test_content_type');
     Vocabulary::create(['vid' => 'test_vocabulary'])->save();
     $this->executeMigrations(['user_picture_field', 'user_picture_field_instance', 'd7_user_role', 'd7_field', 'd7_field_instance', 'd7_user']);
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp(FALSE);
     // Setup vocabulary and terms so the initial import is valid.
     Vocabulary::create(['vid' => 'tags', 'name' => 'Tags'])->save();
     // This will get a term ID of 3.
     $term = Term::create(['vid' => 'tags', 'name' => 'muh']);
     $term->save();
     // This will get a term ID of 4.
     $this->terms[$term->id()] = $term;
     $term = Term::create(['vid' => 'tags', 'name' => 'muh']);
     $term->save();
     $this->terms[$term->id()] = $term;
     ViewTestData::createTestViews(get_class($this), array('taxonomy_test_views'));
 }
Esempio n. 20
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->drupalPlaceBlock('system_breadcrumb_block');
     // Create a test user.
     $admin_user = $this->drupalCreateUser(array('access content', 'administer content types', 'administer node fields', 'administer node form display', 'administer node display', 'administer taxonomy', 'administer taxonomy_term fields', 'administer taxonomy_term display', 'administer users', 'administer account settings', 'administer user display', 'bypass node access'));
     $this->drupalLogin($admin_user);
     // Create content type, with underscores.
     $type_name = strtolower($this->randomMachineName(8)) . '_test';
     $type = $this->drupalCreateContentType(array('name' => $type_name, 'type' => $type_name));
     $this->type = $type->id();
     // Create a default vocabulary.
     $vocabulary = Vocabulary::create(array('name' => $this->randomMachineName(), 'description' => $this->randomMachineName(), 'vid' => Unicode::strtolower($this->randomMachineName()), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, 'help' => '', 'nodes' => array('article' => 'article'), 'weight' => mt_rand(0, 10)));
     $vocabulary->save();
     $this->vocabulary = $vocabulary->id();
 }
Esempio n. 21
0
 /**
  * Tests the entity row handler.
  */
 public function testEntityRow()
 {
     $vocab = Vocabulary::create(['name' => $this->randomMachineName(), 'vid' => strtolower($this->randomMachineName())]);
     $vocab->save();
     $term = Term::create(['name' => $this->randomMachineName(), 'vid' => $vocab->id()]);
     $term->save();
     $view = Views::getView('test_entity_row');
     $build = $view->preview();
     $this->render($build);
     $this->assertText($term->getName(), 'The rendered entity appears as row in the view.');
     // Tests the available view mode options.
     $form = array();
     $form_state = new FormState();
     $form_state->set('view', $view->storage);
     $view->rowPlugin->buildOptionsForm($form, $form_state);
     $this->assertTrue(isset($form['view_mode']['#options']['default']), 'Ensure that the default view mode is available');
 }
Esempio n. 22
0
 /**
  * Tests the normalization of terms.
  */
 public function testTerm()
 {
     $vocabulary = Vocabulary::create(['vid' => 'example_vocabulary']);
     $vocabulary->save();
     $account = User::create(['name' => $this->randomMachineName()]);
     $account->save();
     // @todo Until https://www.drupal.org/node/2327935 is fixed, if no parent is
     // set, the test fails because target_id => 0 is reserialized to NULL.
     $term_parent = Term::create(['name' => $this->randomMachineName(), 'vid' => $vocabulary->id()]);
     $term_parent->save();
     $term = Term::create(['name' => $this->randomMachineName(), 'vid' => $vocabulary->id(), 'description' => array('value' => $this->randomMachineName(), 'format' => $this->randomMachineName()), 'parent' => $term_parent->id()]);
     $term->save();
     $original_values = $term->toArray();
     $normalized = $this->serializer->normalize($term, $this->format, ['account' => $account]);
     /** @var \Drupal\taxonomy\TermInterface $denormalized_term */
     $denormalized_term = $this->serializer->denormalize($normalized, 'Drupal\\taxonomy\\Entity\\Term', $this->format, ['account' => $account]);
     $this->assertEqual($original_values, $denormalized_term->toArray(), 'Term values are restored after normalizing and denormalizing.');
 }
Esempio n. 23
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 = Vocabulary::create(['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();
 }
Esempio n. 24
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     Vocabulary::create(['vid' => 'tags', 'name' => 'Tags'])->save();
     // Setup a hierarchy which looks like this:
     // term 0.0
     // term 1.0
     // - term 1.1
     // term 2.0
     // - term 2.1
     // - term 2.2
     for ($i = 0; $i < 3; $i++) {
         for ($j = 0; $j <= $i; $j++) {
             $this->terms[$i][$j] = $term = Term::create(['vid' => 'tags', 'name' => "Term {$i}.{$j}", 'parent' => isset($terms[$i][0]) ? $terms[$i][0]->id() : 0]);
             $term->save();
         }
     }
     ViewTestData::createTestViews(get_class($this), array('taxonomy_test_views'));
 }
 /**
  * Tests exportContent().
  */
 public function testExportContent()
 {
     \Drupal::service('module_installer')->install(['taxonomy', 'default_content']);
     \Drupal::service('router.builder')->rebuild();
     $this->defaultContentManager = \Drupal::service('default_content.manager');
     $vocabulary = Vocabulary::create(['vid' => 'test']);
     $vocabulary->save();
     $term = Term::create(['vid' => $vocabulary->id(), 'name' => 'test_name']);
     $term->save();
     $term = Term::load($term->id());
     /** @var \Symfony\Component\Serializer\Serializer $serializer */
     $serializer = \Drupal::service('serializer');
     \Drupal::service('rest.link_manager')->setLinkDomain(DefaultContentManager::LINK_DOMAIN);
     $expected = $serializer->serialize($term, 'hal_json', ['json_encode_options' => JSON_PRETTY_PRINT]);
     $exported = $this->defaultContentManager->exportContent('taxonomy_term', $term->id());
     $exported_decoded = json_decode($exported);
     // Ensure the proper UUID is part of it.
     $this->assertEqual($exported_decoded->uuid[0]->value, $term->uuid());
     $this->assertEqual($exported, $expected);
 }
 /**
  * Check access for taxonomy fields.
  */
 public function testTermFields()
 {
     $vocab = Vocabulary::create(['vid' => 'random', 'name' => 'Randomness']);
     $vocab->save();
     $term1 = Term::create(['name' => 'Semi random', 'vid' => $vocab->id()]);
     $term1->save();
     $term2 = Term::create(['name' => 'Majorly random', 'vid' => $vocab->id()]);
     $term2->save();
     $term3 = Term::create(['name' => 'Not really random', 'vid' => $vocab->id()]);
     $term3->save();
     $this->assertFieldAccess('taxonomy_term', 'name', 'Majorly random');
     $this->assertFieldAccess('taxonomy_term', 'name', 'Semi random');
     $this->assertFieldAccess('taxonomy_term', 'name', 'Not really random');
     $this->assertFieldAccess('taxonomy_term', 'tid', $term1->id());
     $this->assertFieldAccess('taxonomy_term', 'tid', $term2->id());
     $this->assertFieldAccess('taxonomy_term', 'tid', $term3->id());
     $this->assertFieldAccess('taxonomy_term', 'uuid', $term1->uuid());
     $this->assertFieldAccess('taxonomy_term', 'uuid', $term2->uuid());
     $this->assertFieldAccess('taxonomy_term', 'uuid', $term3->uuid());
 }
 public function testTitleOptionsFromTaxonomy()
 {
     $field = $this->createNameField('field_name_test', 'entity_test', 'entity_test');
     $vocabulary = Vocabulary::create(array('vid' => 'title_options', 'name' => 'Title options'));
     $vocabulary->save();
     foreach (array('foo', 'bar', 'baz') as $name) {
         $term = Term::create(array('name' => $name, 'vid' => $vocabulary->id()));
         $term->save();
     }
     /**
      * @var \Drupal\field\Entity\FieldStorageConfig $field_storage
      */
     $field_storage = $field->getFieldStorageDefinition();
     $settings = $field_storage->getSettings();
     $settings['title_options'] = array('-- --', '[vocabulary:title_options]');
     $settings['sort_options']['title'] = TRUE;
     $field_storage->set('settings', $settings);
     $field_storage->save();
     $expected = array('' => '--', 'bar' => 'bar', 'baz' => 'baz', 'foo' => 'foo');
     $this->assertEqual($expected, $this->optionsProvider->getOptions($field, 'title'));
 }
 protected function setUp()
 {
     parent::setUp();
     $this->drupalCreateContentType(array('type' => 'article'));
     // Create the vocabulary for the tag field.
     $this->vocabulary = Vocabulary::create(['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']);
 }
Esempio n. 29
0
 /**
  * Tests that the taxonomy index work correctly with forward revisions.
  */
 public function testTaxonomyIndexWithForwardRevision()
 {
     \Drupal::configFactory()->getEditable('taxonomy.settings')->set('maintain_index_table', TRUE)->save();
     Vocabulary::create(['name' => 'test', 'vid' => 'test'])->save();
     $term = Term::create(['name' => 'term1', 'vid' => 'test']);
     $term->save();
     $term2 = Term::create(['name' => 'term2', 'vid' => 'test']);
     $term2->save();
     NodeType::create(['type' => 'page'])->save();
     FieldStorageConfig::create(['entity_type' => 'node', 'field_name' => 'field_tags', 'type' => 'entity_reference', 'settings' => ['target_type' => 'taxonomy_term']])->save();
     FieldConfig::create(['field_name' => 'field_tags', 'entity_type' => 'node', 'bundle' => 'page'])->save();
     $node = Node::create(['type' => 'page', 'title' => 'test_title', 'field_tags' => [$term->id()]]);
     $node->save();
     $taxonomy_index = $this->getTaxonomyIndex();
     $this->assertEquals($term->id(), $taxonomy_index[$node->id()]->tid);
     // Normal new revision.
     $node->setNewRevision(TRUE);
     $node->isDefaultRevision(TRUE);
     $node->field_tags->target_id = $term2->id();
     $node->save();
     $taxonomy_index = $this->getTaxonomyIndex();
     $this->assertEquals($term2->id(), $taxonomy_index[$node->id()]->tid);
     // Check that saving a forward (non-default) revision does not affect the
     // taxonomy index.
     $node->setNewRevision(TRUE);
     $node->isDefaultRevision(FALSE);
     $node->field_tags->target_id = $term->id();
     $node->save();
     $taxonomy_index = $this->getTaxonomyIndex();
     $this->assertEquals($term2->id(), $taxonomy_index[$node->id()]->tid);
     // Check that making the previously created forward-revision the default
     // revision updates the taxonomy index correctly.
     $node->isDefaultRevision(TRUE);
     $node->save();
     $taxonomy_index = $this->getTaxonomyIndex();
     $this->assertEquals($term->id(), $taxonomy_index[$node->id()]->tid);
 }
Esempio n. 30
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installSchema('system', array('sequences'));
     $this->installEntitySchema('node');
     $this->installEntitySchema('user');
     $this->installEntitySchema('taxonomy_term');
     NodeType::create(['type' => 'page', 'name' => 'Basic page', 'display_submitted' => FALSE])->save();
     // Add a vocabulary so we can test different view modes.
     $vocabulary = Vocabulary::create(['name' => $this->randomMachineName(), 'description' => $this->randomMachineName(), 'vid' => $this->randomMachineName(), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, 'help' => '']);
     $vocabulary->save();
     // Add a term to the vocabulary.
     $this->term = Term::create(['name' => 'Sometimes people are just jerks', 'description' => $this->randomMachineName(), 'vid' => $vocabulary->id(), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED]);
     $this->term->save();
     // Create a field.
     $handler_settings = array('target_bundles' => array($vocabulary->id() => $vocabulary->id()), 'auto_create' => TRUE);
     // Add the term field.
     FieldStorageConfig::create(array('field_name' => 'field_term', 'type' => 'entity_reference', 'entity_type' => 'node', 'cardinality' => 1, 'settings' => array('target_type' => 'taxonomy_term')))->save();
     FieldConfig::create(array('field_name' => 'field_term', 'entity_type' => 'node', 'bundle' => 'page', 'label' => 'Terms', 'settings' => array('handler' => 'default', 'handler_settings' => $handler_settings)))->save();
     // Show on default display and teaser.
     entity_get_display('node', 'page', 'default')->setComponent('field_term', array('type' => 'entity_reference_label'))->save();
     // Boot twig environment.
     $this->twig = \Drupal::service('twig');
 }