diff options
| author | Greg Roach <greg@subaqua.co.uk> | 2021-11-05 18:30:58 +0000 |
|---|---|---|
| committer | Greg Roach <greg@subaqua.co.uk> | 2021-11-05 18:36:45 +0000 |
| commit | 062377ee959c5bca8672cc6d68c83a87e2c6abfc (patch) | |
| tree | c18ce0088b577c5a7a7cf67a115dc6863a350b19 /tests/app/Reports | |
| parent | 5183874f79e6c96ed7a5a66bc6a021feaad4d6f6 (diff) | |
| download | webtrees-062377ee959c5bca8672cc6d68c83a87e2c6abfc.tar.gz webtrees-062377ee959c5bca8672cc6d68c83a87e2c6abfc.tar.bz2 webtrees-062377ee959c5bca8672cc6d68c83a87e2c6abfc.zip | |
Unit tests for RightToLeftSupport
Diffstat (limited to 'tests/app/Reports')
| -rw-r--r-- | tests/app/Reports/RightToLeftSupportTest.php | 223 |
1 files changed, 190 insertions, 33 deletions
diff --git a/tests/app/Reports/RightToLeftSupportTest.php b/tests/app/Reports/RightToLeftSupportTest.php index 5b0de222a7..10e9139cc7 100644 --- a/tests/app/Reports/RightToLeftSupportTest.php +++ b/tests/app/Reports/RightToLeftSupportTest.php @@ -37,7 +37,6 @@ class RightToLeftSupportTest extends TestCase { I18N::init('en-US', true); $this->assertSame( - '', RightToLeftSupport::spanLtrRtl('') ); @@ -199,11 +198,15 @@ class RightToLeftSupportTest extends TestCase I18N::init('en-US', true); $this->assertSame( '<span dir="ltr">foo bar</span>', - RightToLeftSupport::spanLtrRtl("foo bar") + RightToLeftSupport::spanLtrRtl('foo bar') ); $this->assertSame( '<span dir="rtl">אבג דהו</span>', - RightToLeftSupport::spanLtrRtl("אבג דהו") + RightToLeftSupport::spanLtrRtl('אבג דהו') + ); + $this->assertSame( + '<span dir="ltr">foo&bar</span>', + RightToLeftSupport::spanLtrRtl('foo&bar') ); I18N::init('he', true); @@ -215,6 +218,106 @@ class RightToLeftSupportTest extends TestCase '<span dir="rtl">אבג דהו</span>', RightToLeftSupport::spanLtrRtl("אבג דהו") ); + $this->assertSame( + '<span dir="ltr">foo&bar</span>', + RightToLeftSupport::spanLtrRtl('foo&bar') + ); + } + + /** + * @covers \Fisharebest\Webtrees\Reports\RightToLeftSupport + * + * @return void + */ + public function testBraces(): void + { + I18N::init('en-US', true); + $this->assertSame( + '<span dir="ltr">foo{{123}}bar</span>', + RightToLeftSupport::spanLtrRtl('foo{{123}}bar') + ); + $this->assertSame( + '<span dir="ltr">foo{{bar</span>', + RightToLeftSupport::spanLtrRtl('foo{{bar') + ); + $this->assertSame( + '<span dir="rtl">אבג{{123}}דהו</span>', + RightToLeftSupport::spanLtrRtl('אבג{{123}}דהו') + ); + + I18N::init('he', true); + $this->assertSame( + '<span dir="ltr">foo{{123}}bar</span>', + RightToLeftSupport::spanLtrRtl('foo{{123}}bar') + ); + $this->assertSame( + '<span dir="ltr">foo{{bar</span>', + RightToLeftSupport::spanLtrRtl('foo{{bar') + ); + $this->assertSame( + '<span dir="rtl">אבג{{123}}דהו</span>', + RightToLeftSupport::spanLtrRtl('אבג{{123}}דהו') + ); + } + + /** + * @covers \Fisharebest\Webtrees\Reports\RightToLeftSupport + * + * @return void + */ + public function testNumbers(): void + { + I18N::init('en-US', true); + $this->assertSame( + '<span dir="ltr">foo 123,456.789 bar</span>', + RightToLeftSupport::spanLtrRtl('foo 123,456.789 bar') + ); + $this->assertSame( + '<span dir="ltr">foo +123,456.789 bar</span>', + RightToLeftSupport::spanLtrRtl('foo +123,456.789 bar') + ); + $this->assertSame( + '<span dir="ltr">foo -123,456.789 bar</span>', + RightToLeftSupport::spanLtrRtl('foo -123,456.789 bar') + ); + $this->assertSame( + '<span dir="rtl">אבג 123,456.789 דהו</span>', + RightToLeftSupport::spanLtrRtl('אבג 123,456.789 דהו') + ); + $this->assertSame( + '<span dir="rtl">אבג +123,456.789 דהו</span>', + RightToLeftSupport::spanLtrRtl('אבג +123,456.789 דהו') + ); + $this->assertSame( + '<span dir="rtl">אבג -123,456.789 דהו</span>', + RightToLeftSupport::spanLtrRtl('אבג -123,456.789 דהו') + ); + + I18N::init('he', true); + $this->assertSame( + '<span dir="ltr">foo 123,456.789 bar</span>', + RightToLeftSupport::spanLtrRtl('foo 123,456.789 bar') + ); + $this->assertSame( + '<span dir="ltr">foo +123,456.789 bar</span>', + RightToLeftSupport::spanLtrRtl('foo +123,456.789 bar') + ); + $this->assertSame( + '<span dir="ltr">foo -123,456.789 bar</span>', + RightToLeftSupport::spanLtrRtl('foo -123,456.789 bar') + ); + $this->assertSame( + '<span dir="rtl">אבג 123,456.789 דהו</span>', + RightToLeftSupport::spanLtrRtl('אבג 123,456.789 דהו') + ); + $this->assertSame( + '<span dir="rtl">אבג +123,456.789 דהו</span>', + RightToLeftSupport::spanLtrRtl('אבג +123,456.789 דהו') + ); + $this->assertSame( + '<span dir="rtl">אבג -123,456.789 דהו</span>', + RightToLeftSupport::spanLtrRtl('אבג -123,456.789 דהו') + ); } /** @@ -222,36 +325,90 @@ class RightToLeftSupportTest extends TestCase * * @return void */ - public function xtestLeftToRight(): void + public function testParentheses(): void { - $this->assertSame('<span dir="ltr">fooébar</span>', RightToLeftSupport::spanLtrRtl('fooébar')); - // Number - $this->assertSame('<span dir="ltr">foo 123,456.78 bar</span>', RightToLeftSupport::spanLtrRtl('foo 123,456.78 bar')); - $this->assertSame('<span dir="ltr">foo -123,456.78 bar</span>', RightToLeftSupport::spanLtrRtl('foo -123,456.78 bar')); - $this->assertSame('<span dir="ltr">foo +123,456.78 bar</span>', RightToLeftSupport::spanLtrRtl('foo +123,456.78 bar')); - $this->assertSame('<span dir="rtl">אבג</span><span dir="ltr"> 123,456.78 bar</span>', RightToLeftSupport::spanLtrRtl('אבג 123,456.78 bar')); - $this->assertSame('<span dir="rtl">אבג</span><span dir="ltr"> -123,456.78 bar</span>', RightToLeftSupport::spanLtrRtl('אבג -123,456.78 bar')); - $this->assertSame('<span dir="rtl">אבג</span><span dir="ltr"> +123,456.78 bar</span>', RightToLeftSupport::spanLtrRtl('אבג +123,456.78 bar')); - // TCPDF directive - $this->assertSame('<span dir="ltr">{{FOO BAR}}</span>', RightToLeftSupport::spanLtrRtl('{{FOO BAR}}')); - // Broken TCPDF directive - $this->assertSame('<span dir="ltr">{{FOO BAR</span>', RightToLeftSupport::spanLtrRtl('{{FOO BAR')); - // Starred name. - $this->assertSame('<span dir="ltr">John <u>Paul</u> Sartre</span>', RightToLeftSupport::spanLtrRtl('John <span class="starredname">Paul</span> Sartre')); - // Unclosed HTML tag - $this->assertSame('<span dir="ltr"><foo</span>', RightToLeftSupport::spanLtrRtl('<foo')); - // All LTR/RTL - $this->assertSame('<span dir="ltr">foo</span>', RightToLeftSupport::spanLtrRtl('foo')); - $this->assertSame('<span dir="rtl">אבג</span>', RightToLeftSupport::spanLtrRtl('אבג')); - // Leading/trailing spaces - $this->assertSame('<span dir="ltr"> foo </span>', RightToLeftSupport::spanLtrRtl(' foo ')); - $this->assertSame('<span dir="ltr"> </span><span dir="rtl">אבג</span><span dir="ltr"> </span>', RightToLeftSupport::spanLtrRtl(' אבג ')); - $this->assertSame('<span dir="ltr"> foo </span>', RightToLeftSupport::spanLtrRtl(' foo ')); - $this->assertSame('<span dir="ltr"> </span><span dir="rtl">אבג</span><span dir="ltr"> </span>', RightToLeftSupport::spanLtrRtl(' אבג ')); - // Spaces stick to the LTR text - $this->assertSame('<span dir="ltr">foo </span><span dir="rtl">אבג</span>', RightToLeftSupport::spanLtrRtl('foo אבג')); - $this->assertSame('<span dir="rtl">אבג</span><span dir="ltr"> foo</span>', RightToLeftSupport::spanLtrRtl('אבג foo')); - // Line breaks - $this->assertSame('<span dir="ltr">foo</span><br><span dir="rtl">אבג</span><br><span dir="ltr">bar</span>', RightToLeftSupport::spanLtrRtl('foo<br>אבג<br>bar')); + I18N::init('en-US', true); + $this->assertSame( + '<span dir="ltr">foo (bar)</span>', + RightToLeftSupport::spanLtrRtl('foo (bar)') + ); + $this->assertSame( + '<span dir="ltr">foo </span><span dir="rtl">(אבג)</span>', + RightToLeftSupport::spanLtrRtl('foo (אבג)') + ); + $this->assertSame( + '<span dir="rtl">אבג</span><span dir="ltr"> (bar)</span>', + RightToLeftSupport::spanLtrRtl('אבג (bar)') + ); + $this->assertSame( + '<span dir="rtl">אבג (דהו)</span>', + RightToLeftSupport::spanLtrRtl('אבג (דהו)') + ); + + I18N::init('he', true); + $this->assertSame( + '<span dir="ltr">foo (bar)</span>', + RightToLeftSupport::spanLtrRtl('foo (bar)') + ); + $this->assertSame( + '<span dir="ltr">foo </span><span dir="rtl">(אבג)</span>', + RightToLeftSupport::spanLtrRtl('foo (אבג)') + ); + $this->assertSame( + '<span dir="rtl">אבג </span><span dir="ltr">(bar)</span>', + RightToLeftSupport::spanLtrRtl('אבג (bar)') + ); + $this->assertSame( + '<span dir="rtl">אבג (דהו)</span>', + RightToLeftSupport::spanLtrRtl('אבג (דהו)') + ); + } + + /** + * @covers \Fisharebest\Webtrees\Reports\RightToLeftSupport + * + * @return void + */ + public function testUnescapedHtml(): void + { + I18N::init('en-US', true); + $this->assertSame( + '<span dir="ltr">>foo<</span>', + RightToLeftSupport::spanLtrRtl(">foo<") + ); + $this->assertSame( + '<span dir="ltr">></span><span dir="rtl">אבג<</span>', + RightToLeftSupport::spanLtrRtl(">אבג<") + ); + + I18N::init('he', true); + $this->assertSame( + '<span dir="rtl">></span><span dir="ltr">foo<</span>', + RightToLeftSupport::spanLtrRtl(">foo<") + ); + $this->assertSame( + '<span dir="rtl">>אבג<</span>', + RightToLeftSupport::spanLtrRtl(">אבג<") + ); + } + + /** + * @covers \Fisharebest\Webtrees\Reports\RightToLeftSupport + * + * @return void + */ + public function testBreakInNumber(): void + { + I18N::init('en-US', true); + $this->assertSame( + '<span dir="ltr">123</span><br><span dir="ltr">456</span>', + RightToLeftSupport::spanLtrRtl("123<br>456") + ); + + I18N::init('he', true); + $this->assertSame( + '<span dir="rtl">123</span><br><span dir="rtl">456</span>', + RightToLeftSupport::spanLtrRtl("123<br>456") + ); } } |
