You are here

public function FeedsMapperFieldTestCase::testTextFieldValidation in Feeds 7.2

Tests text field validation.

File

tests/feeds_mapper_field.test, line 242
Contains FeedsMapperFieldTestCase.

Class

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

Code

public function testTextFieldValidation() {

  // Create a field with settings to validate.
  $max_length = 5;
  $typename = $this
    ->createContentType(array(), array(
    'alpha' => array(
      'type' => 'text',
      'settings' => array(
        'field[settings][max_length]' => $max_length,
      ),
    ),
  ));

  // 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
    ->setSettings('csv', 'FeedsNodeProcessor', array(
    'bundle' => $typename,
  ));
  $this
    ->addMappings('csv', array(
    0 => array(
      'source' => 'title',
      'target' => 'title',
    ),
    1 => array(
      'source' => 'alpha',
      'target' => 'field_alpha',
    ),
  ));

  // Import CSV file.
  $this
    ->importFile('csv', $this
    ->absolutePath() . '/tests/feeds/content.csv');
  $this
    ->assertText('Created 1 node');
  $this
    ->assertText('Failed importing 1 node.');
  $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.');
}