You are here

protected function ParserCSVTest::_testEncodingConversionFailure in Feeds 7.2

Simple test of failed encoding conversion prior to parsing.

1 call to ParserCSVTest::_testEncodingConversionFailure()
ParserCSVTest::test in tests/parser_csv.test
Test method.

File

tests/parser_csv.test, line 84
Tests for ParserCSV library.

Class

ParserCSVTest
Test aggregating a feed as node items.

Code

protected function _testEncodingConversionFailure() {

  // Pull in the $control_result array.
  include $this
    ->absolutePath() . '/tests/feeds/encoding.csv.php';
  $encodings = $this
    ->getEncodings();
  foreach ($encodings as $encoding) {
    $file = $this
      ->absolutePath() . "/tests/feeds/encoding_{$encoding}.csv";
    $iterator = new ParserCSVIterator($file);
    $parser = new ParserCSV();
    $parser
      ->setDelimiter(',');

    // Attempt to read file as UTF-8.
    $parser
      ->setEncoding('UTF-8');
    try {
      $rows = $parser
        ->parse($iterator);
      $this
        ->fail('Incorrect conversion attempt throws exception.');
    } catch (ParserCSVEncodingException $e) {
      $this
        ->assertNotNull($e
        ->getMessage(), 'Incorrect conversion attempt throws exception.');
    }
  }
}