TYPO3 CMS  TYPO3_8-7
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 
19 
20 class AddTest extends \TYPO3\TestingFramework\Core\Functional\FunctionalTestCase
21 {
25  protected $persistentManager;
26 
30  protected $testExtensionsToLoad = ['typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example'];
31 
35  protected $coreExtensionsToLoad = ['extbase', 'fluid'];
36 
40  protected $objectManager;
41 
45  protected $blogRepository;
46 
50  protected function setUp()
51  {
52  parent::setUp();
53 
54  $this->objectManager = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
55  $this->persistentManager = $this->objectManager->get(\TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager::class);
56  $this->blogRepository = $this->objectManager->get(\ExtbaseTeam\BlogExample\Domain\Repository\BlogRepository::class);
57  }
58 
62  public function addSimpleObjectTest()
63  {
64  $newBlogTitle = 'aDi1oogh';
65  $newBlog = $this->objectManager->get(\ExtbaseTeam\BlogExample\Domain\Model\Blog::class);
66  $newBlog->setTitle($newBlogTitle);
67 
69  $this->blogRepository->add($newBlog);
70  $this->persistentManager->persistAll();
71 
72  $queryBuilder = (new ConnectionPool())->getQueryBuilderForTable('tx_blogexample_domain_model_blog');
73  $queryBuilder->getRestrictions()
74  ->removeAll();
75  $newBlogCount = $queryBuilder
76  ->count('*')
77  ->from('tx_blogexample_domain_model_blog')
78  ->where(
79  $queryBuilder->expr()->eq(
80  'title',
81  $queryBuilder->createNamedParameter($newBlogTitle, \PDO::PARAM_STR)
82  )
83  )
84  ->execute()
85  ->fetchColumn(0);
86  $this->assertEquals(1, $newBlogCount);
87  }
88 
92  public function addObjectSetsDefaultLanguageTest()
93  {
94  $newBlogTitle = 'aDi1oogh';
95  $newBlog = $this->objectManager->get(\ExtbaseTeam\BlogExample\Domain\Model\Blog::class);
96  $newBlog->setTitle($newBlogTitle);
97 
99  $this->blogRepository->add($newBlog);
100  $this->persistentManager->persistAll();
101 
102  $queryBuilder = (new ConnectionPool())->getQueryBuilderForTable('tx_blogexample_domain_model_blog');
103  $queryBuilder->getRestrictions()
104  ->removeAll();
105  $newBlogRecord = $queryBuilder
106  ->select('*')
107  ->from('tx_blogexample_domain_model_blog')
108  ->where(
109  $queryBuilder->expr()->eq(
110  'title',
111  $queryBuilder->createNamedParameter($newBlogTitle, \PDO::PARAM_STR)
112  )
113  )
114  ->execute()
115  ->fetch();
116  $this->assertEquals(0, $newBlogRecord['sys_language_uid']);
117  }
118 
122  public function addObjectSetsDefinedLanguageTest()
123  {
124  $newBlogTitle = 'aDi1oogh';
125  $newBlog = $this->objectManager->get(\ExtbaseTeam\BlogExample\Domain\Model\Blog::class);
126  $newBlog->setTitle($newBlogTitle);
127  $newBlog->_setProperty('_languageUid', -1);
128 
130  $this->blogRepository->add($newBlog);
131  $this->persistentManager->persistAll();
132 
133  $queryBuilder = (new ConnectionPool())->getQueryBuilderForTable('tx_blogexample_domain_model_blog');
134  $queryBuilder->getRestrictions()
135  ->removeAll();
136  $newBlogRecord = $queryBuilder
137  ->select('*')
138  ->from('tx_blogexample_domain_model_blog')
139  ->where(
140  $queryBuilder->expr()->eq(
141  'title',
142  $queryBuilder->createNamedParameter($newBlogTitle, \PDO::PARAM_STR)
143  )
144  )
145  ->execute()
146  ->fetch();
147  $this->assertEquals(-1, $newBlogRecord['sys_language_uid']);
148  }
149 
153  public function addObjectSetsNullAsNullForSimpleTypes()
154  {
155  $newBlogTitle = 'aDi1oogh';
156  $newBlog = $this->objectManager->get(\ExtbaseTeam\BlogExample\Domain\Model\Blog::class);
157  $newBlog->setTitle($newBlogTitle);
158  $newBlog->setSubtitle('subtitle');
159 
161  $this->blogRepository->add($newBlog);
162  $this->persistentManager->persistAll();
163 
164  // make sure null can be set explicitly
165  $insertedBlog = $this->blogRepository->findByUid(1);
166  $insertedBlog->setSubtitle(null);
167  $this->blogRepository->update($insertedBlog);
168  $this->persistentManager->persistAll();
169 
170  $queryBuilder = (new ConnectionPool())->getQueryBuilderForTable('tx_blogexample_domain_model_blog');
171  $queryBuilder->getRestrictions()
172  ->removeAll();
173  $newBlogRecord = $queryBuilder
174  ->select('*')
175  ->from('tx_blogexample_domain_model_blog')
176  ->where(
177  $queryBuilder->expr()->eq(
178  'subtitle',
179  $queryBuilder->createNamedParameter($newBlogTitle, \PDO::PARAM_STR)
180  )
181  )
182  ->execute()
183  ->fetch();
184  $this->assertNull($newBlogRecord['subtitle']);
185  }
186 }
static makeInstance($className,... $constructorArguments)