‪TYPO3CMS  11.5
LazyLoadingProxyTest.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 
25 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
26 
27 class ‪LazyLoadingProxyTest extends FunctionalTestCase
28 {
29  protected ‪$coreExtensionsToLoad = ['extbase'];
30  protected ‪$testExtensionsToLoad = ['typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example'];
31 
35  protected function ‪setUp(): void
36  {
37  parent::setUp();
38 
39  GeneralUtility::makeInstance(ConnectionPool::class)
40  ->getConnectionForTable('fe_users')
41  ->insert('fe_users', [
42  'uid' => 1,
43  'username' => 'Blog Admin',
44  'tx_extbase_type' => Administrator::class,
45  ]);
46  }
47 
51  public function ‪serializeAndUnserialize(): void
52  {
53  $blog = new ‪Blog();
54  $blog->_setProperty('administrator', new ‪LazyLoadingProxy($blog, 'administrator', 1));
55 
56  $serialized = serialize($blog->getAdministrator());
57 
58  self::assertFalse(str_contains($serialized, 'dataMapper'), 'Assert that serialized object string does not contain dataMapper');
59 
61  $administratorProxy = unserialize($serialized, ['allowed_classes' => true]);
62  self::assertInstanceOf(LazyLoadingProxy::class, $administratorProxy, 'Assert that $administratorProxy is an instance of LazyLoadingProxy');
63 
65  $administrator = $administratorProxy->_loadRealInstance();
66  self::assertInstanceOf(Administrator::class, $administrator, 'Assert that $administrator is an instance of Administrator');
67 
68  self::assertSame('Blog Admin', $administrator->getUsername());
69  }
70 }
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\LazyLoadingProxyTest\setUp
‪setUp()
Definition: LazyLoadingProxyTest.php:35
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\LazyLoadingProxyTest\$coreExtensionsToLoad
‪$coreExtensionsToLoad
Definition: LazyLoadingProxyTest.php:29
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\LazyLoadingProxyTest
Definition: LazyLoadingProxyTest.php:28
‪ExtbaseTeam\BlogExample\Domain\Model\Administrator
Definition: Administrator.php:28
‪ExtbaseTeam\BlogExample\Domain\Model\Blog
Definition: Blog.php:29
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence
Definition: AddTest.php:18
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\LazyLoadingProxyTest\serializeAndUnserialize
‪serializeAndUnserialize()
Definition: LazyLoadingProxyTest.php:51
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy
Definition: LazyLoadingProxy.php:29
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\LazyLoadingProxyTest\$testExtensionsToLoad
‪$testExtensionsToLoad
Definition: LazyLoadingProxyTest.php:30