You are here

public function FeedsMapperFieldTestCase::test in Entity reference 7

Basic test loading a double entry CSV file.

File

tests/entityreference.feeds.test, line 156
Test case for simple CCK field mapper mappers/content.inc.

Class

FeedsMapperFieldTestCase
Class for testing Feeds field mapper.

Code

public function test() {
  $this
    ->drupalLogin($this->admin_user);
  $this
    ->drupalGet('admin/structure/types/manage/article/fields');
  $this
    ->assertText('Ref - entity ID', t('Found Entity reference field %field.', array(
    '%field' => 'field_er_id',
  )));
  $this
    ->assertText('Ref - entity label', t('Found Entity reference field %field.', array(
    '%field' => 'field_er_label',
  )));
  $this
    ->assertText('Ref - feeds GUID', t('Found Entity reference field %field.', array(
    '%field' => 'field_er_guid',
  )));
  $this
    ->assertText('Ref - feeds URL', t('Found Entity reference field %field.', array(
    '%field' => 'field_er_url',
  )));

  // Add feeds importer
  $this
    ->drupalGet('admin/structure/feeds');
  $this
    ->clickLink('Add importer');
  $this
    ->drupalPost('admin/structure/feeds/create', array(
    'name' => 'Nodes',
    'id' => 'nodes',
  ), 'Create');
  $this
    ->assertText('Your configuration has been created with default settings.');
  $this
    ->drupalPost('admin/structure/feeds/nodes/settings/', array(
    'content_type' => '',
    'import_period' => -1,
  ), 'Save');
  $this
    ->assertText('Your changes have been saved.');
  $this
    ->drupalPost("admin/structure/feeds/nodes/fetcher", array(
    'plugin_key' => 'FeedsFileFetcher',
  ), 'Save');
  $config = unserialize(db_query("SELECT config FROM {feeds_importer} WHERE id = :id", array(
    ':id' => 'nodes',
  ))
    ->fetchField());
  $this
    ->assertEqual($config['fetcher']['plugin_key'], 'FeedsFileFetcher', 'Verified correct fetcher (FeedsFileFetcher).');
  $this
    ->drupalPost("admin/structure/feeds/nodes/parser", array(
    'plugin_key' => 'FeedsCSVParser',
  ), 'Save');
  $config = unserialize(db_query("SELECT config FROM {feeds_importer} WHERE id = :id", array(
    ':id' => 'nodes',
  ))
    ->fetchField());
  $this
    ->assertEqual($config['parser']['plugin_key'], 'FeedsCSVParser', 'Verified correct parser (FeedsCSVParser).');
  $this
    ->drupalPost('admin/structure/feeds/nodes/settings/FeedsNodeProcessor', array(
    'content_type' => 'article',
  ), 'Save');
  $this
    ->assertText('Your changes have been saved.');
  $this
    ->addMappings('nodes', array(
    0 => array(
      'source' => 'title',
      'target' => 'title',
    ),
    1 => array(
      'source' => 'nid',
      'target' => 'nid',
      'unique' => TRUE,
    ),
    2 => array(
      'source' => 'permalink',
      'target' => 'url',
      'unique' => TRUE,
    ),
    3 => array(
      'source' => 'nid',
      'target' => 'guid',
      'unique' => TRUE,
    ),
    4 => array(
      'source' => 'parent_nid',
      'target' => 'field_er_id:etid',
    ),
    5 => array(
      'source' => 'parent_title',
      'target' => 'field_er_label:label',
    ),
    6 => array(
      'source' => 'parent_url',
      'target' => 'field_er_url:url',
    ),
    7 => array(
      'source' => 'parent_guid',
      'target' => 'field_er_guid',
    ),
  ));
  $file = realpath(getcwd()) . '/' . drupal_get_path('module', 'entityreference') . '/tests/feeds_test.csv';
  $this
    ->assertTrue(file_exists($file), 'Source file exists');
  $this
    ->drupalPost('import/nodes', array(
    'files[feeds]' => $file,
  ), 'Import');
  $this
    ->assertText('Created 2 nodes');
  $parent = node_load(1);
  $this
    ->assertTrue(empty($parent->field_er_id['und'][0]['target_id']), t('Parent node: Import by entity ID OK.'));
  $this
    ->assertTrue(empty($parent->field_er_label['und'][0]['target_id']), t('Parent node: Import by entity label OK.'));
  $this
    ->assertTrue(empty($parent->field_er_guid['und'][0]['target_id']), t('Parent node: Import by feeds GUID OK.'));
  $this
    ->assertTrue(empty($parent->field_er_url['und'][0]['target_id']), t('Parent node: Import by feeds URL OK.'));
  $child = node_load(2);
  $this
    ->assertTrue($child->field_er_id['und'][0]['target_id'] == 1, t('Child node: Import by entity ID OK.'));
  $this
    ->assertTrue($child->field_er_label['und'][0]['target_id'] == 1, t('Child node: Import by entity label OK.'));
  $this
    ->assertTrue($child->field_er_guid['und'][0]['target_id'] == 1, t('Child node: Import by feeds GUID OK.'));
  $this
    ->assertTrue($child->field_er_url['und'][0]['target_id'] == 1, t('Child node: Import by feeds URL OK.'));
}