You are here

FeedsProcessorTaxonomyTermTest.php in Feeds 8.2

Tests for plugins/FeedsTermProcessor.inc

Namespace

Drupal\feeds\Tests

File

lib/Drupal/feeds/Tests/FeedsProcessorTaxonomyTermTest.php
View source
<?php

/**
 * @file
 * Tests for plugins/FeedsTermProcessor.inc
 */
namespace Drupal\feeds\Tests;


/**
 * Test aggregating a feed as data records.
 */
class FeedsProcessorTaxonomyTermTest extends FeedsWebTestBase {
  public static function getInfo() {
    return array(
      'name' => 'CSV import to taxonomy',
      'description' => 'Tests a standalone import configuration that uses file fetcher and CSV parser to import taxonomy terms from a CSV file.',
      'group' => 'Feeds',
    );
  }

  /**
   * Set up test.
   */
  public function setUp() {
    parent::setUp();

    // Create an importer.
    $this
      ->createImporterConfiguration('Term import', 'term_import');

    // Set and configure plugins and mappings.
    $this
      ->setPlugin('term_import', 'file');
    $this
      ->setPlugin('term_import', 'csv');
    $this
      ->setPlugin('term_import', 'taxonomy_term');

    // Create vocabulary.
    entity_create('taxonomy_vocabulary', array(
      'name' => 'Addams vocabulary',
      'vid' => 'addams',
    ))
      ->save();
    $this
      ->setSettings('term_import', 'taxonomy_term', array(
      'bundle' => 'addams',
    ));

    // Use standalone form.
    $this
      ->setSettings('term_import', NULL, array(
      'content_type' => '',
    ));
  }

  /**
   * Test term creation, refreshing/deleting feeds and feed items.
   */
  public function test() {
    $this
      ->addMappings('term_import', array(
      0 => array(
        'source' => 'name',
        'target' => 'name',
        'unique' => 1,
      ),
    ));

    // Import and assert.
    $this
      ->importFile('term_import', $this
      ->absolutePath() . '/tests/feeds/users.csv');
    $this
      ->assertText('Created 5 terms');
    $this
      ->drupalGet('admin/structure/taxonomy/manage/addams');
    $this
      ->assertText('Morticia');
    $this
      ->assertText('Fester');
    $this
      ->assertText('Gomez');
    $this
      ->assertText('Pugsley');

    // Import again.
    $this
      ->importFile('term_import', $this
      ->absolutePath() . '/tests/feeds/users.csv');
    $this
      ->assertText('There are no new terms.');

    // Force update.
    $this
      ->setSettings('term_import', 'taxonomy_term', array(
      'skip_hash_check' => TRUE,
      'update_existing' => 2,
    ));
    $this
      ->importFile('term_import', $this
      ->absolutePath() . '/tests/feeds/users.csv');
    $this
      ->assertText('Updated 5 terms.');

    // Add a term manually, delete all terms, this term should still stand.
    entity_create('taxonomy_term', array(
      'name' => 'Cousin Itt',
      'vid' => 'addams',
    ))
      ->save();
    $this
      ->drupalPost('import/term_import/delete-items', array(), t('Delete'));
    $this
      ->drupalGet('admin/structure/taxonomy/manage/addams');
    $this
      ->assertText('Cousin Itt');
    $this
      ->assertNoText('Morticia');
    $this
      ->assertNoText('Fester');
    $this
      ->assertNoText('Gomez');
    $this
      ->assertNoText('Pugsley');
  }

}

Classes

Namesort descending Description
FeedsProcessorTaxonomyTermTest Test aggregating a feed as data records.