/**
  * {@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);
 }
 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();
     }
 }
Exemplo n.º 3
0
  /**
   * {@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);
  }
Exemplo n.º 4
0
 /**
  * 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();
 }
 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();
     $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');
 }
 /**
  * {@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();
 }
Exemplo n.º 8
0
 /**
  * {@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();
 }
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('entity_test_rev');
     $this->installEntitySchema('entity_test_mul');
     $this->installEntitySchema('entity_test_mulrev');
 }
Exemplo n.º 10
0
 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');
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     // Enable an additional language.
     ConfigurableLanguage::createFromLangcode('de')->save();
     $this->installEntitySchema('entity_test_mulrev');
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installConfig(array('user'));
     $this->installEntitySchema('comment');
     $this->installSchema('comment', array('comment_entity_statistics'));
 }
 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');
 }
Exemplo n.º 14
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installConfig(array('user'));
     $this->user = $this->createUser();
     \Drupal::service('current_user')->setAccount($this->user);
 }
 /**
  * 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();
 }
Exemplo n.º 16
0
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('node');
     $this->installEntitySchema('comment');
     $this->installSchema('comment', array('comment_entity_statistics'));
 }
 public function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('entity_test_rev');
     // Setup a field and instance.
     entity_reference_create_instance($this->entityType, $this->bundle, $this->fieldName, 'Field test', $this->referencedEntityType, 'default', array('target_bundles' => array($this->bundle)), FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
 }
 public function setUp()
 {
     parent::setUp();
     // Install default system configuration.
     $this->installConfig(array('system'));
     $this->interfaceLanguage = \Drupal::languageManager()->getCurrentLanguage();
     $this->tokenService = \Drupal::token();
 }
Exemplo n.º 19
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     // Create the test field.
     entity_test_install();
     // Install required default configuration for filter module.
     $this->installConfig(array('system', 'filter'));
 }
Exemplo n.º 20
0
 /**
  * Set the default field storage backend for fields created during tests.
  */
 public function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('node');
     // Create a node type for testing.
     $type = entity_create('node_type', array('type' => 'page', 'name' => 'page'));
     $type->save();
 }
Exemplo n.º 21
0
 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 = entity_create('field_storage_config', 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) {
             entity_create('field_config', array('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();
 }
 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}
  */
 function setUp()
 {
     parent::setUp();
     $this->role1 = entity_create('user_role', array('id' => strtolower($this->randomMachineName(8)), 'label' => $this->randomMachineName(8)));
     $this->role1->save();
     $this->role2 = entity_create('user_role', array('id' => strtolower($this->randomMachineName(8)), 'label' => $this->randomMachineName(8)));
     $this->role2->save();
     entity_reference_create_instance('user', 'user', 'user_reference', 'User reference', 'user');
 }
Exemplo n.º 25
0
 /**
  * {@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'));
 }
Exemplo n.º 26
0
  /**
   * Performs setup tasks before each individual test method is run.
   *
   * Installs commonly used schemas and sets up a search server and an index,
   * with the specified processor enabled.
   *
   * @param string|null $processor
   *   (optional) The plugin ID of the processor that should be set up for
   *   testing.
   */
  public function setUp($processor = NULL) {
    parent::setUp();

    $this->installSchema('node', array('node_access'));
    $this->installSchema('search_api', array('search_api_item', 'search_api_task'));

    $server_name = $this->randomMachineName();
    $this->server = Server::create(array(
      'id' => strtolower($server_name),
      'name' => $server_name,
      'status' => TRUE,
      'backend' => 'search_api_db',
      'backend_config' => array(
        'min_chars' => 3,
        'database' => 'default:default',
      ),
    ));
    $this->server->save();

    $index_name = $this->randomMachineName();
    $this->index = Index::create(array(
      'id' => strtolower($index_name),
      'name' => $index_name,
      'status' => TRUE,
      'datasources' => array('entity:comment', 'entity:node'),
      'server' => $server_name,
      'tracker' => 'default',
    ));
    $this->index->setServer($this->server);
    $this->index->setOption('fields', array(
      'entity:comment/subject' => array(
        'type' => 'text',
      ),
      'entity:node/title' => array(
        'type' => 'text',
      ),
    ));
    if ($processor) {
      $this->index->setOption('processors', array(
        $processor => array(
          'processor_id' => $processor,
          'weights' => array(),
          'settings' => array(),
        ),
      ));

      /** @var \Drupal\search_api\Processor\ProcessorPluginManager $plugin_manager */
      $plugin_manager = \Drupal::service('plugin.manager.search_api.processor');
      $this->processor = $plugin_manager->createInstance($processor, array('index' => $this->index));
    }
    $this->index->save();
    \Drupal::configFactory()
      ->getEditable('search_api.settings')
      ->set('tracking_page_size', 100)
      ->save();
    Utility::getIndexTaskManager()->addItemsAll($this->index);
  }
 /**
  * {@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');
 }
 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);
 }
Exemplo n.º 29
0
 /**
  * @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);
         }
     }
 }
Exemplo n.º 30
0
 /**
  * {@inheritdoc}
  */
 public 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();
     // Set up two fields: one with text processing enabled, the other disabled.
     entity_create('field_storage_config', array('name' => 'processed_text', 'entity_type' => $this->entityType, 'type' => 'text', 'settings' => array()))->save();
     entity_create('field_instance_config', array('entity_type' => $this->entityType, 'bundle' => $this->bundle, 'field_name' => 'processed_text', 'label' => 'Processed text', 'settings' => array('text_processing' => TRUE)))->save();
     entity_create('field_storage_config', array('name' => 'unprocessed_text', 'entity_type' => $this->entityType, 'type' => 'text', 'settings' => array()))->save();
     entity_create('field_instance_config', array('entity_type' => $this->entityType, 'bundle' => $this->bundle, 'field_name' => 'unprocessed_text', 'label' => 'Unprocessed text', 'settings' => array('text_processing' => FALSE)))->save();
 }