‪TYPO3CMS  ‪main
HrefLangGeneratorTest.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\DataProvider;
21 use PHPUnit\Framework\Attributes\Test;
22 use PHPUnit\Framework\MockObject\MockObject;
23 use Psr\Http\Message\UriInterface;
28 use TYPO3\TestingFramework\Core\AccessibleObjectInterface;
29 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
30 
31 final class ‪HrefLangGeneratorTest extends UnitTestCase
32 {
33  protected MockObject&AccessibleObjectInterface&‪HrefLangGenerator ‪$subject;
34 
35  public function ‪setUp(): void
36  {
37  parent::setUp();
38 
39  $this->subject = $this->getAccessibleMock(
40  HrefLangGenerator::class,
41  null,
42  [
43  $this->getMockBuilder(ContentObjectRenderer::class)->disableOriginalConstructor()->getMock(),
44  $this->getMockBuilder(LanguageMenuProcessor::class)->disableOriginalConstructor()->getMock(),
45  ]
46  );
47  }
48 
49  public static function ‪urlPathWithoutHostDataProvider(): array
50  {
51  return [
52  [
53  '/',
54  ],
55  [
56  'example.com', // This can't be defined as a domain because it can also be a filename
57  ],
58  [
59  'filename.pdf',
60  ],
61  [
62  'example.com/filename.pdf',
63  ],
64  [
65  '/page-1/subpage-1',
66  ],
67  ];
68  }
69 
70  #[DataProvider('urlPathWithoutHostDataProvider')]
71  #[Test]
73  {
74  $mockUriInterface = $this->getMockBuilder(UriInterface::class)->getMock();
75  $mockSiteLanguage = $this->getMockBuilder(SiteLanguage::class)->disableOriginalConstructor()->getMock();
76  $mockSiteLanguage->expects(self::once())->method('getBase')->willReturn($mockUriInterface);
77  $this->subject->_call('getAbsoluteUrl', ‪$url, $mockSiteLanguage);
78  }
79 
80  public static function ‪urlPathWithHostDataProvider(): array
81  {
82  return [
83  [
84  '//example.com/filename.pdf',
85  ],
86  [
87  '//example.com',
88  ],
89  [
90  'https://example.com',
91  ],
92  [
93  'https://example.com/page-1/subpage-1',
94  ],
95  ];
96  }
97 
98  #[DataProvider('urlPathWithHostDataProvider')]
99  #[Test]
101  {
102  $mockUriInterface = $this->getMockBuilder(UriInterface::class)->getMock();
103  $mockSiteLanguage = $this->getMockBuilder(SiteLanguage::class)->disableOriginalConstructor()->getMock();
104  $mockSiteLanguage->expects(self::never())->method('getBase')->willReturn($mockUriInterface);
105  $this->subject->_call('getAbsoluteUrl', ‪$url, $mockSiteLanguage);
106  }
107 }
‪TYPO3\CMS\Seo\Tests\Unit\HrefLang\HrefLangGeneratorTest\$subject
‪MockObject &AccessibleObjectInterface &HrefLangGenerator $subject
Definition: HrefLangGeneratorTest.php:33
‪TYPO3\CMS\Seo\Tests\Unit\HrefLang\HrefLangGeneratorTest\setUp
‪setUp()
Definition: HrefLangGeneratorTest.php:35
‪TYPO3\CMS\Frontend\DataProcessing\LanguageMenuProcessor
Definition: LanguageMenuProcessor.php:47
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage
Definition: SiteLanguage.php:27
‪TYPO3\CMS\Seo\HrefLang\HrefLangGenerator
Definition: HrefLangGenerator.php:38
‪TYPO3\CMS\Seo\Tests\Unit\HrefLang\HrefLangGeneratorTest\urlPathWithoutHostDataProvider
‪static urlPathWithoutHostDataProvider()
Definition: HrefLangGeneratorTest.php:49
‪TYPO3\CMS\Webhooks\Message\$url
‪identifier readonly UriInterface $url
Definition: LoginErrorOccurredMessage.php:36
‪TYPO3\CMS\Seo\Tests\Unit\HrefLang\HrefLangGeneratorTest\urlPathWithHostDataProvider
‪static urlPathWithHostDataProvider()
Definition: HrefLangGeneratorTest.php:80
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:102
‪TYPO3\CMS\Seo\Tests\Unit\HrefLang\HrefLangGeneratorTest
Definition: HrefLangGeneratorTest.php:32
‪TYPO3\CMS\Seo\Tests\Unit\HrefLang
Definition: HrefLangGeneratorTest.php:18
‪TYPO3\CMS\Seo\Tests\Unit\HrefLang\HrefLangGeneratorTest\checkIfSiteLanguageGetBaseIsCalledForUrlsWithoutHost
‪checkIfSiteLanguageGetBaseIsCalledForUrlsWithoutHost(string $url)
Definition: HrefLangGeneratorTest.php:72
‪TYPO3\CMS\Seo\Tests\Unit\HrefLang\HrefLangGeneratorTest\checkIfSiteLanguageGetBaseIsNotCalledForUrlsWithHost
‪checkIfSiteLanguageGetBaseIsNotCalledForUrlsWithHost(string $url)
Definition: HrefLangGeneratorTest.php:100