You are here

public function HtmlParserTest::testEucJpEncodedNoDeclaration in Feeds extensible parsers 8

Tests a EUC-JP (Japanese) encoded file without the encoding declaration.

This implicitly tests Base's encoding conversion.

File

tests/src/Unit/Feeds/Parser/HtmlParserTest.php, line 172

Class

HtmlParserTest
@coversDefaultClass \Drupal\feeds_ex\Feeds\Parser\HtmlParser @group feeds_ex

Namespace

Drupal\Tests\feeds_ex\Unit\Feeds\Parser

Code

public function testEucJpEncodedNoDeclaration() {
  $fetcher_result = new RawFetcherResult(file_get_contents($this->moduleDir . '/tests/resources/test_jp.html'), $this->fileSystem);
  $config = [
    'context' => [
      'value' => '//div[@class="post"]',
    ],
    'sources' => [
      'title' => [
        'name' => 'Title',
        'value' => 'h3',
      ],
      'description' => [
        'name' => 'Title',
        'value' => 'p',
      ],
    ],
    'source_encoding' => [
      'EUC-JP',
    ],
  ] + $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('私はタイトルです' . $delta, $item
      ->get('title'));
    $this
      ->assertSame('私が説明してい' . $delta, $item
      ->get('description'));
  }
}