/**
  * 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');
 }
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('taxonomy_term');
     $vocabulary = entity_create('taxonomy_vocabulary', array('name' => $this->randomMachineName(), 'vid' => Unicode::strtolower($this->randomMachineName()), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED));
     $vocabulary->save();
     entity_create('field_storage_config', array('field_name' => 'field_test_taxonomy', 'entity_type' => 'entity_test', 'type' => 'taxonomy_term_reference', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, 'settings' => array('allowed_values' => array(array('vocabulary' => $vocabulary->id(), 'parent' => 0)))))->save();
     entity_create('field_config', array('entity_type' => 'entity_test', 'field_name' => 'field_test_taxonomy', 'bundle' => 'entity_test'))->save();
     $this->term = entity_create('taxonomy_term', array('name' => $this->randomMachineName(), 'vid' => $vocabulary->id(), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED));
     $this->term->save();
 }
 /**
  * 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');
 }
Exemple #4
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');
 }
 protected function setUp()
 {
     parent::setUp();
     // Use Classy theme for testing markup output.
     \Drupal::service('theme_handler')->install(['classy']);
     \Drupal::service('theme_handler')->setDefault('classy');
     $this->baseUri = \Drupal::url('<front>', [], ['absolute' => TRUE]);
     // Create two test users.
     $this->adminUser = $this->drupalCreateUser(array('administer content types', 'administer comments', 'access comments', 'access content'));
     $this->webUser = $this->drupalCreateUser(array('access comments', 'post comments', 'skip comment approval', 'access content'));
     $this->drupalLogin($this->adminUser);
     // Create term.
     $this->term = Term::create(['name' => $this->randomMachineName(), 'description' => $this->randomMachineName(), 'vid' => 'tags']);
     $this->term->save();
     // Create image.
     file_unmanaged_copy(\Drupal::root() . '/core/misc/druplicon.png', 'public://example.jpg');
     $this->image = File::create(['uri' => 'public://example.jpg']);
     $this->image->save();
     // Create article.
     $article_settings = array('type' => 'article', 'promote' => NODE_PROMOTED, 'field_image' => array(array('target_id' => $this->image->id())), 'field_tags' => array(array('target_id' => $this->term->id())));
     $this->article = $this->drupalCreateNode($article_settings);
     // Create second article to test teaser list.
     $this->drupalCreateNode(array('type' => 'article', 'promote' => NODE_PROMOTED));
     // Create article comment.
     $this->articleComment = $this->saveComment($this->article->id(), $this->webUser->id(), NULL, 0);
     // Create page.
     $this->page = $this->drupalCreateNode(array('type' => 'page'));
     // Set URIs.
     // Image.
     $image_file = $this->article->get('field_image')->entity;
     $this->imageUri = ImageStyle::load('large')->buildUrl($image_file->getFileUri());
     // Term.
     $this->termUri = $this->term->url('canonical', array('absolute' => TRUE));
     // Article.
     $this->articleUri = $this->article->url('canonical', array('absolute' => TRUE));
     // Page.
     $this->pageUri = $this->page->url('canonical', array('absolute' => TRUE));
     // Author.
     $this->authorUri = $this->adminUser->url('canonical', array('absolute' => TRUE));
     // Comment.
     $this->articleCommentUri = $this->articleComment->url('canonical', array('absolute' => TRUE));
     // Commenter.
     $this->commenterUri = $this->webUser->url('canonical', array('absolute' => TRUE));
     $this->drupalLogout();
 }
 protected function setUp()
 {
     parent::setUp();
     $this->base_uri = \Drupal::url('<front>', [], ['absolute' => TRUE]);
     // Create two test users.
     $this->adminUser = $this->drupalCreateUser(array('administer content types', 'administer comments', 'access comments', 'access content'));
     $this->webUser = $this->drupalCreateUser(array('access comments', 'post comments', 'skip comment approval', 'access content'));
     $this->drupalLogin($this->adminUser);
     // Create term.
     $this->term = entity_create('taxonomy_term', array('name' => $this->randomMachineName(), 'description' => $this->randomMachineName(), 'vid' => 'tags'));
     $this->term->save();
     // Create image.
     file_unmanaged_copy(DRUPAL_ROOT . '/core/misc/druplicon.png', 'public://example.jpg');
     $this->image = entity_create('file', array('uri' => 'public://example.jpg'));
     $this->image->save();
     // Create article.
     $article_settings = array('type' => 'article', 'promote' => NODE_PROMOTED, 'field_image' => array(array('target_id' => $this->image->id())), 'field_tags' => array(array('target_id' => $this->term->id())));
     $this->article = $this->drupalCreateNode($article_settings);
     // Create second article to test teaser list.
     $this->drupalCreateNode(array('type' => 'article', 'promote' => NODE_PROMOTED));
     // Create article comment.
     $this->articleComment = $this->saveComment($this->article->id(), $this->webUser->id(), NULL, 0);
     // Create page.
     $this->page = $this->drupalCreateNode(array('type' => 'page'));
     // Set URIs.
     // Image.
     $image_file = $this->article->get('field_image')->entity;
     $this->imageUri = entity_load('image_style', 'large')->buildUrl($image_file->getFileUri());
     // Term.
     $this->termUri = $this->term->url('canonical', array('absolute' => TRUE));
     // Article.
     $this->articleUri = $this->article->url('canonical', array('absolute' => TRUE));
     // Page.
     $this->pageUri = $this->page->url('canonical', array('absolute' => TRUE));
     // Author.
     $this->authorUri = $this->adminUser->url('canonical', array('absolute' => TRUE));
     // Comment.
     $this->articleCommentUri = $this->articleComment->url('canonical', array('absolute' => TRUE));
     // Commenter.
     $this->commenterUri = $this->webUser->url('canonical', array('absolute' => TRUE));
     $this->drupalLogout();
 }