. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Reports; use Fisharebest\Webtrees\I18N; 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\Reports\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\Reports\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\Reports\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\Reports\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\Reports\RightToLeftSupport * * @return void */ public function testHtmlEntities(): 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\Reports\RightToLeftSupport * * @return void */ public function xtestLeftToRight(): void { $this->assertSame('fooébar', RightToLeftSupport::spanLtrRtl('fooébar')); // Number $this->assertSame('foo 123,456.78 bar', RightToLeftSupport::spanLtrRtl('foo 123,456.78 bar')); $this->assertSame('foo -123,456.78 bar', RightToLeftSupport::spanLtrRtl('foo -123,456.78 bar')); $this->assertSame('foo +123,456.78 bar', RightToLeftSupport::spanLtrRtl('foo +123,456.78 bar')); $this->assertSame('אבג ‪123,456.78‬ bar', RightToLeftSupport::spanLtrRtl('אבג 123,456.78 bar')); $this->assertSame('אבג ‪-123,456.78‬ bar', RightToLeftSupport::spanLtrRtl('אבג -123,456.78 bar')); $this->assertSame('אבג ‪+123,456.78‬ bar', RightToLeftSupport::spanLtrRtl('אבג +123,456.78 bar')); // TCPDF directive $this->assertSame('{{FOO BAR}}', RightToLeftSupport::spanLtrRtl('{{FOO BAR}}')); // Broken TCPDF directive $this->assertSame('{{FOO BAR', RightToLeftSupport::spanLtrRtl('{{FOO BAR')); // Starred name. $this->assertSame('John Paul Sartre', RightToLeftSupport::spanLtrRtl('John Paul Sartre')); // Unclosed HTML tag $this->assertSame('', RightToLeftSupport::spanLtrRtl('assertSame('foo', RightToLeftSupport::spanLtrRtl('foo')); $this->assertSame('אבג', RightToLeftSupport::spanLtrRtl('אבג')); // Leading/trailing spaces $this->assertSame(' foo ', RightToLeftSupport::spanLtrRtl(' foo ')); $this->assertSame(' אבג ', RightToLeftSupport::spanLtrRtl(' אבג ')); $this->assertSame(' foo ', RightToLeftSupport::spanLtrRtl(' foo ')); $this->assertSame(' אבג ', RightToLeftSupport::spanLtrRtl(' אבג ')); // Spaces stick to the LTR text $this->assertSame('foo אבג', RightToLeftSupport::spanLtrRtl('foo אבג')); $this->assertSame('אבג foo', RightToLeftSupport::spanLtrRtl('אבג foo')); // Line breaks $this->assertSame('foo
אבג
bar', RightToLeftSupport::spanLtrRtl('foo
אבג
bar')); } }