TYPO3 CMS  TYPO3_6-2
AddTest.php
Go to the documentation of this file.
1 <?php
3 
19 
21 
25  protected $persistentManager;
26 
30  protected $testExtensionsToLoad = array('typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example');
31 
35  protected $coreExtensionsToLoad = array('extbase', 'fluid');
36 
40  protected $objectManager;
41 
45  protected $blogRepository;
46 
50  public function setUp() {
51  parent::setUp();
52 
53  $this->objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
54  $this->persistentManager = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager');
55  $this->blogRepository = $this->objectManager->get('ExtbaseTeam\\BlogExample\\Domain\\Repository\\BlogRepository');
56  }
57 
61  public function addSimpleObjectTest() {
62  $newBlogTitle = 'aDi1oogh';
63  $newBlog = $this->objectManager->get('ExtbaseTeam\\BlogExample\\Domain\\Model\\Blog');
64  $newBlog->setTitle($newBlogTitle);
65 
67  $this->blogRepository->add($newBlog);
68  $this->persistentManager->persistAll();
69 
70  $newBlogCount = $this->getDatabaseConnection()->exec_SELECTcountRows('*', 'tx_blogexample_domain_model_blog', 'title = \'' . $newBlogTitle . '\'');
71  $this->assertSame(1, $newBlogCount);
72  }
73 
77  public function addObjectSetsDefaultLanguageTest() {
78  $newBlogTitle = 'aDi1oogh';
79  $newBlog = $this->objectManager->get('ExtbaseTeam\\BlogExample\\Domain\\Model\\Blog');
80  $newBlog->setTitle($newBlogTitle);
81 
83  $this->blogRepository->add($newBlog);
84  $this->persistentManager->persistAll();
85 
86  $newBlogRecord = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('*', 'tx_blogexample_domain_model_blog', 'title = \'' . $newBlogTitle . '\'');
87  $this->assertEquals(0, $newBlogRecord['sys_language_uid']);
88  }
89 
93  public function addObjectSetsDefinedLanguageTest() {
94  $newBlogTitle = 'aDi1oogh';
95  $newBlog = $this->objectManager->get('ExtbaseTeam\\BlogExample\\Domain\\Model\\Blog');
96  $newBlog->setTitle($newBlogTitle);
97  $newBlog->_setProperty('_languageUid', -1);
98 
100  $this->blogRepository->add($newBlog);
101  $this->persistentManager->persistAll();
102 
103  $newBlogRecord = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('*', 'tx_blogexample_domain_model_blog', 'title = \'' . $newBlogTitle . '\'');
104  $this->assertEquals(-1, $newBlogRecord['sys_language_uid']);
105  }
106 
107 }