TYPO3 CMS  TYPO3_7-6
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 
18 
20 {
24  protected $persistentManager;
25 
29  protected $testExtensionsToLoad = ['typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example'];
30 
34  protected $coreExtensionsToLoad = ['extbase', 'fluid'];
35 
39  protected $objectManager;
40 
44  protected $blogRepository;
45 
49  protected function setUp()
50  {
51  parent::setUp();
52 
53  $this->objectManager = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
54  $this->persistentManager = $this->objectManager->get(\TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager::class);
55  $this->blogRepository = $this->objectManager->get(\ExtbaseTeam\BlogExample\Domain\Repository\BlogRepository::class);
56  }
57 
61  public function addSimpleObjectTest()
62  {
63  $newBlogTitle = 'aDi1oogh';
64  $newBlog = $this->objectManager->get(\ExtbaseTeam\BlogExample\Domain\Model\Blog::class);
65  $newBlog->setTitle($newBlogTitle);
66 
68  $this->blogRepository->add($newBlog);
69  $this->persistentManager->persistAll();
70 
71  $newBlogCount = $this->getDatabaseConnection()->exec_SELECTcountRows('*', 'tx_blogexample_domain_model_blog', 'title = \'' . $newBlogTitle . '\'');
72  $this->assertSame(1, $newBlogCount);
73  }
74 
78  public function addObjectSetsDefaultLanguageTest()
79  {
80  $newBlogTitle = 'aDi1oogh';
81  $newBlog = $this->objectManager->get(\ExtbaseTeam\BlogExample\Domain\Model\Blog::class);
82  $newBlog->setTitle($newBlogTitle);
83 
85  $this->blogRepository->add($newBlog);
86  $this->persistentManager->persistAll();
87 
88  $newBlogRecord = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('*', 'tx_blogexample_domain_model_blog', 'title = \'' . $newBlogTitle . '\'');
89  $this->assertEquals(0, $newBlogRecord['sys_language_uid']);
90  }
91 
95  public function addObjectSetsDefinedLanguageTest()
96  {
97  $newBlogTitle = 'aDi1oogh';
98  $newBlog = $this->objectManager->get(\ExtbaseTeam\BlogExample\Domain\Model\Blog::class);
99  $newBlog->setTitle($newBlogTitle);
100  $newBlog->_setProperty('_languageUid', -1);
101 
103  $this->blogRepository->add($newBlog);
104  $this->persistentManager->persistAll();
105 
106  $newBlogRecord = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('*', 'tx_blogexample_domain_model_blog', 'title = \'' . $newBlogTitle . '\'');
107  $this->assertEquals(-1, $newBlogRecord['sys_language_uid']);
108  }
109 }