You are here

public function FeedsCSVParserTestCase::testGetTemplate in Feeds 7.2

Tests if a CSV template is generated properly using various settings.

See also

::getTemplateDataProvider()

File

tests/feeds_parser_csv.test, line 110
Contains FeedsCSVParserTestCase.

Class

FeedsCSVParserTestCase
Tests the CSV parser using the UI.

Code

public function testGetTemplate() {

  // Create node type.
  $node_type = $this
    ->drupalCreateContentType();
  foreach ($this
    ->getTemplateDataProvider() as $key => $testdata) {

    // Prepend 'csv' to importer machine name as '0' is not a valid machine
    // name.
    $key = 'csv' . $key;

    // Create and configure importer.
    $this
      ->createImporterConfiguration('Content CSV', $key);
    $this
      ->setPlugin($key, 'FeedsCSVParser');
    $this
      ->setSettings($key, 'FeedsCSVParser', array(
      'delimiter' => $testdata['delimiter'],
    ));
    $this
      ->setSettings($key, 'FeedsNodeProcessor', array(
      'bundle' => $node_type->type,
    ));
    $this
      ->addMappings($key, $testdata['mapping']);

    // Get CSV template and assert result.
    $this
      ->drupalGet('import/' . $key . '/template');
    $this
      ->assertRaw($testdata['expected']);

    // Check texts that are displayed on the import page. These texts in the
    // content should have gone through to check_plain() so we do that here as
    // well.
    $this
      ->drupalGet('import/' . $key);
    $this
      ->assertText('Import CSV files with one or more of these columns: ' . check_plain($testdata['texts']['columns']) . '.');
    if (isset($testdata['texts']['unique'])) {
      $this
        ->assertText(check_plain($testdata['texts']['unique']));
    }
    else {
      $this
        ->assertText(t('No columns are unique. The import will only create new items, no items will be updated.'));
    }
  }
}