Skip to content

Commit

Permalink
tests: add test case for mixed direction text with tag-handling
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-jones-dev committed May 3, 2024
1 parent bb52c54 commit 7e1c098
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/TranslateTextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,31 @@ public function testMultipleText(?ClientInterface $httpClient)
$this->assertEquals('en', $result[1]->detectedSourceLang);
}

/**
* @dataProvider provideHttpClient
*/
public function testMixedDirectionText(?ClientInterface $httpClient)
{
$this->needsRealServer();
$translator = $this->makeTranslator([TranslatorOptions::HTTP_CLIENT => $httpClient]);
$options = [
TranslateTextOptions::TAG_HANDLING => 'xml',
TranslateTextOptions::IGNORE_TAGS => 'ignore',
];

$ar_ignore_part = "<ignore>يجب تجاهل هذا الجزء.</ignore>";
$en_sentence_with_ar_ignore_part =
"<p>This is a <b>short</b> <i>sentence</i>. $ar_ignore_part This is another sentence.";

$en_ignore_part = "<ignore>This part should be ignored.</ignore>";
$ar_sentence_with_en_ignore_part = "<p>هذه <i>جملة</i> <b>قصيرة</b>. $en_ignore_part هذه جملة أخرى.</p>";

$en_result = $translator->translateText($en_sentence_with_ar_ignore_part, null, 'en-US', $options);
$this->assertStringContainsString($ar_ignore_part, $en_result);
$ar_result = $translator->translateText($ar_sentence_with_en_ignore_part, null, 'ar', $options);
$this->assertStringContainsString($en_ignore_part, $ar_result);
}

/**
* @dataProvider provideHttpClient
*/
Expand Down

0 comments on commit 7e1c098

Please sign in to comment.