‪TYPO3CMS  ‪main
EditRecordViewHelperTest.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;
25 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
26 use TYPO3Fluid\Fluid\View\TemplateView;
27 
28 final class ‪EditRecordViewHelperTest extends FunctionalTestCase
29 {
30  protected bool ‪$initializeDatabase = false;
31 
33 
34  public function ‪setUp(): void
35  {
36  parent::setUp();
37  $this->request = (new ‪ServerRequest('https://www.example.com/'))
38  ->withAttribute('applicationType', ‪SystemEnvironmentBuilder::REQUESTTYPE_BE)
39  ->withAttribute('normalizedParams', new ‪NormalizedParams([], [], '', ''));
40  }
41 
42  #[Test]
44  {
45  $context = $this->get(RenderingContextFactory::class)->create();
46  $context->setRequest($this->request);
47  $context->getViewHelperResolver()->addNamespace('be', 'TYPO3\\CMS\\Backend\\ViewHelpers');
48  $context->getTemplatePaths()->setTemplateSource('<be:uri.editRecord uid="42" table="a_table">edit record a_table:42</be:uri.editRecord>');
49  $result = urldecode((new TemplateView($context))->render());
50 
51  self::assertStringContainsString('/typo3/record/edit', $result);
52  self::assertStringContainsString('edit[a_table][42]=edit', $result);
53  }
54 
55  #[Test]
57  {
58  $context = $this->get(RenderingContextFactory::class)->create();
59  $context->setRequest($this->request);
60  $context->getViewHelperResolver()->addNamespace('be', 'TYPO3\\CMS\\Backend\\ViewHelpers');
61  $context->getTemplatePaths()->setTemplateSource('{be:uri.editRecord(uid: 21, table: \'b_table\')}');
62  $result = urldecode((new TemplateView($context))->render());
63 
64  self::assertStringContainsString('/typo3/record/edit', $result);
65  self::assertStringContainsString('edit[b_table][21]=edit', $result);
66  }
67 
68  #[Test]
70  {
71  $context = $this->get(RenderingContextFactory::class)->create();
72  $context->getViewHelperResolver()->addNamespace('be', 'TYPO3\\CMS\\Backend\\ViewHelpers');
73  $context->getTemplatePaths()->setTemplateSource('<be:uri.editRecord uid="43" table="c_table" returnUrl="foo/bar">edit record c_table:43</be:uri.editRecord>');
74  $result = urldecode((new TemplateView($context))->render());
75 
76  self::assertStringContainsString('/typo3/record/edit', $result);
77  self::assertStringContainsString('edit[c_table][43]=edit', $result);
78  self::assertStringContainsString('returnUrl=foo/bar', $result);
79  }
80 
81  #[Test]
82  public function ‪renderReturnsValidLinkWithField(): void
83  {
84  $context = $this->get(RenderingContextFactory::class)->create();
85  $context->setRequest($this->request);
86  $context->getViewHelperResolver()->addNamespace('be', 'TYPO3\\CMS\\Backend\\ViewHelpers');
87  $context->getTemplatePaths()->setTemplateSource('<be:uri.editRecord uid="43" table="c_table" fields="canonical_url">edit record c_table:43</be:uri.editRecord>');
88  $result = urldecode((new TemplateView($context))->render());
89 
90  self::assertStringContainsString('/typo3/record/edit', $result);
91  self::assertStringContainsString('edit[c_table][43]=edit', $result);
92  self::assertStringContainsString('columnsOnly=canonical_url', $result);
93  }
94 
95  #[Test]
96  public function ‪renderReturnsValidLinkWithFields(): void
97  {
98  $context = $this->get(RenderingContextFactory::class)->create();
99  $context->setRequest($this->request);
100  $context->getViewHelperResolver()->addNamespace('be', 'TYPO3\\CMS\\Backend\\ViewHelpers');
101  $context->getTemplatePaths()->setTemplateSource('<be:uri.editRecord uid="43" table="c_table" fields="canonical_url,title">edit record c_table:43</be:uri.editRecord>');
102  $result = urldecode((new TemplateView($context))->render());
103 
104  self::assertStringContainsString('/typo3/record/edit', $result);
105  self::assertStringContainsString('edit[c_table][43]=edit', $result);
106  self::assertStringContainsString('columnsOnly=canonical_url,title', $result);
107  }
108 
109  #[Test]
111  {
112  $this->expectException(\InvalidArgumentException::class);
113  $this->expectExceptionCode(1526128259);
114 
115  $context = $this->get(RenderingContextFactory::class)->create();
116  $context->getViewHelperResolver()->addNamespace('be', 'TYPO3\\CMS\\Backend\\ViewHelpers');
117  $context->getTemplatePaths()->setTemplateSource('<be:uri.editRecord uid="-42" table="c_table">edit record c_table:-42</be:uri.editRecord>');
118  (new TemplateView($context))->render();
119  }
120 }
‪TYPO3\CMS\Backend\Tests\Functional\ViewHelpers\Uri\EditRecordViewHelperTest
Definition: EditRecordViewHelperTest.php:29
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder
Definition: SystemEnvironmentBuilder.php:41
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder\REQUESTTYPE_BE
‪const REQUESTTYPE_BE
Definition: SystemEnvironmentBuilder.php:45
‪TYPO3\CMS\Backend\Tests\Functional\ViewHelpers\Uri\EditRecordViewHelperTest\renderReturnsValidLinkWithField
‪renderReturnsValidLinkWithField()
Definition: EditRecordViewHelperTest.php:82
‪TYPO3\CMS\Backend\Tests\Functional\ViewHelpers\Uri\EditRecordViewHelperTest\setUp
‪setUp()
Definition: EditRecordViewHelperTest.php:34
‪TYPO3\CMS\Backend\Tests\Functional\ViewHelpers\Uri\EditRecordViewHelperTest\$initializeDatabase
‪bool $initializeDatabase
Definition: EditRecordViewHelperTest.php:30
‪TYPO3\CMS\Backend\Tests\Functional\ViewHelpers\Uri\EditRecordViewHelperTest\renderReturnsValidLinkInExplicitFormat
‪renderReturnsValidLinkInExplicitFormat()
Definition: EditRecordViewHelperTest.php:43
‪TYPO3\CMS\Backend\Tests\Functional\ViewHelpers\Uri
Definition: EditRecordViewHelperTest.php:18
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:39
‪TYPO3\CMS\Backend\Tests\Functional\ViewHelpers\Uri\EditRecordViewHelperTest\renderThrowsExceptionForInvalidUidArgument
‪renderThrowsExceptionForInvalidUidArgument()
Definition: EditRecordViewHelperTest.php:110
‪TYPO3\CMS\Backend\Tests\Functional\ViewHelpers\Uri\EditRecordViewHelperTest\renderReturnsValidLinkInInlineFormat
‪renderReturnsValidLinkInInlineFormat()
Definition: EditRecordViewHelperTest.php:56
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContextFactory
Definition: RenderingContextFactory.php:51
‪TYPO3\CMS\Backend\Tests\Functional\ViewHelpers\Uri\EditRecordViewHelperTest\renderReturnsValidLinkWithReturnUrl
‪renderReturnsValidLinkWithReturnUrl()
Definition: EditRecordViewHelperTest.php:69
‪TYPO3\CMS\Core\Http\NormalizedParams
Definition: NormalizedParams.php:38
‪TYPO3\CMS\Backend\Tests\Functional\ViewHelpers\Uri\EditRecordViewHelperTest\$request
‪ServerRequest $request
Definition: EditRecordViewHelperTest.php:32
‪TYPO3\CMS\Backend\Tests\Functional\ViewHelpers\Uri\EditRecordViewHelperTest\renderReturnsValidLinkWithFields
‪renderReturnsValidLinkWithFields()
Definition: EditRecordViewHelperTest.php:96