‪TYPO3CMS  9.5
IsDirtyTest.php
Go to the documentation of this file.
1 <?php
2 
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 
24 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
25 
26 class ‪IsDirtyTest extends FunctionalTestCase
27 {
28 
32  protected ‪$testExtensionsToLoad = ['typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example'];
33 
37  protected ‪$coreExtensionsToLoad = ['extbase', 'fluid'];
38 
42  protected ‪$objectManager;
43 
47  protected ‪$blogRepository;
48 
53 
57  protected function ‪setUp()
58  {
59  parent::setUp();
60 
61  $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/pages.xml');
62  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/blogs.xml');
63  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/posts.xml');
64  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/post-post-mm.xml');
65  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/tags.xml');
66  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/tags-mm.xml');
67  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/post-tag-mm.xml');
68  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/persons.xml');
69  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/fe_users.xml');
70  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/fe_groups.xml');
71 
72  $this->objectManager = GeneralUtility::makeInstance(ObjectManager::class);
73  $this->blogRepository = $this->objectManager->get(BlogRepository::class);
74  $this->adminRepository = $this->objectManager->get(AdministratorRepository::class);
75  }
76 
80  public function ‪objectFetchedFromDbIsNotDirty()
81  {
82  $blog = $this->blogRepository->findByUid(3);
83  $this->assertFalse($blog->_isDirty());
84  }
85 
90  {
91  $blog = $this->blogRepository->findByUid(3);
92  $this->assertInstanceOf(LazyLoadingProxy::class, $blog->getAdministrator()); // precondition
93 
94  $admin = $this->adminRepository->findByUid(3);
95  $this->assertInstanceOf(Administrator::class, $admin); // precondition
96 
97  $blog->setAdministrator($admin);
98  $this->assertFalse($blog->_isDirty());
99  }
100 
105  {
106  $blog = $this->blogRepository->findByUid(3);
107  $this->assertInstanceOf(LazyLoadingProxy::class, $blog->getAdministrator()); //precondition
108 
109  $blog->setAdministrator(new ‪Administrator());
110  $this->assertTrue($blog->_isDirty());
111  }
112 
117  {
118  $blog = $this->blogRepository->findByUid(3);
119  $lazyLoadingProxy = $blog->getAdministrator();
120  $this->assertInstanceOf(LazyLoadingProxy::class, $lazyLoadingProxy); //precondition
121 
122  $admin = $this->adminRepository->findByUid(3);
123  $this->assertInstanceOf(Administrator::class, $admin); // precondition
124 
125  $blog->setAdministrator($admin);
126  $blog->_memorizeCleanState();
127 
128  $blog->_setProperty('administrator', $lazyLoadingProxy);
129  $this->assertFalse($blog->_isDirty());
130  }
131 
136  {
137  $blogOne = $this->blogRepository->findByUid(3);
138  $this->assertInstanceOf(LazyLoadingProxy::class, $blogOne->getAdministrator()); //precondition
139 
140  $blogTwo = $this->blogRepository->findByUid(2);
141  $this->assertInstanceOf(LazyLoadingProxy::class, $blogTwo->getAdministrator()); //precondition
142 
143  $blogOne->_setProperty('administrator', $blogTwo->getAdministrator());
144  $this->assertTrue($blogOne->_isDirty());
145 
146  $this->blogRepository->update($blogOne);
147 
148  $updatedBlogOne = $this->blogRepository->findByUid(3);
149  $this->assertSame($updatedBlogOne->getAdministrator()->getUid(), $blogTwo->getAdministrator()->getUid());
150  }
151 }
‪ExtbaseTeam\BlogExample\Domain\Repository\BlogRepository
Definition: BlogRepository.php:21
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\IsDirtyTest\$adminRepository
‪ExtbaseTeam BlogExample Domain Repository AdministratorRepository $adminRepository
Definition: IsDirtyTest.php:47
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\IsDirtyTest\realInstanceReplacedByLazyLoadingProxyIsNotDirty
‪realInstanceReplacedByLazyLoadingProxyIsNotDirty()
Definition: IsDirtyTest.php:111
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\IsDirtyTest\$blogRepository
‪ExtbaseTeam BlogExample Domain Repository BlogRepository $blogRepository
Definition: IsDirtyTest.php:43
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\IsDirtyTest\$objectManager
‪TYPO3 CMS Extbase Object ObjectManagerInterface $objectManager
Definition: IsDirtyTest.php:39
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\IsDirtyTest\lazyLoadingProxyByWrongLazyLoadingProxyIsDirtyAndUpdated
‪lazyLoadingProxyByWrongLazyLoadingProxyIsDirtyAndUpdated()
Definition: IsDirtyTest.php:130
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\IsDirtyTest\lazyLoadingProxyReplacedByRealInstanceIsNotDirty
‪lazyLoadingProxyReplacedByRealInstanceIsNotDirty()
Definition: IsDirtyTest.php:84
‪ExtbaseTeam\BlogExample\Domain\Repository\AdministratorRepository
Definition: AdministratorRepository.php:21
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\IsDirtyTest
Definition: IsDirtyTest.php:27
‪ExtbaseTeam\BlogExample\Domain\Model\Administrator
Definition: Administrator.php:22
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\IsDirtyTest\setUp
‪setUp()
Definition: IsDirtyTest.php:52
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\IsDirtyTest\lazyLoadingProxyReplacedByWrongInstanceIsDirty
‪lazyLoadingProxyReplacedByWrongInstanceIsDirty()
Definition: IsDirtyTest.php:99
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence
Definition: AddTest.php:2
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\IsDirtyTest\objectFetchedFromDbIsNotDirty
‪objectFetchedFromDbIsNotDirty()
Definition: IsDirtyTest.php:75
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy
Definition: LazyLoadingProxy.php:28
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\IsDirtyTest\$testExtensionsToLoad
‪array $testExtensionsToLoad
Definition: IsDirtyTest.php:31
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\IsDirtyTest\$coreExtensionsToLoad
‪array $coreExtensionsToLoad
Definition: IsDirtyTest.php:35
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:25