diff --git a/typo3/sysext/frontend/Classes/Typolink/TelephoneLinkBuilder.php b/typo3/sysext/frontend/Classes/Typolink/TelephoneLinkBuilder.php index 6054d98940ce6320a814fec9de1e3c2738e95e6c..aa91307309e190ba0495286abb81ab3944486dce 100644 --- a/typo3/sysext/frontend/Classes/Typolink/TelephoneLinkBuilder.php +++ b/typo3/sysext/frontend/Classes/Typolink/TelephoneLinkBuilder.php @@ -24,6 +24,7 @@ class TelephoneLinkBuilder extends AbstractTypolinkBuilder { public function build(array &$linkDetails, string $linkText, string $target, array $conf): LinkResultInterface { + $linkText = $linkText ?: $linkDetails['telephone'] ?? ''; return (new LinkResult($linkDetails['type'], $linkDetails['typoLinkParameter']))->withLinkConfiguration($conf)->withLinkText($linkText); } } diff --git a/typo3/sysext/frontend/Tests/Unit/Typolink/TelephoneLinkBuilderTest.php b/typo3/sysext/frontend/Tests/Unit/Typolink/TelephoneLinkBuilderTest.php new file mode 100644 index 0000000000000000000000000000000000000000..7f9b8b30102a17cad4c9eb77b67d9411ae03aa0f --- /dev/null +++ b/typo3/sysext/frontend/Tests/Unit/Typolink/TelephoneLinkBuilderTest.php @@ -0,0 +1,74 @@ +<?php + +declare(strict_types=1); + +/* + * This file is part of the TYPO3 CMS project. + * + * It is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, either version 2 + * of the License, or any later version. + * + * For the full copyright and license information, please read the + * LICENSE.txt file that was distributed with this source code. + * + * The TYPO3 project - inspiring people to share! + */ + +namespace TYPO3\CMS\Frontend\Tests\Unit\Typolink; + +use PHPUnit\Framework\Attributes\Test; +use TYPO3\CMS\Frontend\Typolink\TelephoneLinkBuilder; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; + +final class TelephoneLinkBuilderTest extends UnitTestCase +{ + #[Test] + public function noLinkTextForMissingDetailAndNoLinkTextProvided(): void + { + $linkDetails = [ + 'type' => 'telephone', + 'typoLinkParameter' => 'tel:+49 221 4710 999', + ]; + $subject = $this->getAccessibleMock(TelephoneLinkBuilder::class, null, [], '', false); + $actualResult = $subject->build($linkDetails, '', '', []); + self::assertSame('', $actualResult->getLinkText()); + } + + #[Test] + public function respectsProvidedLinkText(): void + { + $linkDetails = [ + 'type' => 'telephone', + 'typoLinkParameter' => 'tel:+49 221 4710 999', + ]; + $subject = $this->getAccessibleMock(TelephoneLinkBuilder::class, null, [], '', false); + $actualResult = $subject->build($linkDetails, 'Phone number', '', []); + self::assertSame('Phone number', $actualResult->getLinkText()); + } + + #[Test] + public function fallsBackToPhoneNumberOnMissingLinkText(): void + { + $linkDetails = [ + 'type' => 'telephone', + 'typoLinkParameter' => 'tel:+49 221 4710 999', + 'telephone' => '+49 221 4710 999', + ]; + $subject = $this->getAccessibleMock(TelephoneLinkBuilder::class, null, [], '', false); + $actualResult = $subject->build($linkDetails, '', '', []); + self::assertSame('+49 221 4710 999', $actualResult->getLinkText()); + } + + #[Test] + public function respectsProvidedLinkParameter(): void + { + $linkDetails = [ + 'type' => 'telephone', + 'typoLinkParameter' => 'tel:+49 221 4710 999', + ]; + $subject = $this->getAccessibleMock(TelephoneLinkBuilder::class, null, [], '', false); + $actualResult = $subject->build($linkDetails, '', '', []); + self::assertSame('tel:+49 221 4710 999', $actualResult->getUrl()); + } +}