.
*/
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
*/
public function testEmptyString(): void
{
I18N::init('en-US', true);
static::assertSame(
'',
RightToLeftSupport::spanLtrRtl('')
);
I18N::init('he', true);
static::assertSame(
'',
RightToLeftSupport::spanLtrRtl('')
);
}
/**
* @covers \Fisharebest\Webtrees\Report\RightToLeftSupport
*/
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")
);
}
/**
* @covers \Fisharebest\Webtrees\Report\RightToLeftSupport
*/
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דהו")
);
}
/**
* @covers \Fisharebest\Webtrees\Report\RightToLeftSupport
*/
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('אבג
דהו')
);
}
/**
* @covers \Fisharebest\Webtrees\Report\RightToLeftSupport
*/
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')
);
}
/**
* @covers \Fisharebest\Webtrees\Report\RightToLeftSupport
*/
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}}דהו')
);
}
/**
* @covers \Fisharebest\Webtrees\Report\RightToLeftSupport
*/
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 דהו')
);
}
/**
* @covers \Fisharebest\Webtrees\Report\RightToLeftSupport
*/
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('אבג (דהו)')
);
}
/**
* @covers \Fisharebest\Webtrees\Report\RightToLeftSupport
*/
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('>אבג<')
);
}
/**
* @covers \Fisharebest\Webtrees\Report\RightToLeftSupport
*/
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')
);
}
}