You are here

public function FeedsMapperFieldTestCase::testTextFieldValidationForTaxonomyTerms in Feeds 7.2

Tests text field validation for taxonomy terms.

File

tests/feeds_mapper_field.test, line 374
Contains FeedsMapperFieldTestCase.

Class

FeedsMapperFieldTestCase
Test case for simple CCK field mapper mappers/content.inc.

Code

public function testTextFieldValidationForTaxonomyTerms() {

  // Create vocabulary.
  $edit = array(
    'name' => 'Addams vocabulary',
    'machine_name' => 'addams',
  );
  $this
    ->drupalPost('admin/structure/taxonomy/add', $edit, t('Save'));

  // Create a field with settings to validate.
  field_create_field(array(
    'field_name' => 'field_alpha',
    'type' => 'text',
    'settings' => array(
      'max_length' => 5,
    ),
  ));
  field_create_instance(array(
    'field_name' => 'field_alpha',
    'entity_type' => 'taxonomy_term',
    'label' => 'alpha_text_label',
    'bundle' => 'addams',
    'widget' => array(
      'type' => 'text_textfield',
    ),
  ));

  // Create and configure importer.
  $this
    ->createImporterConfiguration('Content CSV', 'csv');
  $this
    ->setSettings('csv', NULL, array(
    'content_type' => '',
    'import_period' => FEEDS_SCHEDULE_NEVER,
  ));
  $this
    ->setPlugin('csv', 'FeedsFileFetcher');
  $this
    ->setPlugin('csv', 'FeedsCSVParser');
  $this
    ->setPlugin('csv', 'FeedsTermProcessor');
  $this
    ->setSettings('csv', 'FeedsTermProcessor', array(
    'bundle' => 'addams',
  ));
  $this
    ->addMappings('csv', array(
    0 => array(
      'source' => 'title',
      'target' => 'name',
    ),
    1 => array(
      'source' => 'alpha',
      'target' => 'field_alpha',
    ),
  ));

  // Import CSV file.
  $this
    ->importFile('csv', $this
    ->absolutePath() . '/tests/feeds/content.csv');
  $this
    ->assertText('Created 1 taxonomy term.');
  $this
    ->assertText('Failed importing 1 taxonomy term.');
  $this
    ->assertText("Field validation errors in item 'Ut wisi enim ad minim veniam'");
  $this
    ->assertText('alpha_text_label: the text may not be longer than 5 characters.');
}