public function HtmlParserTest::testSimpleParsing in Feeds extensible parsers 8
Tests simple parsing.
File
- tests/
src/ Unit/ Feeds/ Parser/ HtmlParserTest.php, line 33
Class
- HtmlParserTest
- @coversDefaultClass \Drupal\feeds_ex\Feeds\Parser\HtmlParser @group feeds_ex
Namespace
Drupal\Tests\feeds_ex\Unit\Feeds\ParserCode
public function testSimpleParsing() {
$fetcher_result = new RawFetcherResult(file_get_contents($this->moduleDir . '/tests/resources/test.html'), $this->fileSystem);
$config = [
'context' => [
'value' => '//div[@class="post"]',
],
'sources' => [
'title' => [
'name' => 'Title',
'value' => 'h3',
],
'description' => [
'name' => 'Description',
'value' => 'p',
],
],
] + $this->parser
->defaultConfiguration();
$this->parser
->setConfiguration($config);
$result = $this->parser
->parse($this->feed, $fetcher_result, $this->state);
$this
->assertCount(3, $result);
$this
->assertSame('I am a title<thing>Stuff</thing>', $result[0]
->get('title'));
$this
->assertSame('I am a description0', $result[0]
->get('description'));
$this
->assertSame('I am a title1', $result[1]
->get('title'));
$this
->assertSame('I am a description1', $result[1]
->get('description'));
$this
->assertSame('I am a title2', $result[2]
->get('title'));
$this
->assertSame('I am a description2', $result[2]
->get('description'));
}