You are here

public function FeedsCSVParserTestCase::testEncodingFailure in Feeds 7.2

Tests an encoding failure during parsing a CSV.

File

tests/feeds_parser_csv.test, line 72
Contains FeedsCSVParserTestCase.

Class

FeedsCSVParserTestCase
Tests the CSV parser using the UI.

Code

public function testEncodingFailure() {

  // Create node type.
  $node_type = $this
    ->drupalCreateContentType();

  // Create and configure importer.
  $this
    ->createImporterConfiguration('Content CSV', 'csv');
  $this
    ->setPlugin('csv', 'FeedsFileFetcher');
  $this
    ->setPlugin('csv', 'FeedsCSVParser');
  $this
    ->setSettings('csv', 'FeedsNodeProcessor', array(
    'bundle' => $node_type->type,
  ));
  $this
    ->addMappings('csv', array(
    0 => array(
      'source' => 'id',
      'target' => 'guid',
    ),
    1 => array(
      'source' => 'text',
      'target' => 'title',
    ),
  ));

  // Ensure that on the CSV parser settings page a setting for encoding is
  // shown.
  $this
    ->drupalGet('admin/structure/feeds/csv/settings/FeedsCSVParser');
  $this
    ->assertField('encoding');
  $this
    ->assertNoText('PHP mbstring extension must be available for character encoding conversion.');

  // Try to import a CSV file that is not UTF-8 encoded. Import should be
  // halted and an encoding warning should be shown.
  $this
    ->importFile('csv', $this
    ->absolutePath() . '/tests/feeds/encoding_SJIS.csv');
  $this
    ->assertNoText('Failed importing 4 nodes.');
  $this
    ->assertText('Source file is not in UTF-8 encoding.');
}