Skip to content

Commit 69fdc5c

Browse files
committed
test(translation-detector): add direct tests for isTranslated
Covers the previously untested public method with four cases: wrapped text (true), bare text (false), mismatched text (false), and escaped single quotes in wrapper (true).
1 parent 2e938b3 commit 69fdc5c

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

tests/PatternDiff/TranslationDetectorTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,38 @@ public function testGenerateTranslationWrapperUsesElayneDomain(): void
136136
$this->assertStringContainsString("'elayne'", $wrapper);
137137
}
138138

139+
// ========================================================================
140+
// isTranslated Tests
141+
// ========================================================================
142+
143+
public function testIsTranslatedReturnsTrueWhenTextIsWrapped(): void
144+
{
145+
$content = "<?php esc_html_e( 'Hello World', 'elayne' ); ?>";
146+
147+
$this->assertTrue($this->detector->isTranslated('Hello World', $content));
148+
}
149+
150+
public function testIsTranslatedReturnsFalseWhenTextIsBare(): void
151+
{
152+
$content = '<p>Hello World</p>';
153+
154+
$this->assertFalse($this->detector->isTranslated('Hello World', $content));
155+
}
156+
157+
public function testIsTranslatedReturnsFalseForDifferentText(): void
158+
{
159+
$content = "<?php esc_html_e( 'Goodbye', 'elayne' ); ?>";
160+
161+
$this->assertFalse($this->detector->isTranslated('Hello World', $content));
162+
}
163+
164+
public function testIsTranslatedReturnsTrueWithSingleQuotesInWrapper(): void
165+
{
166+
$content = "<?php esc_html_e( 'It\\'s fine', 'elayne' ); ?>";
167+
168+
$this->assertTrue($this->detector->isTranslated("It\\'s fine", $content));
169+
}
170+
139171
// ========================================================================
140172
// extractTranslatableText Tests
141173
// ========================================================================

0 commit comments

Comments
 (0)