‪TYPO3CMS  11.5
IsDirtyTest.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 
24 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
25 
26 class ‪IsDirtyTest extends FunctionalTestCase
27 {
28  protected ‪$testExtensionsToLoad = ['typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example'];
29 
33  protected ‪$blogRepository;
34 
38  protected ‪$adminRepository;
39 
43  protected function ‪setUp(): void
44  {
45  parent::setUp();
46 
47  $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/pages.xml');
48  $this->importCSVDataSet(__DIR__ . '/../Persistence/Fixtures/blogs.csv');
49  $this->importCSVDataSet(__DIR__ . '/../Persistence/Fixtures/posts.csv');
50  $this->importCSVDataSet(__DIR__ . '/../Persistence/Fixtures/post-post-mm.csv');
51  $this->importCSVDataSet(__DIR__ . '/../Persistence/Fixtures/tags.csv');
52  $this->importCSVDataSet(__DIR__ . '/../Persistence/Fixtures/tags-mm.csv');
53  $this->importCSVDataSet(__DIR__ . '/../Persistence/Fixtures/post-tag-mm.csv');
54  $this->importCSVDataSet(__DIR__ . '/../Persistence/Fixtures/persons.csv');
55  $this->importCSVDataSet(__DIR__ . '/../Persistence/Fixtures/fe_users.csv');
56  $this->importCSVDataSet(__DIR__ . '/../Persistence/Fixtures/fe_groups.csv');
57 
58  $this->blogRepository = $this->get(BlogRepository::class);
59  $this->adminRepository = $this->get(AdministratorRepository::class);
60  }
61 
65  public function ‪objectFetchedFromDbIsNotDirty(): void
66  {
67  $blog = $this->blogRepository->findByUid(3);
68  self::assertFalse($blog->_isDirty());
69  }
70 
75  {
76  $blog = $this->blogRepository->findByUid(3);
77  self::assertInstanceOf(LazyLoadingProxy::class, $blog->getAdministrator()); // precondition
78 
79  $admin = $this->adminRepository->findByUid(3);
80  self::assertInstanceOf(Administrator::class, $admin); // precondition
81 
82  $blog->setAdministrator($admin);
83  self::assertFalse($blog->_isDirty());
84  }
85 
90  {
91  $blog = $this->blogRepository->findByUid(3);
92  self::assertInstanceOf(LazyLoadingProxy::class, $blog->getAdministrator()); //precondition
93 
94  $blog->setAdministrator(new Administrator());
95  self::assertTrue($blog->_isDirty());
96  }
97 
102  {
103  $blog = $this->blogRepository->findByUid(3);
104  $lazyLoadingProxy = $blog->getAdministrator();
105  self::assertInstanceOf(LazyLoadingProxy::class, $lazyLoadingProxy); //precondition
106 
107  $admin = $this->adminRepository->findByUid(3);
108  self::assertInstanceOf(Administrator::class, $admin); // precondition
109 
110  $blog->setAdministrator($admin);
111  $blog->_memorizeCleanState();
112 
113  $blog->_setProperty('administrator', $lazyLoadingProxy);
114  self::assertFalse($blog->_isDirty());
115  }
116 
121  {
122  $blogOne = $this->blogRepository->findByUid(3);
123  self::assertInstanceOf(LazyLoadingProxy::class, $blogOne->getAdministrator()); //precondition
124 
125  $blogTwo = $this->blogRepository->findByUid(2);
126  self::assertInstanceOf(LazyLoadingProxy::class, $blogTwo->getAdministrator()); //precondition
127 
128  $blogOne->_setProperty('administrator', $blogTwo->getAdministrator());
129  self::assertTrue($blogOne->_isDirty());
130 
131  $this->blogRepository->update($blogOne);
132 
133  $updatedBlogOne = $this->blogRepository->findByUid(3);
134  self::assertSame($updatedBlogOne->getAdministrator()->getUid(), $blogTwo->getAdministrator()->getUid());
135  }
136 
140  public function ‪undefinedPropertyIsAlwaysClean(): void
141  {
142  $blogOne = $this->blogRepository->findByUid(1);
143  self::assertFalse($blogOne->_isDirty('undefinedProperty'));
144  }
145 }
‪ExtbaseTeam\BlogExample\Domain\Repository\BlogRepository
Definition: BlogRepository.php:27
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\IsDirtyTest\realInstanceReplacedByLazyLoadingProxyIsNotDirty
‪realInstanceReplacedByLazyLoadingProxyIsNotDirty()
Definition: IsDirtyTest.php:99
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\IsDirtyTest\lazyLoadingProxyByWrongLazyLoadingProxyIsDirtyAndUpdated
‪lazyLoadingProxyByWrongLazyLoadingProxyIsDirtyAndUpdated()
Definition: IsDirtyTest.php:118
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\IsDirtyTest\lazyLoadingProxyReplacedByRealInstanceIsNotDirty
‪lazyLoadingProxyReplacedByRealInstanceIsNotDirty()
Definition: IsDirtyTest.php:72
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\IsDirtyTest\$blogRepository
‪BlogRepository $blogRepository
Definition: IsDirtyTest.php:32
‪ExtbaseTeam\BlogExample\Domain\Repository\AdministratorRepository
Definition: AdministratorRepository.php:25
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\IsDirtyTest
Definition: IsDirtyTest.php:27
‪ExtbaseTeam\BlogExample\Domain\Model\Administrator
Definition: Administrator.php:28
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\IsDirtyTest\setUp
‪setUp()
Definition: IsDirtyTest.php:41
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\IsDirtyTest\$adminRepository
‪AdministratorRepository $adminRepository
Definition: IsDirtyTest.php:36
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\IsDirtyTest\lazyLoadingProxyReplacedByWrongInstanceIsDirty
‪lazyLoadingProxyReplacedByWrongInstanceIsDirty()
Definition: IsDirtyTest.php:87
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence
Definition: AddTest.php:18
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\IsDirtyTest\undefinedPropertyIsAlwaysClean
‪undefinedPropertyIsAlwaysClean()
Definition: IsDirtyTest.php:138
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\IsDirtyTest\objectFetchedFromDbIsNotDirty
‪objectFetchedFromDbIsNotDirty()
Definition: IsDirtyTest.php:63
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy
Definition: LazyLoadingProxy.php:29
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\IsDirtyTest\$testExtensionsToLoad
‪$testExtensionsToLoad
Definition: IsDirtyTest.php:28