TYPO3 CMS  TYPO3_8-7
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 
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 
52  protected $adminRepository;
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 
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 }
static makeInstance($className,... $constructorArguments)