You are here

protected function ParserCSVTest::_testBatching in Feeds 7.2

Same name and namespace in other branches
  1. 6 tests/parser_csv.test \ParserCSVTest::_testBatching()
  2. 7 tests/parser_csv.test \ParserCSVTest::_testBatching()

Test batching.

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

File

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

Class

ParserCSVTest
Test aggregating a feed as node items.

Code

protected function _testBatching() {

  // Pull in the $control_result array.
  include $this
    ->absolutePath() . '/tests/feeds/nodes.csv.php';
  $delimiters = $this
    ->getDelimiters();
  foreach ($delimiters as $delimiterType => $delimiter) {
    $file = $this
      ->absolutePath() . '/tests/feeds/nodes_' . $delimiterType . '.csv';

    // Set up parser with 2 lines to parse per call.
    $iterator = new ParserCSVIterator($file);
    $parser = new ParserCSV();
    $parser
      ->setDelimiter($delimiter);
    $parser
      ->setLineLimit(2);
    $rows = array();
    $pos = 0;

    // Call parser until all lines are parsed, then compare to control result.
    do {
      $parser
        ->setStartByte($pos);
      $rows = array_merge($rows, $parser
        ->parse($iterator));
      $pos = $parser
        ->lastLinePos();
      $this
        ->assertTrue($parser
        ->lastLinePos() || count($rows) == 10, t('Parser reports line limit correctly'));
    } while ($pos = $parser
      ->lastLinePos());
    $this
      ->assertEqual(md5(serialize($rows)), md5(serialize($control_result)), t('Batch parsed result matches control result for delimiter: ') . $delimiterType);
  }
}