114e48043c1c2a5fc3901c2182b245bac21fd82b
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Functional / Persistence / AddTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Functional\Persistence;
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
17 use TYPO3\CMS\Core\Utility\GeneralUtility;
18
19 class AddTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase {
20
21 /**
22 * @var \TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager
23 */
24 protected $persistentManager;
25
26 /**
27 * @var array
28 */
29 protected $testExtensionsToLoad = array('typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example');
30
31 /**
32 * @var array
33 */
34 protected $coreExtensionsToLoad = array('extbase', 'fluid');
35
36 /**
37 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface The object manager
38 */
39 protected $objectManager;
40
41 /**
42 * @var \TYPO3\CMS\Extbase\Persistence\Repository
43 */
44 protected $blogRepository;
45
46 /**
47 * Sets up this test suite.
48 */
49 protected function setUp() {
50 parent::setUp();
51
52 $this->objectManager = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
53 $this->persistentManager = $this->objectManager->get(\TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager::class);
54 $this->blogRepository = $this->objectManager->get(\ExtbaseTeam\BlogExample\Domain\Repository\BlogRepository::class);
55 }
56
57 /**
58 * @test
59 */
60 public function addSimpleObjectTest() {
61 $newBlogTitle = 'aDi1oogh';
62 $newBlog = $this->objectManager->get(\ExtbaseTeam\BlogExample\Domain\Model\Blog::class);
63 $newBlog->setTitle($newBlogTitle);
64
65 /** @var \ExtbaseTeam\BlogExample\Domain\Repository\BlogRepository $blogRepository */
66 $this->blogRepository->add($newBlog);
67 $this->persistentManager->persistAll();
68
69 $newBlogCount = $this->getDatabaseConnection()->exec_SELECTcountRows('*', 'tx_blogexample_domain_model_blog', 'title = \'' . $newBlogTitle . '\'');
70 $this->assertSame(1, $newBlogCount);
71 }
72
73 }