You are here

public function XmlParserTest::testSimpleParsing in Feeds extensible parsers 8

Tests simple parsing.

File

tests/src/Unit/Feeds/Parser/XmlParserTest.php, line 33

Class

XmlParserTest
@coversDefaultClass \Drupal\feeds_ex\Feeds\Parser\XmlParser @group feeds_ex

Namespace

Drupal\Tests\feeds_ex\Unit\Feeds\Parser

Code

public function testSimpleParsing() {
  $contents = file_get_contents($this->moduleDir . '/tests/resources/test.xml');

  // Implicitly test that invalid characters are ignored and null bytes are
  // stripped.
  $contents = str_replace('I am a description', chr(0) . 'I am a description' . chr(11), $contents);
  $fetcher_result = new RawFetcherResult($contents, $this->fileSystem);
  $config = [
    'context' => [
      'value' => '/items/item',
    ],
    'sources' => [
      'title' => [
        'name' => 'Title',
        'value' => 'title',
      ],
      'description' => [
        'name' => 'Title',
        'value' => 'description',
      ],
    ],
  ] + $this->parser
    ->defaultConfiguration();
  $this->parser
    ->setConfiguration($config);
  $result = $this->parser
    ->parse($this->feed, $fetcher_result, $this->state);
  $this
    ->assertCount(3, $result);
  foreach ($result as $delta => $item) {
    $this
      ->assertSame('I am a title' . $delta, $item
      ->get('title'));
    $this
      ->assertSame('I am a description' . $delta, $item
      ->get('description'));
  }
}