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