Skip to content

Commit

Permalink
Added a test for DomExtractor errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
parpalak committed Nov 22, 2023
1 parent 68e2f03 commit 3adf959
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion tests/unit/Rose/Extractor/ExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public function testRegexExtractor(string $htmlText, string $resultText): void
public function testDomExtractor(string $htmlText, string $resultText, ?array $words = null, $images = null): void
{
$extractionResult = $this->domExtractor->extract($htmlText);
$sentenceMap = $extractionResult->getContentWithMetadata()->getSentenceMap();

$sentenceMap = $extractionResult->getContentWithMetadata()->getSentenceMap();
self::assertEquals($resultText, $sentenceMap->toSentenceCollection()->getText());
if ($words !== null) {
self::assertEquals($words, $sentenceMap->toSentenceCollection()->getWordsArray());
Expand All @@ -57,6 +57,25 @@ public function testDomExtractor(string $htmlText, string $resultText, ?array $w
}
}

public function testDomExtractionError(): void
{
$extractor = new DomExtractor();

$extractionResult = $extractor->extract('<p>html text</p>');
self::assertFalse($extractionResult->getErrors()->hasErrors());

$extractionResult = $extractor->extract('Plain text');
self::assertTrue($extractionResult->getErrors()->hasErrors());
self::assertEquals(['1:? Found anonymous text block "Plain text". Consider using <p> tag as a text container. (code=anon_text)'], $extractionResult->getErrors()->getFormattedLines());

$extractionResult = $extractor->extract('<b>unbalanced html</i>');
self::assertTrue($extractionResult->getErrors()->hasErrors());
self::assertEquals([
'1:152 Unexpected end tag : i (code=76)',
'1:159 Opening and ending tag mismatch: body and b (code=76)',
], $extractionResult->getErrors()->getFormattedLines());
}

/**
* @dataProvider htmlSentenceProvider
*/
Expand Down

0 comments on commit 3adf959

Please sign in to comment.