‪TYPO3CMS  ‪main
PreviewUriBuilderTest.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;
21 use Psr\EventDispatcher\EventDispatcherInterface;
26 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
27 
28 final class ‪PreviewUriBuilderTest extends UnitTestCase
29 {
30  protected bool ‪$resetSingletonInstances = true;
31 
32  #[Test]
33  public function ‪attributesContainAlternativeUri(): void
34  {
35  $eventDispatcher = new class () implements EventDispatcherInterface {
36  public function dispatch(object $event)
37  {
38  if ($event instanceof ‪BeforePagePreviewUriGeneratedEvent) {
39  $alternativeUri = 'https://typo3.org/about/typo3-the-cms/the-history-of-typo3/#section';
40  $event->setPreviewUri(new ‪Uri($alternativeUri));
41  }
42  return $event;
43  }
44  };
45  GeneralUtility::addInstance(EventDispatcherInterface::class, $eventDispatcher);
46  $subject = ‪PreviewUriBuilder::create(0)->withModuleLoading(false);
47  $attributes = $subject->buildDispatcherAttributes([‪PreviewUriBuilder::OPTION_SWITCH_FOCUS => false]);
48 
49  self::assertSame(
50  [
51  'data-dispatch-action' => 'TYPO3.WindowManager.localOpen',
52  'data-dispatch-args' => '["https:\/\/typo3.org\/about\/typo3-the-cms\/the-history-of-typo3\/#section",false,"newTYPO3frontendWindow"]',
53  ],
54  $attributes
55  );
56  }
57 }
‪TYPO3\CMS\Backend\Tests\Unit\Routing\PreviewUriBuilderTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: PreviewUriBuilderTest.php:30
‪TYPO3\CMS\Core\Http\Uri
Definition: Uri.php:30
‪TYPO3\CMS\Backend\Routing\PreviewUriBuilder\create
‪static static create(int $pageId)
Definition: PreviewUriBuilder.php:65
‪TYPO3\CMS\Backend\Routing\Event\BeforePagePreviewUriGeneratedEvent
Definition: BeforePagePreviewUriGeneratedEvent.php:29
‪TYPO3\CMS\Backend\Tests\Unit\Routing\PreviewUriBuilderTest\attributesContainAlternativeUri
‪attributesContainAlternativeUri()
Definition: PreviewUriBuilderTest.php:33
‪TYPO3\CMS\Backend\Routing\PreviewUriBuilder
Definition: PreviewUriBuilder.php:44
‪TYPO3\CMS\Backend\Tests\Unit\Routing
Definition: PreviewUriBuilderTest.php:18
‪TYPO3\CMS\Backend\Routing\PreviewUriBuilder\OPTION_SWITCH_FOCUS
‪const OPTION_SWITCH_FOCUS
Definition: PreviewUriBuilder.php:45
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Backend\Tests\Unit\Routing\PreviewUriBuilderTest
Definition: PreviewUriBuilderTest.php:29