15183874fSGreg Roach<?php 25183874fSGreg Roach 35183874fSGreg Roach/** 45183874fSGreg Roach * webtrees: online genealogy 5d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 65183874fSGreg Roach * This program is free software: you can redistribute it and/or modify 75183874fSGreg Roach * it under the terms of the GNU General Public License as published by 85183874fSGreg Roach * the Free Software Foundation, either version 3 of the License, or 95183874fSGreg Roach * (at your option) any later version. 105183874fSGreg Roach * This program is distributed in the hope that it will be useful, 115183874fSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 125183874fSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 135183874fSGreg Roach * GNU General Public License for more details. 145183874fSGreg Roach * You should have received a copy of the GNU General Public License 155183874fSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 165183874fSGreg Roach */ 175183874fSGreg Roach 185183874fSGreg Roachdeclare(strict_types=1); 195183874fSGreg Roach 205183874fSGreg Roachnamespace Fisharebest\Webtrees\Reports; 215183874fSGreg Roach 225183874fSGreg Roachuse Fisharebest\Webtrees\I18N; 23d5e02c3aSGreg Roachuse Fisharebest\Webtrees\Report\RightToLeftSupport; 245183874fSGreg Roachuse Fisharebest\Webtrees\TestCase; 25*202c018bSGreg Roachuse PHPUnit\Framework\Attributes\CoversClass; 265183874fSGreg Roach 275183874fSGreg Roach/** 285183874fSGreg Roach * Test the RTL functions. This is very old code, and poorly understood. 295183874fSGreg Roach * These tests exist to capture the existing functionality, and prevent regression during refactoring. 305183874fSGreg Roach */ 31*202c018bSGreg Roach#[CoversClass(RightToLeftSupport::class)] 325183874fSGreg Roachclass RightToLeftSupportTest extends TestCase 335183874fSGreg Roach{ 345183874fSGreg Roach public function testEmptyString(): void 355183874fSGreg Roach { 365183874fSGreg Roach I18N::init('en-US', true); 37f01ab4acSGreg Roach static::assertSame( 385183874fSGreg Roach '', 395183874fSGreg Roach RightToLeftSupport::spanLtrRtl('') 405183874fSGreg Roach ); 415183874fSGreg Roach 425183874fSGreg Roach I18N::init('he', true); 43f01ab4acSGreg Roach static::assertSame( 445183874fSGreg Roach '', 455183874fSGreg Roach RightToLeftSupport::spanLtrRtl('') 465183874fSGreg Roach ); 475183874fSGreg Roach } 485183874fSGreg Roach 495183874fSGreg Roach public function testStripControlCharacters(): void 505183874fSGreg Roach { 515183874fSGreg Roach I18N::init('en-US', true); 52f01ab4acSGreg Roach static::assertSame( 535183874fSGreg Roach '<span dir="ltr">foobar</span>', 545183874fSGreg Roach RightToLeftSupport::spanLtrRtl('foo‎bar') 555183874fSGreg Roach ); 56f01ab4acSGreg Roach static::assertSame( 575183874fSGreg Roach '<span dir="ltr">foobar</span>', 585183874fSGreg Roach RightToLeftSupport::spanLtrRtl('foo‏bar') 595183874fSGreg Roach ); 60f01ab4acSGreg Roach static::assertSame( 615183874fSGreg Roach '<span dir="ltr">foobar</span>', 625183874fSGreg Roach RightToLeftSupport::spanLtrRtl("foo\xE2\x80\x8Ebar") 635183874fSGreg Roach ); 64f01ab4acSGreg Roach static::assertSame( 655183874fSGreg Roach '<span dir="ltr">foobar</span>', 665183874fSGreg Roach RightToLeftSupport::spanLtrRtl("foo\xE2\x80\x8Fbar") 675183874fSGreg Roach ); 68f01ab4acSGreg Roach static::assertSame( 695183874fSGreg Roach '<span dir="ltr">foobar</span>', 705183874fSGreg Roach RightToLeftSupport::spanLtrRtl("foo\xE2\x80\xADbar") 715183874fSGreg Roach ); 72f01ab4acSGreg Roach static::assertSame( 735183874fSGreg Roach '<span dir="ltr">foobar</span>', 745183874fSGreg Roach RightToLeftSupport::spanLtrRtl("foo\xE2\x80\xAEbar") 755183874fSGreg Roach ); 76f01ab4acSGreg Roach static::assertSame( 775183874fSGreg Roach '<span dir="ltr">foobar</span>', 785183874fSGreg Roach RightToLeftSupport::spanLtrRtl("foo\xE2\x80\xAAbar") 795183874fSGreg Roach ); 80f01ab4acSGreg Roach static::assertSame( 815183874fSGreg Roach '<span dir="ltr">foobar</span>', 825183874fSGreg Roach RightToLeftSupport::spanLtrRtl("foo\xE2\x80\xABbar") 835183874fSGreg Roach ); 84f01ab4acSGreg Roach static::assertSame( 855183874fSGreg Roach '<span dir="ltr">foobar</span>', 865183874fSGreg Roach RightToLeftSupport::spanLtrRtl("foo\xE2\x80\xACbar") 875183874fSGreg Roach ); 885183874fSGreg Roach 895183874fSGreg Roach I18N::init('he', true); 90f01ab4acSGreg Roach static::assertSame( 915183874fSGreg Roach '<span dir="ltr">foobar</span>', 925183874fSGreg Roach RightToLeftSupport::spanLtrRtl('foo‎bar') 935183874fSGreg Roach ); 94f01ab4acSGreg Roach static::assertSame( 955183874fSGreg Roach '<span dir="ltr">foobar</span>', 965183874fSGreg Roach RightToLeftSupport::spanLtrRtl('foo‏bar') 975183874fSGreg Roach ); 98f01ab4acSGreg Roach static::assertSame( 995183874fSGreg Roach '<span dir="ltr">foobar</span>', 1005183874fSGreg Roach RightToLeftSupport::spanLtrRtl("foo\xE2\x80\x8Ebar") 1015183874fSGreg Roach ); 102f01ab4acSGreg Roach static::assertSame( 1035183874fSGreg Roach '<span dir="ltr">foobar</span>', 1045183874fSGreg Roach RightToLeftSupport::spanLtrRtl("foo\xE2\x80\x8Fbar") 1055183874fSGreg Roach ); 106f01ab4acSGreg Roach static::assertSame( 1075183874fSGreg Roach '<span dir="ltr">foobar</span>', 1085183874fSGreg Roach RightToLeftSupport::spanLtrRtl("foo\xE2\x80\xADbar") 1095183874fSGreg Roach ); 110f01ab4acSGreg Roach static::assertSame( 1115183874fSGreg Roach '<span dir="ltr">foobar</span>', 1125183874fSGreg Roach RightToLeftSupport::spanLtrRtl("foo\xE2\x80\xAEbar") 1135183874fSGreg Roach ); 114f01ab4acSGreg Roach static::assertSame( 1155183874fSGreg Roach '<span dir="ltr">foobar</span>', 1165183874fSGreg Roach RightToLeftSupport::spanLtrRtl("foo\xE2\x80\xAAbar") 1175183874fSGreg Roach ); 118f01ab4acSGreg Roach static::assertSame( 1195183874fSGreg Roach '<span dir="ltr">foobar</span>', 1205183874fSGreg Roach RightToLeftSupport::spanLtrRtl("foo\xE2\x80\xABbar") 1215183874fSGreg Roach ); 122f01ab4acSGreg Roach static::assertSame( 1235183874fSGreg Roach '<span dir="ltr">foobar</span>', 1245183874fSGreg Roach RightToLeftSupport::spanLtrRtl("foo\xE2\x80\xACbar") 1255183874fSGreg Roach ); 1265183874fSGreg Roach } 1275183874fSGreg Roach 1285183874fSGreg Roach public function testNewLinesBecomeHTMLBreaks(): void 1295183874fSGreg Roach { 1305183874fSGreg Roach I18N::init('en-US', true); 131f01ab4acSGreg Roach static::assertSame( 1325183874fSGreg Roach '<span dir="ltr">foo</span><br><span dir="ltr">bar</span>', 1335183874fSGreg Roach RightToLeftSupport::spanLtrRtl("foo\nbar") 1345183874fSGreg Roach ); 135f01ab4acSGreg Roach static::assertSame( 1365183874fSGreg Roach '<span dir="rtl">אבג</span><br><span dir="rtl">דהו</span>', 1375183874fSGreg Roach RightToLeftSupport::spanLtrRtl("אבג\nדהו") 1385183874fSGreg Roach ); 1395183874fSGreg Roach 1405183874fSGreg Roach I18N::init('he', true); 141f01ab4acSGreg Roach static::assertSame( 1425183874fSGreg Roach '<span dir="ltr">foo</span><br><span dir="ltr">bar</span>', 1435183874fSGreg Roach RightToLeftSupport::spanLtrRtl("foo\nbar") 1445183874fSGreg Roach ); 145f01ab4acSGreg Roach static::assertSame( 1465183874fSGreg Roach '<span dir="rtl">אבג</span><br><span dir="rtl">דהו</span>', 1475183874fSGreg Roach RightToLeftSupport::spanLtrRtl("אבג\nדהו") 1485183874fSGreg Roach ); 1495183874fSGreg Roach } 1505183874fSGreg Roach 1515183874fSGreg Roach public function testLineBreaks(): void 1525183874fSGreg Roach { 1535183874fSGreg Roach I18N::init('en-US', true); 154f01ab4acSGreg Roach static::assertSame( 1555183874fSGreg Roach '<span dir="ltr">foo</span><br><span dir="ltr">bar</span>', 1566e60786aSGreg Roach RightToLeftSupport::spanLtrRtl('foo<br>bar') 1575183874fSGreg Roach ); 158f01ab4acSGreg Roach static::assertSame( 1595183874fSGreg Roach '<span dir="rtl">אבג</span><br><span dir="rtl">דהו</span>', 1606e60786aSGreg Roach RightToLeftSupport::spanLtrRtl('אבג<br>דהו') 1615183874fSGreg Roach ); 1625183874fSGreg Roach 1635183874fSGreg Roach I18N::init('he', true); 164f01ab4acSGreg Roach static::assertSame( 1655183874fSGreg Roach '<span dir="ltr">foo</span><br><span dir="ltr">bar</span>', 1666e60786aSGreg Roach RightToLeftSupport::spanLtrRtl('foo<br>bar') 1675183874fSGreg Roach ); 168f01ab4acSGreg Roach static::assertSame( 1695183874fSGreg Roach '<span dir="rtl">אבג</span><br><span dir="rtl">דהו</span>', 1706e60786aSGreg Roach RightToLeftSupport::spanLtrRtl('אבג<br>דהו') 1715183874fSGreg Roach ); 1725183874fSGreg Roach } 1735183874fSGreg Roach 1745183874fSGreg Roach public function testHtmlEntities(): void 1755183874fSGreg Roach { 1765183874fSGreg Roach I18N::init('en-US', true); 177f01ab4acSGreg Roach static::assertSame( 1785183874fSGreg Roach '<span dir="ltr">foo bar</span>', 179062377eeSGreg Roach RightToLeftSupport::spanLtrRtl('foo bar') 1805183874fSGreg Roach ); 181f01ab4acSGreg Roach static::assertSame( 1825183874fSGreg Roach '<span dir="rtl">אבג דהו</span>', 183062377eeSGreg Roach RightToLeftSupport::spanLtrRtl('אבג דהו') 184062377eeSGreg Roach ); 185f01ab4acSGreg Roach static::assertSame( 186062377eeSGreg Roach '<span dir="ltr">foo&bar</span>', 187062377eeSGreg Roach RightToLeftSupport::spanLtrRtl('foo&bar') 1885183874fSGreg Roach ); 1895183874fSGreg Roach 1905183874fSGreg Roach I18N::init('he', true); 191f01ab4acSGreg Roach static::assertSame( 1925183874fSGreg Roach '<span dir="ltr">foo bar</span>', 1936e60786aSGreg Roach RightToLeftSupport::spanLtrRtl('foo bar') 1945183874fSGreg Roach ); 195f01ab4acSGreg Roach static::assertSame( 1965183874fSGreg Roach '<span dir="rtl">אבג דהו</span>', 1976e60786aSGreg Roach RightToLeftSupport::spanLtrRtl('אבג דהו') 1985183874fSGreg Roach ); 199f01ab4acSGreg Roach static::assertSame( 200062377eeSGreg Roach '<span dir="ltr">foo&bar</span>', 201062377eeSGreg Roach RightToLeftSupport::spanLtrRtl('foo&bar') 202062377eeSGreg Roach ); 2035183874fSGreg Roach } 2045183874fSGreg Roach 205062377eeSGreg Roach public function testBraces(): void 2065183874fSGreg Roach { 207062377eeSGreg Roach I18N::init('en-US', true); 208f01ab4acSGreg Roach static::assertSame( 209062377eeSGreg Roach '<span dir="ltr">foo{{123}}bar</span>', 210062377eeSGreg Roach RightToLeftSupport::spanLtrRtl('foo{{123}}bar') 211062377eeSGreg Roach ); 212f01ab4acSGreg Roach static::assertSame( 213062377eeSGreg Roach '<span dir="ltr">foo{{bar</span>', 214062377eeSGreg Roach RightToLeftSupport::spanLtrRtl('foo{{bar') 215062377eeSGreg Roach ); 216f01ab4acSGreg Roach static::assertSame( 217062377eeSGreg Roach '<span dir="rtl">אבג{{123}}דהו</span>', 218062377eeSGreg Roach RightToLeftSupport::spanLtrRtl('אבג{{123}}דהו') 219062377eeSGreg Roach ); 220062377eeSGreg Roach 221062377eeSGreg Roach I18N::init('he', true); 222f01ab4acSGreg Roach static::assertSame( 223062377eeSGreg Roach '<span dir="ltr">foo{{123}}bar</span>', 224062377eeSGreg Roach RightToLeftSupport::spanLtrRtl('foo{{123}}bar') 225062377eeSGreg Roach ); 226f01ab4acSGreg Roach static::assertSame( 227062377eeSGreg Roach '<span dir="ltr">foo{{bar</span>', 228062377eeSGreg Roach RightToLeftSupport::spanLtrRtl('foo{{bar') 229062377eeSGreg Roach ); 230f01ab4acSGreg Roach static::assertSame( 231062377eeSGreg Roach '<span dir="rtl">אבג{{123}}דהו</span>', 232062377eeSGreg Roach RightToLeftSupport::spanLtrRtl('אבג{{123}}דהו') 233062377eeSGreg Roach ); 234062377eeSGreg Roach } 235062377eeSGreg Roach 236062377eeSGreg Roach public function testNumbers(): void 237062377eeSGreg Roach { 238062377eeSGreg Roach I18N::init('en-US', true); 239f01ab4acSGreg Roach static::assertSame( 240062377eeSGreg Roach '<span dir="ltr">foo 123,456.789 bar</span>', 241062377eeSGreg Roach RightToLeftSupport::spanLtrRtl('foo 123,456.789 bar') 242062377eeSGreg Roach ); 243f01ab4acSGreg Roach static::assertSame( 244062377eeSGreg Roach '<span dir="ltr">foo +123,456.789 bar</span>', 245062377eeSGreg Roach RightToLeftSupport::spanLtrRtl('foo +123,456.789 bar') 246062377eeSGreg Roach ); 247f01ab4acSGreg Roach static::assertSame( 248062377eeSGreg Roach '<span dir="ltr">foo -123,456.789 bar</span>', 249062377eeSGreg Roach RightToLeftSupport::spanLtrRtl('foo -123,456.789 bar') 250062377eeSGreg Roach ); 251f01ab4acSGreg Roach static::assertSame( 252062377eeSGreg Roach '<span dir="rtl">אבג 123,456.789 דהו</span>', 253062377eeSGreg Roach RightToLeftSupport::spanLtrRtl('אבג 123,456.789 דהו') 254062377eeSGreg Roach ); 255f01ab4acSGreg Roach static::assertSame( 256062377eeSGreg Roach '<span dir="rtl">אבג +123,456.789 דהו</span>', 257062377eeSGreg Roach RightToLeftSupport::spanLtrRtl('אבג +123,456.789 דהו') 258062377eeSGreg Roach ); 259f01ab4acSGreg Roach static::assertSame( 260062377eeSGreg Roach '<span dir="rtl">אבג -123,456.789 דהו</span>', 261062377eeSGreg Roach RightToLeftSupport::spanLtrRtl('אבג -123,456.789 דהו') 262062377eeSGreg Roach ); 263062377eeSGreg Roach 264062377eeSGreg Roach I18N::init('he', true); 265f01ab4acSGreg Roach static::assertSame( 266062377eeSGreg Roach '<span dir="ltr">foo 123,456.789 bar</span>', 267062377eeSGreg Roach RightToLeftSupport::spanLtrRtl('foo 123,456.789 bar') 268062377eeSGreg Roach ); 269f01ab4acSGreg Roach static::assertSame( 270062377eeSGreg Roach '<span dir="ltr">foo +123,456.789 bar</span>', 271062377eeSGreg Roach RightToLeftSupport::spanLtrRtl('foo +123,456.789 bar') 272062377eeSGreg Roach ); 273f01ab4acSGreg Roach static::assertSame( 274062377eeSGreg Roach '<span dir="ltr">foo -123,456.789 bar</span>', 275062377eeSGreg Roach RightToLeftSupport::spanLtrRtl('foo -123,456.789 bar') 276062377eeSGreg Roach ); 277f01ab4acSGreg Roach static::assertSame( 278062377eeSGreg Roach '<span dir="rtl">אבג 123,456.789 דהו</span>', 279062377eeSGreg Roach RightToLeftSupport::spanLtrRtl('אבג 123,456.789 דהו') 280062377eeSGreg Roach ); 281f01ab4acSGreg Roach static::assertSame( 282062377eeSGreg Roach '<span dir="rtl">אבג +123,456.789 דהו</span>', 283062377eeSGreg Roach RightToLeftSupport::spanLtrRtl('אבג +123,456.789 דהו') 284062377eeSGreg Roach ); 285f01ab4acSGreg Roach static::assertSame( 286062377eeSGreg Roach '<span dir="rtl">אבג -123,456.789 דהו</span>', 287062377eeSGreg Roach RightToLeftSupport::spanLtrRtl('אבג -123,456.789 דהו') 288062377eeSGreg Roach ); 289062377eeSGreg Roach } 290062377eeSGreg Roach 291062377eeSGreg Roach public function testParentheses(): void 292062377eeSGreg Roach { 293062377eeSGreg Roach I18N::init('en-US', true); 294f01ab4acSGreg Roach static::assertSame( 295062377eeSGreg Roach '<span dir="ltr">foo (bar)</span>', 296062377eeSGreg Roach RightToLeftSupport::spanLtrRtl('foo (bar)') 297062377eeSGreg Roach ); 298f01ab4acSGreg Roach static::assertSame( 299062377eeSGreg Roach '<span dir="ltr">foo </span><span dir="rtl">(אבג)</span>', 300062377eeSGreg Roach RightToLeftSupport::spanLtrRtl('foo (אבג)') 301062377eeSGreg Roach ); 302f01ab4acSGreg Roach static::assertSame( 303062377eeSGreg Roach '<span dir="rtl">אבג</span><span dir="ltr"> (bar)</span>', 304062377eeSGreg Roach RightToLeftSupport::spanLtrRtl('אבג (bar)') 305062377eeSGreg Roach ); 306f01ab4acSGreg Roach static::assertSame( 307062377eeSGreg Roach '<span dir="rtl">אבג (דהו)</span>', 308062377eeSGreg Roach RightToLeftSupport::spanLtrRtl('אבג (דהו)') 309062377eeSGreg Roach ); 310062377eeSGreg Roach 311062377eeSGreg Roach I18N::init('he', true); 312f01ab4acSGreg Roach static::assertSame( 313062377eeSGreg Roach '<span dir="ltr">foo (bar)</span>', 314062377eeSGreg Roach RightToLeftSupport::spanLtrRtl('foo (bar)') 315062377eeSGreg Roach ); 316f01ab4acSGreg Roach static::assertSame( 317062377eeSGreg Roach '<span dir="ltr">foo </span><span dir="rtl">(אבג)</span>', 318062377eeSGreg Roach RightToLeftSupport::spanLtrRtl('foo (אבג)') 319062377eeSGreg Roach ); 320f01ab4acSGreg Roach static::assertSame( 321062377eeSGreg Roach '<span dir="rtl">אבג </span><span dir="ltr">(bar)</span>', 322062377eeSGreg Roach RightToLeftSupport::spanLtrRtl('אבג (bar)') 323062377eeSGreg Roach ); 324f01ab4acSGreg Roach static::assertSame( 325062377eeSGreg Roach '<span dir="rtl">אבג (דהו)</span>', 326062377eeSGreg Roach RightToLeftSupport::spanLtrRtl('אבג (דהו)') 327062377eeSGreg Roach ); 328062377eeSGreg Roach } 329062377eeSGreg Roach 330062377eeSGreg Roach public function testUnescapedHtml(): void 331062377eeSGreg Roach { 332062377eeSGreg Roach I18N::init('en-US', true); 333f01ab4acSGreg Roach static::assertSame( 334062377eeSGreg Roach '<span dir="ltr">>foo<</span>', 3356e60786aSGreg Roach RightToLeftSupport::spanLtrRtl('>foo<') 336062377eeSGreg Roach ); 337f01ab4acSGreg Roach static::assertSame( 338062377eeSGreg Roach '<span dir="ltr">></span><span dir="rtl">אבג<</span>', 3396e60786aSGreg Roach RightToLeftSupport::spanLtrRtl('>אבג<') 340062377eeSGreg Roach ); 341062377eeSGreg Roach 342062377eeSGreg Roach I18N::init('he', true); 343f01ab4acSGreg Roach static::assertSame( 344062377eeSGreg Roach '<span dir="rtl">></span><span dir="ltr">foo<</span>', 3456e60786aSGreg Roach RightToLeftSupport::spanLtrRtl('>foo<') 346062377eeSGreg Roach ); 347f01ab4acSGreg Roach static::assertSame( 348062377eeSGreg Roach '<span dir="rtl">>אבג<</span>', 3496e60786aSGreg Roach RightToLeftSupport::spanLtrRtl('>אבג<') 350062377eeSGreg Roach ); 351062377eeSGreg Roach } 352062377eeSGreg Roach 353062377eeSGreg Roach public function testBreakInNumber(): void 354062377eeSGreg Roach { 355062377eeSGreg Roach I18N::init('en-US', true); 356f01ab4acSGreg Roach static::assertSame( 357062377eeSGreg Roach '<span dir="ltr">123</span><br><span dir="ltr">456</span>', 3586e60786aSGreg Roach RightToLeftSupport::spanLtrRtl('123<br>456') 359062377eeSGreg Roach ); 360062377eeSGreg Roach 361062377eeSGreg Roach I18N::init('he', true); 362f01ab4acSGreg Roach static::assertSame( 363062377eeSGreg Roach '<span dir="rtl">123</span><br><span dir="rtl">456</span>', 3646e60786aSGreg Roach RightToLeftSupport::spanLtrRtl('123<br>456') 365062377eeSGreg Roach ); 3665183874fSGreg Roach } 3675183874fSGreg Roach} 368