.
*/
declare(strict_types=1);
namespace Fisharebest\Webtrees\Reports;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Report\RightToLeftSupport;
use Fisharebest\Webtrees\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;
/**
* 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.
*/
#[CoversClass(RightToLeftSupport::class)]
class RightToLeftSupportTest extends TestCase
{
public function testEmptyString(): void
{
I18N::init('en-US', true);
static::assertSame(
'',
RightToLeftSupport::spanLtrRtl('')
);
I18N::init('he', true);
static::assertSame(
'',
RightToLeftSupport::spanLtrRtl('')
);
}
public function testStripControlCharacters(): void
{
I18N::init('en-US', true);
static::assertSame(
'foobar',
RightToLeftSupport::spanLtrRtl('foobar')
);
static::assertSame(
'foobar',
RightToLeftSupport::spanLtrRtl('foobar')
);
static::assertSame(
'foobar',
RightToLeftSupport::spanLtrRtl("foo\xE2\x80\x8Ebar")
);
static::assertSame(
'foobar',
RightToLeftSupport::spanLtrRtl("foo\xE2\x80\x8Fbar")
);
static::assertSame(
'foobar',
RightToLeftSupport::spanLtrRtl("foo\xE2\x80\xADbar")
);
static::assertSame(
'foobar',
RightToLeftSupport::spanLtrRtl("foo\xE2\x80\xAEbar")
);
static::assertSame(
'foobar',
RightToLeftSupport::spanLtrRtl("foo\xE2\x80\xAAbar")
);
static::assertSame(
'foobar',
RightToLeftSupport::spanLtrRtl("foo\xE2\x80\xABbar")
);
static::assertSame(
'foobar',
RightToLeftSupport::spanLtrRtl("foo\xE2\x80\xACbar")
);
I18N::init('he', true);
static::assertSame(
'foobar',
RightToLeftSupport::spanLtrRtl('foobar')
);
static::assertSame(
'foobar',
RightToLeftSupport::spanLtrRtl('foobar')
);
static::assertSame(
'foobar',
RightToLeftSupport::spanLtrRtl("foo\xE2\x80\x8Ebar")
);
static::assertSame(
'foobar',
RightToLeftSupport::spanLtrRtl("foo\xE2\x80\x8Fbar")
);
static::assertSame(
'foobar',
RightToLeftSupport::spanLtrRtl("foo\xE2\x80\xADbar")
);
static::assertSame(
'foobar',
RightToLeftSupport::spanLtrRtl("foo\xE2\x80\xAEbar")
);
static::assertSame(
'foobar',
RightToLeftSupport::spanLtrRtl("foo\xE2\x80\xAAbar")
);
static::assertSame(
'foobar',
RightToLeftSupport::spanLtrRtl("foo\xE2\x80\xABbar")
);
static::assertSame(
'foobar',
RightToLeftSupport::spanLtrRtl("foo\xE2\x80\xACbar")
);
}
public function testNewLinesBecomeHTMLBreaks(): void
{
I18N::init('en-US', true);
static::assertSame(
'foo
bar',
RightToLeftSupport::spanLtrRtl("foo\nbar")
);
static::assertSame(
'אבג
דהו',
RightToLeftSupport::spanLtrRtl("אבג\nדהו")
);
I18N::init('he', true);
static::assertSame(
'foo
bar',
RightToLeftSupport::spanLtrRtl("foo\nbar")
);
static::assertSame(
'אבג
דהו',
RightToLeftSupport::spanLtrRtl("אבג\nדהו")
);
}
public function testLineBreaks(): void
{
I18N::init('en-US', true);
static::assertSame(
'foo
bar',
RightToLeftSupport::spanLtrRtl('foo
bar')
);
static::assertSame(
'אבג
דהו',
RightToLeftSupport::spanLtrRtl('אבג
דהו')
);
I18N::init('he', true);
static::assertSame(
'foo
bar',
RightToLeftSupport::spanLtrRtl('foo
bar')
);
static::assertSame(
'אבג
דהו',
RightToLeftSupport::spanLtrRtl('אבג
דהו')
);
}
public function testHtmlEntities(): void
{
I18N::init('en-US', true);
static::assertSame(
'foo bar',
RightToLeftSupport::spanLtrRtl('foo bar')
);
static::assertSame(
'אבג דהו',
RightToLeftSupport::spanLtrRtl('אבג דהו')
);
static::assertSame(
'foo&bar',
RightToLeftSupport::spanLtrRtl('foo&bar')
);
I18N::init('he', true);
static::assertSame(
'foo bar',
RightToLeftSupport::spanLtrRtl('foo bar')
);
static::assertSame(
'אבג דהו',
RightToLeftSupport::spanLtrRtl('אבג דהו')
);
static::assertSame(
'foo&bar',
RightToLeftSupport::spanLtrRtl('foo&bar')
);
}
public function testBraces(): void
{
I18N::init('en-US', true);
static::assertSame(
'foo{{123}}bar',
RightToLeftSupport::spanLtrRtl('foo{{123}}bar')
);
static::assertSame(
'foo{{bar',
RightToLeftSupport::spanLtrRtl('foo{{bar')
);
static::assertSame(
'אבג{{123}}דהו',
RightToLeftSupport::spanLtrRtl('אבג{{123}}דהו')
);
I18N::init('he', true);
static::assertSame(
'foo{{123}}bar',
RightToLeftSupport::spanLtrRtl('foo{{123}}bar')
);
static::assertSame(
'foo{{bar',
RightToLeftSupport::spanLtrRtl('foo{{bar')
);
static::assertSame(
'אבג{{123}}דהו',
RightToLeftSupport::spanLtrRtl('אבג{{123}}דהו')
);
}
public function testNumbers(): void
{
I18N::init('en-US', true);
static::assertSame(
'foo 123,456.789 bar',
RightToLeftSupport::spanLtrRtl('foo 123,456.789 bar')
);
static::assertSame(
'foo +123,456.789 bar',
RightToLeftSupport::spanLtrRtl('foo +123,456.789 bar')
);
static::assertSame(
'foo -123,456.789 bar',
RightToLeftSupport::spanLtrRtl('foo -123,456.789 bar')
);
static::assertSame(
'אבג 123,456.789 דהו',
RightToLeftSupport::spanLtrRtl('אבג 123,456.789 דהו')
);
static::assertSame(
'אבג +123,456.789 דהו',
RightToLeftSupport::spanLtrRtl('אבג +123,456.789 דהו')
);
static::assertSame(
'אבג -123,456.789 דהו',
RightToLeftSupport::spanLtrRtl('אבג -123,456.789 דהו')
);
I18N::init('he', true);
static::assertSame(
'foo 123,456.789 bar',
RightToLeftSupport::spanLtrRtl('foo 123,456.789 bar')
);
static::assertSame(
'foo +123,456.789 bar',
RightToLeftSupport::spanLtrRtl('foo +123,456.789 bar')
);
static::assertSame(
'foo -123,456.789 bar',
RightToLeftSupport::spanLtrRtl('foo -123,456.789 bar')
);
static::assertSame(
'אבג 123,456.789 דהו',
RightToLeftSupport::spanLtrRtl('אבג 123,456.789 דהו')
);
static::assertSame(
'אבג +123,456.789 דהו',
RightToLeftSupport::spanLtrRtl('אבג +123,456.789 דהו')
);
static::assertSame(
'אבג -123,456.789 דהו',
RightToLeftSupport::spanLtrRtl('אבג -123,456.789 דהו')
);
}
public function testParentheses(): void
{
I18N::init('en-US', true);
static::assertSame(
'foo (bar)',
RightToLeftSupport::spanLtrRtl('foo (bar)')
);
static::assertSame(
'foo (אבג)',
RightToLeftSupport::spanLtrRtl('foo (אבג)')
);
static::assertSame(
'אבג (bar)',
RightToLeftSupport::spanLtrRtl('אבג (bar)')
);
static::assertSame(
'אבג (דהו)',
RightToLeftSupport::spanLtrRtl('אבג (דהו)')
);
I18N::init('he', true);
static::assertSame(
'foo (bar)',
RightToLeftSupport::spanLtrRtl('foo (bar)')
);
static::assertSame(
'foo (אבג)',
RightToLeftSupport::spanLtrRtl('foo (אבג)')
);
static::assertSame(
'אבג (bar)',
RightToLeftSupport::spanLtrRtl('אבג (bar)')
);
static::assertSame(
'אבג (דהו)',
RightToLeftSupport::spanLtrRtl('אבג (דהו)')
);
}
public function testUnescapedHtml(): void
{
I18N::init('en-US', true);
static::assertSame(
'>foo<',
RightToLeftSupport::spanLtrRtl('>foo<')
);
static::assertSame(
'>אבג<',
RightToLeftSupport::spanLtrRtl('>אבג<')
);
I18N::init('he', true);
static::assertSame(
'>foo<',
RightToLeftSupport::spanLtrRtl('>foo<')
);
static::assertSame(
'>אבג<',
RightToLeftSupport::spanLtrRtl('>אבג<')
);
}
public function testBreakInNumber(): void
{
I18N::init('en-US', true);
static::assertSame(
'123
456',
RightToLeftSupport::spanLtrRtl('123
456')
);
I18N::init('he', true);
static::assertSame(
'123
456',
RightToLeftSupport::spanLtrRtl('123
456')
);
}
}