. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Reports; use Fisharebest\Webtrees\I18N; use Fisharebest\Webtrees\Report\RightToLeftSupport; use Fisharebest\Webtrees\TestCase; /** * Test the RTL functions. This is very old code, and poorly understood. * These tests exist to capture the existing functionality, and prevent regression during refactoring. */ class RightToLeftSupportTest extends TestCase { /** * @covers \Fisharebest\Webtrees\Report\RightToLeftSupport * * @return void */ public function testEmptyString(): void { I18N::init('en-US', true); $this->assertSame( '', RightToLeftSupport::spanLtrRtl('') ); I18N::init('he', true); $this->assertSame( '', RightToLeftSupport::spanLtrRtl('') ); } /** * @covers \Fisharebest\Webtrees\Report\RightToLeftSupport * * @return void */ public function testStripControlCharacters(): void { I18N::init('en-US', true); $this->assertSame( 'foobar', RightToLeftSupport::spanLtrRtl('foo‎bar') ); $this->assertSame( 'foobar', RightToLeftSupport::spanLtrRtl('foo‏bar') ); $this->assertSame( 'foobar', RightToLeftSupport::spanLtrRtl("foo\xE2\x80\x8Ebar") ); $this->assertSame( 'foobar', RightToLeftSupport::spanLtrRtl("foo\xE2\x80\x8Fbar") ); $this->assertSame( 'foobar', RightToLeftSupport::spanLtrRtl("foo\xE2\x80\xADbar") ); $this->assertSame( 'foobar', RightToLeftSupport::spanLtrRtl("foo\xE2\x80\xAEbar") ); $this->assertSame( 'foobar', RightToLeftSupport::spanLtrRtl("foo\xE2\x80\xAAbar") ); $this->assertSame( 'foobar', RightToLeftSupport::spanLtrRtl("foo\xE2\x80\xABbar") ); $this->assertSame( 'foobar', RightToLeftSupport::spanLtrRtl("foo\xE2\x80\xACbar") ); I18N::init('he', true); $this->assertSame( 'foobar', RightToLeftSupport::spanLtrRtl('foo‎bar') ); $this->assertSame( 'foobar', RightToLeftSupport::spanLtrRtl('foo‏bar') ); $this->assertSame( 'foobar', RightToLeftSupport::spanLtrRtl("foo\xE2\x80\x8Ebar") ); $this->assertSame( 'foobar', RightToLeftSupport::spanLtrRtl("foo\xE2\x80\x8Fbar") ); $this->assertSame( 'foobar', RightToLeftSupport::spanLtrRtl("foo\xE2\x80\xADbar") ); $this->assertSame( 'foobar', RightToLeftSupport::spanLtrRtl("foo\xE2\x80\xAEbar") ); $this->assertSame( 'foobar', RightToLeftSupport::spanLtrRtl("foo\xE2\x80\xAAbar") ); $this->assertSame( 'foobar', RightToLeftSupport::spanLtrRtl("foo\xE2\x80\xABbar") ); $this->assertSame( 'foobar', RightToLeftSupport::spanLtrRtl("foo\xE2\x80\xACbar") ); } /** * @covers \Fisharebest\Webtrees\Report\RightToLeftSupport * * @return void */ public function testNewLinesBecomeHTMLBreaks(): void { I18N::init('en-US', true); $this->assertSame( 'foo
bar', RightToLeftSupport::spanLtrRtl("foo\nbar") ); $this->assertSame( 'אבג
דהו', RightToLeftSupport::spanLtrRtl("אבג\nדהו") ); I18N::init('he', true); $this->assertSame( 'foo
bar', RightToLeftSupport::spanLtrRtl("foo\nbar") ); $this->assertSame( 'אבג
דהו', RightToLeftSupport::spanLtrRtl("אבג\nדהו") ); } /** * @covers \Fisharebest\Webtrees\Report\RightToLeftSupport * * @return void */ public function testLineBreaks(): void { I18N::init('en-US', true); $this->assertSame( 'foo
bar', RightToLeftSupport::spanLtrRtl("foo
bar") ); $this->assertSame( 'אבג
דהו', RightToLeftSupport::spanLtrRtl("אבג
דהו") ); I18N::init('he', true); $this->assertSame( 'foo
bar', RightToLeftSupport::spanLtrRtl("foo
bar") ); $this->assertSame( 'אבג
דהו', RightToLeftSupport::spanLtrRtl("אבג
דהו") ); } /** * @covers \Fisharebest\Webtrees\Report\RightToLeftSupport * * @return void */ public function testHtmlEntities(): void { I18N::init('en-US', true); $this->assertSame( 'foo bar', RightToLeftSupport::spanLtrRtl('foo bar') ); $this->assertSame( 'אבג דהו', RightToLeftSupport::spanLtrRtl('אבג דהו') ); $this->assertSame( 'foo&bar', RightToLeftSupport::spanLtrRtl('foo&bar') ); I18N::init('he', true); $this->assertSame( 'foo bar', RightToLeftSupport::spanLtrRtl("foo bar") ); $this->assertSame( 'אבג דהו', RightToLeftSupport::spanLtrRtl("אבג דהו") ); $this->assertSame( 'foo&bar', RightToLeftSupport::spanLtrRtl('foo&bar') ); } /** * @covers \Fisharebest\Webtrees\Report\RightToLeftSupport * * @return void */ public function testBraces(): void { I18N::init('en-US', true); $this->assertSame( 'foo{{123}}bar', RightToLeftSupport::spanLtrRtl('foo{{123}}bar') ); $this->assertSame( 'foo{{bar', RightToLeftSupport::spanLtrRtl('foo{{bar') ); $this->assertSame( 'אבג{{123}}דהו', RightToLeftSupport::spanLtrRtl('אבג{{123}}דהו') ); I18N::init('he', true); $this->assertSame( 'foo{{123}}bar', RightToLeftSupport::spanLtrRtl('foo{{123}}bar') ); $this->assertSame( 'foo{{bar', RightToLeftSupport::spanLtrRtl('foo{{bar') ); $this->assertSame( 'אבג{{123}}דהו', RightToLeftSupport::spanLtrRtl('אבג{{123}}דהו') ); } /** * @covers \Fisharebest\Webtrees\Report\RightToLeftSupport * * @return void */ public function testNumbers(): void { I18N::init('en-US', true); $this->assertSame( 'foo 123,456.789 bar', RightToLeftSupport::spanLtrRtl('foo 123,456.789 bar') ); $this->assertSame( 'foo +123,456.789 bar', RightToLeftSupport::spanLtrRtl('foo +123,456.789 bar') ); $this->assertSame( 'foo -123,456.789 bar', RightToLeftSupport::spanLtrRtl('foo -123,456.789 bar') ); $this->assertSame( 'אבג ‪123,456.789‬ דהו', RightToLeftSupport::spanLtrRtl('אבג 123,456.789 דהו') ); $this->assertSame( 'אבג ‪+123,456.789‬ דהו', RightToLeftSupport::spanLtrRtl('אבג +123,456.789 דהו') ); $this->assertSame( 'אבג ‪-123,456.789‬ דהו', RightToLeftSupport::spanLtrRtl('אבג -123,456.789 דהו') ); I18N::init('he', true); $this->assertSame( 'foo 123,456.789 bar', RightToLeftSupport::spanLtrRtl('foo 123,456.789 bar') ); $this->assertSame( 'foo +123,456.789 bar', RightToLeftSupport::spanLtrRtl('foo +123,456.789 bar') ); $this->assertSame( 'foo -123,456.789 bar', RightToLeftSupport::spanLtrRtl('foo -123,456.789 bar') ); $this->assertSame( 'אבג ‪123,456.789‬ דהו', RightToLeftSupport::spanLtrRtl('אבג 123,456.789 דהו') ); $this->assertSame( 'אבג ‪+123,456.789‬ דהו', RightToLeftSupport::spanLtrRtl('אבג +123,456.789 דהו') ); $this->assertSame( 'אבג ‪-123,456.789‬ דהו', RightToLeftSupport::spanLtrRtl('אבג -123,456.789 דהו') ); } /** * @covers \Fisharebest\Webtrees\Report\RightToLeftSupport * * @return void */ public function testParentheses(): void { I18N::init('en-US', true); $this->assertSame( 'foo (bar)', RightToLeftSupport::spanLtrRtl('foo (bar)') ); $this->assertSame( 'foo (אבג)', RightToLeftSupport::spanLtrRtl('foo (אבג)') ); $this->assertSame( 'אבג (bar)', RightToLeftSupport::spanLtrRtl('אבג (bar)') ); $this->assertSame( 'אבג (דהו)', RightToLeftSupport::spanLtrRtl('אבג (דהו)') ); I18N::init('he', true); $this->assertSame( 'foo (bar)', RightToLeftSupport::spanLtrRtl('foo (bar)') ); $this->assertSame( 'foo (אבג)', RightToLeftSupport::spanLtrRtl('foo (אבג)') ); $this->assertSame( 'אבג (bar)', RightToLeftSupport::spanLtrRtl('אבג (bar)') ); $this->assertSame( 'אבג (דהו)', RightToLeftSupport::spanLtrRtl('אבג (דהו)') ); } /** * @covers \Fisharebest\Webtrees\Report\RightToLeftSupport * * @return void */ public function testUnescapedHtml(): void { I18N::init('en-US', true); $this->assertSame( '>foo<', RightToLeftSupport::spanLtrRtl(">foo<") ); $this->assertSame( '>אבג<', RightToLeftSupport::spanLtrRtl(">אבג<") ); I18N::init('he', true); $this->assertSame( '>foo<', RightToLeftSupport::spanLtrRtl(">foo<") ); $this->assertSame( '>אבג<', RightToLeftSupport::spanLtrRtl(">אבג<") ); } /** * @covers \Fisharebest\Webtrees\Report\RightToLeftSupport * * @return void */ public function testBreakInNumber(): void { I18N::init('en-US', true); $this->assertSame( '123
456', RightToLeftSupport::spanLtrRtl("123
456") ); I18N::init('he', true); $this->assertSame( '‪123‬
‪456‬', RightToLeftSupport::spanLtrRtl("123
456") ); } }