You are here

public function FeedsMapperNodeSummaryTestCase::test in Feeds 7.2

Tests importing CSV files for text fields with summary.

File

tests/feeds_mapper_summary.test, line 27
Contains FeedsMapperNodeSummaryTestCase.

Class

FeedsMapperNodeSummaryTestCase
Test case for mapping to node summary.

Code

public function test() {

  // Create and configure importer.
  $this
    ->createImporterWithSummaryMapper();

  // Create a new filter format.
  $format = drupal_strtolower($this
    ->randomName());
  $edit = array(
    'format' => $format,
    'name' => $this
      ->randomName(),
    // Authenticated users.
    'roles[2]' => TRUE,
  );
  $this
    ->drupalPost('admin/config/content/formats/add', $edit, t('Save configuration'));

  // The "update existing" and "skip hash check" are turned on so we can test
  // later if the summaries of the nodes get overwritten with the values from
  // the source.
  $this
    ->setSettings('syndication', 'FeedsNodeProcessor', array(
    'update_existing' => 2,
    'skip_hash_check' => TRUE,
    'input_format' => $format,
  ));

  // Import CSV file.
  $this
    ->importFile('syndication', $this
    ->absolutePath() . '/tests/feeds/node_summary.csv');
  $this
    ->assertText('Created 3 nodes');
  $this
    ->assertNodeSummaryValues();

  // Check that text format is applied correctly.
  $this
    ->drupalGet('node/1/edit');
  $this
    ->assertNodeFieldValue('format', $format);

  // Check the teasers of the three imported nodes, assumed to be all present
  // on the front page.
  $this
    ->assertNodeTeaserValues();

  // Set a summary and a text for each imported node.
  $edit = array(
    'body[und][0][summary]' => 'Nam liber tempor summary',
    'body[und][0][value]' => 'Nam liber tempor body',
  );
  $this
    ->drupalPost('node/1/edit', $edit, t('Save'));
  $this
    ->drupalPost('node/2/edit', $edit, t('Save'));
  $this
    ->drupalPost('node/3/edit', $edit, t('Save'));

  // Import the same CSV file again.
  $this
    ->importFile('syndication', $this
    ->absolutePath() . '/tests/feeds/node_summary.csv');
  $this
    ->assertText('Updated 3 nodes');
  $this
    ->assertNodeSummaryValues();
  $this
    ->assertNodeTeaserValues();

  // The previous texts of the nodes should no longer be visible.
  $this
    ->assertNoText('Nam liber tempor summary');
  $this
    ->assertNoText('Nam liber tempor body');

  // Check that text format is applied correctly.
  $this
    ->drupalGet('node/1/edit');
  $this
    ->assertNodeFieldValue('format', $format);
  $this
    ->drupalGet('node/2/edit');
  $this
    ->assertNodeFieldValue('format', $format);
  $this
    ->drupalGet('node/3/edit');
  $this
    ->assertNodeFieldValue('format', $format);

  // Remove the body mapping to check that the text format doesn't get updated
  // from the summary.
  $this
    ->removeMappings('syndication', array(
    2 => array(
      'source' => 'body',
      'target' => 'body',
    ),
  ));

  // Change the text format and remove the body mapping to ensure that the
  // text format doesn't change.
  $this
    ->setSettings('syndication', 'FeedsNodeProcessor', array(
    'input_format' => 'plain_text',
  ));
  $this
    ->importFile('syndication', $this
    ->absolutePath() . '/tests/feeds/node_summary.csv');
  $this
    ->assertText('Updated 3 nodes');

  // Check that text format remains at its previous value.
  $this
    ->drupalGet('node/1/edit');
  $this
    ->assertNodeFieldValue('format', $format);
  $this
    ->drupalGet('node/2/edit');
  $this
    ->assertNodeFieldValue('format', $format);
  $this
    ->drupalGet('node/3/edit');
  $this
    ->assertNodeFieldValue('format', $format);
}