‪TYPO3CMS  10.4
AddTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
25 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
26 
27 class ‪AddTest extends FunctionalTestCase
28 {
32  protected ‪$persistentManager;
33 
37  protected ‪$testExtensionsToLoad = ['typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example'];
38 
42  protected ‪$coreExtensionsToLoad = ['extbase', 'fluid'];
43 
47  protected ‪$objectManager;
48 
52  protected ‪$blogRepository;
53 
57  protected function ‪setUp(): void
58  {
59  parent::setUp();
60 
61  $this->objectManager = GeneralUtility::makeInstance(ObjectManager::class);
62  $this->persistentManager = $this->objectManager->get(PersistenceManager::class);
63  $this->blogRepository = $this->objectManager->get(BlogRepository::class);
64  ‪$GLOBALS['BE_USER'] = new ‪BackendUserAuthentication();
65  }
66 
70  public function ‪addSimpleObjectTest()
71  {
72  $newBlogTitle = 'aDi1oogh';
73  $newBlog = $this->objectManager->get(Blog::class);
74  $newBlog->setTitle($newBlogTitle);
75 
77  $this->blogRepository->add($newBlog);
78  $this->persistentManager->persistAll();
79 
80  $queryBuilder = (new ‪ConnectionPool())->getQueryBuilderForTable('tx_blogexample_domain_model_blog');
81  $queryBuilder->getRestrictions()
82  ->removeAll();
83  $newBlogCount = $queryBuilder
84  ->count('*')
85  ->from('tx_blogexample_domain_model_blog')
86  ->where(
87  $queryBuilder->expr()->eq(
88  'title',
89  $queryBuilder->createNamedParameter($newBlogTitle, \PDO::PARAM_STR)
90  )
91  )
92  ->execute()
93  ->fetchColumn(0);
94  self::assertEquals(1, $newBlogCount);
95  }
96 
100  public function ‪addObjectSetsDefaultLanguageTest()
101  {
102  $newBlogTitle = 'aDi1oogh';
103  $newBlog = $this->objectManager->get(Blog::class);
104  $newBlog->setTitle($newBlogTitle);
105 
107  $this->blogRepository->add($newBlog);
108  $this->persistentManager->persistAll();
109 
110  $queryBuilder = (new ‪ConnectionPool())->getQueryBuilderForTable('tx_blogexample_domain_model_blog');
111  $queryBuilder->getRestrictions()
112  ->removeAll();
113  $newBlogRecord = $queryBuilder
114  ->select('*')
115  ->from('tx_blogexample_domain_model_blog')
116  ->where(
117  $queryBuilder->expr()->eq(
118  'title',
119  $queryBuilder->createNamedParameter($newBlogTitle, \PDO::PARAM_STR)
120  )
121  )
122  ->execute()
123  ->fetch();
124  self::assertEquals(0, $newBlogRecord['sys_language_uid']);
125  }
126 
130  public function ‪addObjectSetsDefinedLanguageTest()
131  {
132  $newBlogTitle = 'aDi1oogh';
133  $newBlog = $this->objectManager->get(Blog::class);
134  $newBlog->setTitle($newBlogTitle);
135  $newBlog->_setProperty('_languageUid', -1);
136 
138  $this->blogRepository->add($newBlog);
139  $this->persistentManager->persistAll();
140 
141  $queryBuilder = (new ‪ConnectionPool())->getQueryBuilderForTable('tx_blogexample_domain_model_blog');
142  $queryBuilder->getRestrictions()
143  ->removeAll();
144  $newBlogRecord = $queryBuilder
145  ->select('*')
146  ->from('tx_blogexample_domain_model_blog')
147  ->where(
148  $queryBuilder->expr()->eq(
149  'title',
150  $queryBuilder->createNamedParameter($newBlogTitle, \PDO::PARAM_STR)
151  )
152  )
153  ->execute()
154  ->fetch();
155  self::assertEquals(-1, $newBlogRecord['sys_language_uid']);
156  }
157 
162  {
163  $newBlogTitle = 'aDi1oogh';
164  $newBlog = $this->objectManager->get(Blog::class);
165  $newBlog->setTitle($newBlogTitle);
166  $newBlog->setSubtitle('subtitle');
167 
169  $this->blogRepository->add($newBlog);
170  $this->persistentManager->persistAll();
171 
172  // make sure null can be set explicitly
173  $insertedBlog = $this->blogRepository->findByUid(1);
174  $insertedBlog->setSubtitle(null);
175  $this->blogRepository->update($insertedBlog);
176  $this->persistentManager->persistAll();
177 
178  $queryBuilder = (new ‪ConnectionPool())->getQueryBuilderForTable('tx_blogexample_domain_model_blog');
179  $queryBuilder->getRestrictions()
180  ->removeAll();
181  $newBlogRecord = $queryBuilder
182  ->select('*')
183  ->from('tx_blogexample_domain_model_blog')
184  ->where(
185  $queryBuilder->expr()->eq(
186  'subtitle',
187  $queryBuilder->createNamedParameter($newBlogTitle, \PDO::PARAM_STR)
188  )
189  )
190  ->execute()
191  ->fetch();
192  self::assertNull($newBlogRecord['subtitle']);
193  }
194 }
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\AddTest\$persistentManager
‪TYPO3 CMS Extbase Persistence Generic PersistenceManager $persistentManager
Definition: AddTest.php:31
‪ExtbaseTeam\BlogExample\Domain\Repository\BlogRepository
Definition: BlogRepository.php:25
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\AddTest\$objectManager
‪TYPO3 CMS Extbase Object ObjectManagerInterface $objectManager
Definition: AddTest.php:43
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\AddTest\addObjectSetsDefaultLanguageTest
‪addObjectSetsDefaultLanguageTest()
Definition: AddTest.php:95
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\AddTest\setUp
‪setUp()
Definition: AddTest.php:52
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager
Definition: PersistenceManager.php:29
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\AddTest\$coreExtensionsToLoad
‪array $coreExtensionsToLoad
Definition: AddTest.php:39
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\AddTest\addObjectSetsDefinedLanguageTest
‪addObjectSetsDefinedLanguageTest()
Definition: AddTest.php:125
‪ExtbaseTeam\BlogExample\Domain\Model\Blog
Definition: Blog.php:27
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence
Definition: AddTest.php:16
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\AddTest\$blogRepository
‪TYPO3 CMS Extbase Persistence Repository $blogRepository
Definition: AddTest.php:47
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\AddTest\addSimpleObjectTest
‪addSimpleObjectTest()
Definition: AddTest.php:65
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\AddTest\$testExtensionsToLoad
‪array $testExtensionsToLoad
Definition: AddTest.php:35
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\AddTest
Definition: AddTest.php:28
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:28
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\AddTest\addObjectSetsNullAsNullForSimpleTypes
‪addObjectSetsNullAsNullForSimpleTypes()
Definition: AddTest.php:156