You are here

function FeedsMapperTaxonomyTest::setUp in Feeds 8.2

Sets up a Drupal site for running functional and integration tests.

Installs Drupal with the installation profile specified in \Drupal\simpletest\WebTestBase::$profile into the prefixed database.

Afterwards, installs any additional modules specified in the static \Drupal\simpletest\WebTestBase::$modules property of each class in the class hierarchy.

After installation all caches are flushed and several configuration values are reset to the values of the parent site executing the test, since the default values may be incompatible with the environment in which tests are being executed.

Overrides FeedsWebTestBase::setUp

File

lib/Drupal/feeds/Tests/FeedsMapperTaxonomyTest.php, line 24
Test case for taxonomy mapper mappers/taxonomy.inc.

Class

FeedsMapperTaxonomyTest
Class for testing Feeds <em>content</em> mapper.

Namespace

Drupal\feeds\Tests

Code

function setUp() {
  parent::setUp();

  // Add Tags vocabulary.
  entity_create('taxonomy_vocabulary', array(
    'name' => 'Tags',
    'vid' => 'tags',
  ))
    ->save();
  entity_create('taxonomy_term', array(
    'name' => 'term1',
    'vid' => 'tags',
  ))
    ->save();

  // Create term reference field.
  $field = array(
    'field_name' => 'field_tags',
    'type' => 'taxonomy_term_reference',
    'cardinality' => FIELD_CARDINALITY_UNLIMITED,
    'settings' => array(
      'allowed_values' => array(
        array(
          'vocabulary' => 'tags',
          'parent' => 0,
        ),
      ),
    ),
  );
  field_create_field($field);

  // Add term reference field to feed item bundle.
  $this->instance = array(
    'field_name' => 'field_tags',
    'bundle' => 'article',
    'entity_type' => 'node',
    'widget' => array(
      'type' => 'options_select',
    ),
    'display' => array(
      'default' => array(
        'type' => 'taxonomy_term_reference_link',
      ),
    ),
  );
  field_create_instance($this->instance);

  // Add term reference field to feed node bundle.
  $this->instance = array(
    'field_name' => 'field_tags',
    'bundle' => 'page',
    'entity_type' => 'node',
    'widget' => array(
      'type' => 'options_select',
    ),
    'display' => array(
      'default' => array(
        'type' => 'taxonomy_term_reference_link',
      ),
    ),
  );
  field_create_instance($this->instance);
  $edit = array(
    'fields[field_tags][type]' => 'taxonomy_term_reference_link',
  );
  $this
    ->drupalPost('admin/structure/types/manage/article/display', $edit, t('Save'));

  // Create an importer configuration with basic mapping.
  $this
    ->createImporterConfiguration('Syndication', 'syndication');
  $this
    ->addMappings('syndication', array(
    0 => array(
      'source' => 'title',
      'target' => 'title',
    ),
    1 => array(
      'source' => 'description',
      'target' => 'body',
    ),
    2 => array(
      'source' => 'timestamp',
      'target' => 'created',
    ),
    3 => array(
      'source' => 'url',
      'target' => 'url',
      'unique' => TRUE,
    ),
    4 => array(
      'source' => 'guid',
      'target' => 'guid',
      'unique' => TRUE,
    ),
  ));
}