You are here

public function FeedsMapperFieldTestCase::testCardinalityValidation in Feeds 7.2

Tests cardinality validation.

File

tests/feeds_mapper_field.test, line 483
Contains FeedsMapperFieldTestCase.

Class

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

Code

public function testCardinalityValidation() {

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

  // Create and configure importer.
  $this
    ->createImporterConfiguration('Syndication', 'syndication');
  $this
    ->setSettings('syndication', NULL, array(
    'content_type' => '',
    'import_period' => FEEDS_SCHEDULE_NEVER,
  ));
  $this
    ->setPlugin('syndication', 'FeedsHTTPFetcher');
  $this
    ->setPlugin('syndication', 'FeedsSyndicationParser');
  $this
    ->setSettings('syndication', 'FeedsNodeProcessor', array(
    'bundle' => $typename,
  ));
  $this
    ->addMappings('syndication', array(
    0 => array(
      'source' => 'title',
      'target' => 'title',
    ),
    1 => array(
      'source' => 'tags',
      'target' => 'field_alpha',
    ),
  ));

  // Import RSS.
  // Three items of the RSS contain more than 6 categories. Because categories
  // are mapped to field_alpha and field_alpha may only hold 6 values, they
  // should fail to import.
  $edit = array(
    'feeds[FeedsHTTPFetcher][source]' => $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/developmentseed.rss2',
  );
  $this
    ->drupalPost('import/syndication', $edit, 'Import');
  $this
    ->assertText('Created 7 nodes');
  $this
    ->assertText('Failed importing 3 nodes.');
  $this
    ->assertText("Field validation errors in item 'Open Atrium Translation Workflow: Two Way Translation Updates'");
  $this
    ->assertText("Field validation errors in item 'Mapping Innovation at the World Bank with Open Atrium'");
  $this
    ->assertText("Field validation errors in item 'Open Data for Microfinance: The New MIXMarket.org'");
  $this
    ->assertText('alpha_text_label: this field cannot hold more than 6 values.');
}