‪TYPO3CMS  ‪main
LinktypeRegistryTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PHPUnit\Framework\Attributes\Test;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
26 final class ‪LinktypeRegistryTest extends UnitTestCase
27 {
28  #[Test]
29  public function ‪registrationRequiresInterface(): void
30  {
31  $linktypes = [
32  new class () {},
33  $this->‪getLinkType('valid-identifier'),
34  ];
35 
36  $linkTypeRegistry = new ‪LinktypeRegistry($linktypes);
37 
38  self::assertNotNull($linkTypeRegistry->getLinktype('valid-identifier'));
39  self::assertCount(1, $linkTypeRegistry->getLinktypes());
40  self::assertEquals(['valid-identifier'], $linkTypeRegistry->getIdentifiers());
41  }
42 
43  #[Test]
45  {
46  $linktypes = [
47  $this->‪getLinkType(),
48  ];
49 
50  $this->expectException(\InvalidArgumentException::class);
51  $this->expectExceptionCode(1644932383);
52 
53  new ‪LinktypeRegistry($linktypes);
54  }
55 
56  #[Test]
58  {
59  $linktypes = [
60  $this->‪getLinkType('duplicate'),
61  $this->‪getLinkType('duplicate'),
62  ];
63 
64  $this->expectException(\InvalidArgumentException::class);
65  $this->expectExceptionCode(1644932384);
66 
67  new ‪LinktypeRegistry($linktypes);
68  }
69 
70  protected function ‪getLinkType(string ‪$identifier = ''): ‪LinktypeInterface
71  {
72  return new class (‪$identifier) implements ‪LinktypeInterface {
73  private string ‪$identifier;
74  public function __construct(string ‪$identifier)
75  {
76  $this->identifier = ‪$identifier;
77  }
78  public function getIdentifier(): string
79  {
80  return ‪$this->identifier;
81  }
82  public function checkLink(string ‪$url, array $softRefEntry, ‪LinkAnalyzer $reference): bool
83  {
84  return true;
85  }
86  public function setAdditionalConfig(array $config): void {}
87  public function fetchType(array $value, string $type, string $key): string
88  {
89  return '';
90  }
91  public function getErrorParams(): array
92  {
93  return [];
94  }
95  public function getBrokenUrl(array $row): string
96  {
97  return '';
98  }
99  public function getErrorMessage(array $errorParams): string
100  {
101  return '';
102  }
103  };
104  }
105 }
‪TYPO3\CMS\Linkvalidator\Tests\Unit\Linktype\LinktypeRegistryTest\getLinkType
‪getLinkType(string $identifier='')
Definition: LinktypeRegistryTest.php:70
‪TYPO3\CMS\Linkvalidator\Tests\Unit\Linktype\LinktypeRegistryTest\registrationThrowsExceptionOnDuplicateIdentifier
‪registrationThrowsExceptionOnDuplicateIdentifier()
Definition: LinktypeRegistryTest.php:57
‪TYPO3\CMS\Linkvalidator\Linktype\LinktypeInterface
Definition: LinktypeInterface.php:26
‪TYPO3\CMS\Linkvalidator\Tests\Unit\Linktype
Definition: ExternalLinktypeTest.php:18
‪TYPO3\CMS\Linkvalidator\Tests\Unit\Linktype\LinktypeRegistryTest\registrationThrowsExceptionOnEmptyIdentifier
‪registrationThrowsExceptionOnEmptyIdentifier()
Definition: LinktypeRegistryTest.php:44
‪TYPO3\CMS\Linkvalidator\Tests\Unit\Linktype\LinktypeRegistryTest\registrationRequiresInterface
‪registrationRequiresInterface()
Definition: LinktypeRegistryTest.php:29
‪TYPO3\CMS\Webhooks\Message\$url
‪identifier readonly UriInterface $url
Definition: LoginErrorOccurredMessage.php:36
‪TYPO3\CMS\Linkvalidator\Linktype\LinktypeRegistry
Definition: LinktypeRegistry.php:27
‪TYPO3\CMS\Webhooks\Message\$identifier
‪identifier readonly string $identifier
Definition: FileAddedMessage.php:37
‪TYPO3\CMS\Linkvalidator\Tests\Unit\Linktype\LinktypeRegistryTest
Definition: LinktypeRegistryTest.php:27