Skip to content

Commit

Permalink
[BUGFIX] Use telephone as fallback for link text
Browse files Browse the repository at this point in the history
Resolves: #102139
Releases: main, 12.4
Change-Id: I9eb3b759de4af5c322aedc96df169aa7c603add6
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/83427
Reviewed-by: Oliver Bartsch <bo@cedev.de>
Tested-by: Oliver Bartsch <bo@cedev.de>
Tested-by: core-ci <typo3@b13.com>
  • Loading branch information
paravista authored and o-ba committed Mar 13, 2024
1 parent 2709fb7 commit 3709afe
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
Expand Up @@ -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);
}
}
@@ -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());
}
}

0 comments on commit 3709afe

Please sign in to comment.