37 protected $testExtensionsToLoad = array(
'typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example');
52 $this->importDataSet(ORIGINAL_ROOT .
'typo3/sysext/core/Tests/Functional/Fixtures/pages.xml');
53 $this->importDataSet(ORIGINAL_ROOT .
'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/blogs.xml');
54 $this->importDataSet(ORIGINAL_ROOT .
'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/posts.xml');
55 $this->importDataSet(ORIGINAL_ROOT .
'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/tags.xml');
56 $this->importDataSet(ORIGINAL_ROOT .
'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/post-tag-mm.xml');
57 $this->importDataSet(ORIGINAL_ROOT .
'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/categories.xml');
58 $this->importDataSet(ORIGINAL_ROOT .
'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/category-mm.xml');
61 $this->persistentManager = $this->objectManager->get(
'TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager');
63 $blogRepository = $this->objectManager->get(
'ExtbaseTeam\\BlogExample\\Domain\\Repository\\BlogRepository');
64 $this->blog = $blogRepository->findByUid(1);
73 $countPosts = $this->
getDatabaseConnection()->exec_SELECTcountRows(
'*',
'tx_blogexample_domain_model_post');
74 $this->assertSame($this->numberOfRecordsInFixture, $countPosts);
76 $newPostTitle =
'sdufhisdhuf';
77 $newPost = $this->objectManager->get(
'ExtbaseTeam\\BlogExample\\Domain\\Model\\Post');
78 $newPost->setBlog($this->blog);
79 $newPost->setTitle($newPostTitle);
80 $newPost->setContent(
'Bla Bla Bla');
82 $this->blog->addPost($newPost);
83 $this->updateAndPersistBlog();
85 $countPosts = $this->
getDatabaseConnection()->exec_SELECTcountRows(
'*',
'tx_blogexample_domain_model_post');
86 $this->assertSame(($this->numberOfRecordsInFixture + 1), $countPosts);
88 $post = $this->
getDatabaseConnection()->exec_SELECTgetSingleRow(
'title,sorting',
'tx_blogexample_domain_model_post',
'blog =' . $this->blog->getUid(),
'',
'sorting DESC');
89 $this->assertSame($newPostTitle, $post[
'title']);
90 $this->assertSame((
string)($this->numberOfRecordsInFixture), $post[
'sorting']);
99 $countPosts = $this->
getDatabaseConnection()->exec_SELECTcountRows(
'*',
'tx_blogexample_domain_model_post');
100 $this->assertSame($this->numberOfRecordsInFixture, $countPosts);
102 $post = $this->
getDatabaseConnection()->exec_SELECTgetSingleRow(
'sorting',
'tx_blogexample_domain_model_post',
'blog =' . $this->blog->getUid(),
'',
'sorting DESC');
103 $this->assertEquals(10, $post[
'sorting']);
105 $posts = $this->blog->getPosts();
106 $postsArray = $posts->toArray();
107 $latestPost = array_pop($postsArray);
109 $this->assertEquals(10, $latestPost->getUid());
111 $this->blog->removePost($latestPost);
112 $this->updateAndPersistBlog();
114 $countPosts = $this->
getDatabaseConnection()->exec_SELECTcountRows(
'*',
'tx_blogexample_domain_model_post',
'deleted=0');
115 $this->assertEquals(($this->numberOfRecordsInFixture - 1), $countPosts);
117 $post = $this->
getDatabaseConnection()->exec_SELECTgetSingleRow(
'uid',
'tx_blogexample_domain_model_post',
'uid =' . $latestPost->getUid() .
' AND deleted=0');
118 $this->assertSame(NULL, $post[
'uid']);
120 $post = $this->
getDatabaseConnection()->exec_SELECTgetSingleRow(
'title,sorting',
'tx_blogexample_domain_model_post',
'blog =' . $this->blog->getUid(),
'',
'sorting DESC');
121 $this->assertSame(
'Post9', $post[
'title']);
122 $this->assertSame(
'9', $post[
'sorting']);
131 $countPosts = $this->
getDatabaseConnection()->exec_SELECTcountRows(
'*',
'tx_blogexample_domain_model_post');
132 $this->assertSame($this->numberOfRecordsInFixture, $countPosts);
134 $posts = clone $this->blog->getPosts();
135 $this->blog->getPosts()->removeAll($posts);
137 $newPostTitle =
'INSERTED POST at position 6';
138 foreach ($posts as $post) {
139 $this->blog->addPost($post);
141 $newPost = $this->objectManager->get(
'ExtbaseTeam\\BlogExample\\Domain\\Model\\Post');
142 $newPost->setBlog($this->blog);
143 $newPost->setTitle($newPostTitle);
144 $newPost->setContent(
'Bla Bla Bla');
145 $this->blog->addPost($newPost);
149 $this->updateAndPersistBlog();
151 $countPosts = $this->
getDatabaseConnection()->exec_SELECTcountRows(
'*',
'tx_blogexample_domain_model_post',
'deleted=0');
152 $this->assertSame(($this->numberOfRecordsInFixture + 1), $countPosts);
155 $post = $this->
getDatabaseConnection()->exec_SELECTgetSingleRow(
'title,sorting',
'tx_blogexample_domain_model_post',
'blog =' . $this->blog->getUid(),
'',
'sorting DESC');
156 $this->assertSame(
'Post10', $post[
'title']);
157 $this->assertSame(
'11', $post[
'sorting']);
160 $post = $this->
getDatabaseConnection()->exec_SELECTgetSingleRow(
'title,sorting',
'tx_blogexample_domain_model_post',
'uid=' . ($this->numberOfRecordsInFixture + 1));
161 $this->assertSame($newPostTitle, $post[
'title']);
162 $this->assertSame(
'6', $post[
'sorting']);
171 $countPosts = $this->
getDatabaseConnection()->exec_SELECTcountRows(
'*',
'tx_blogexample_domain_model_post');
172 $this->assertSame($this->numberOfRecordsInFixture, $countPosts);
174 $posts = clone $this->blog->getPosts();
176 foreach ($posts as $post) {
178 $this->blog->removePost($post);
182 $this->updateAndPersistBlog();
184 $countPosts = $this->
getDatabaseConnection()->exec_SELECTcountRows(
'*',
'tx_blogexample_domain_model_post',
'deleted=0');
185 $this->assertSame(($this->numberOfRecordsInFixture - 1), $countPosts);
187 $post = $this->
getDatabaseConnection()->exec_SELECTgetSingleRow(
'title,sorting',
'tx_blogexample_domain_model_post',
'blog ='.$this->blog->getUid(),
'',
'sorting DESC');
188 $this->assertSame(
'Post10', $post[
'title']);
189 $this->assertSame(
'10', $post[
'sorting']);
198 $countPosts = $this->
getDatabaseConnection()->exec_SELECTcountRows(
'*',
'tx_blogexample_domain_model_post');
199 $this->assertSame($this->numberOfRecordsInFixture, $countPosts);
201 $posts = clone $this->blog->getPosts();
202 $postsArray = $posts->toArray();
203 $latestPost = array_pop($postsArray);
205 $this->blog->getPosts()->removeAll($posts);
207 $postCount = $posts->count();
208 foreach ($posts as $post) {
209 if ($counter != ($postCount - 1)) {
210 $this->blog->addPost($post);
213 $latestPost->setTitle(
'MOVED POST ' . $latestPost->getTitle());
214 $this->blog->addPost($latestPost);
218 $this->updateAndPersistBlog();
220 $countPosts = $this->
getDatabaseConnection()->exec_SELECTcountRows(
'*',
'tx_blogexample_domain_model_post',
'deleted=0');
221 $this->assertSame($this->numberOfRecordsInFixture, $countPosts);
223 $post = $this->
getDatabaseConnection()->exec_SELECTgetSingleRow(
'title,sorting',
'tx_blogexample_domain_model_post',
'blog ='.$this->blog->getUid(),
'',
'sorting DESC');
224 $this->assertSame(
'Post9', $post[
'title']);
225 $this->assertSame(
'10', $post[
'sorting']);
227 $post = $this->
getDatabaseConnection()->exec_SELECTgetSingleRow(
'title,uid',
'tx_blogexample_domain_model_post',
'blog ='.$this->blog->getUid().
' AND sorting=6');
228 $this->assertSame(
'MOVED POST Post10', $post[
'title']);
229 $this->assertSame(
'10', $post[
'uid']);
238 $count = $this->
getDatabaseConnection()->exec_SELECTcountRows(
'*',
'tx_blogexample_domain_model_tag');
239 $this->assertSame(10, $count);
241 $newTagTitle =
'sdufhisdhuf';
242 $newTag = $this->objectManager->get(
'ExtbaseTeam\\BlogExample\\Domain\\Model\\Tag', $newTagTitle);
244 $postRepository = $this->objectManager->get(
'ExtbaseTeam\\BlogExample\\Domain\\Repository\\PostRepository');
245 $post = $postRepository->findByUid(1);
246 $post->addTag($newTag);
248 $postRepository->update($post);
249 $this->persistentManager->persistAll();
251 $count = $this->
getDatabaseConnection()->exec_SELECTcountRows(
'*',
'tx_blogexample_domain_model_tag');
252 $this->assertSame(11, $count);
254 $tag = $this->
getDatabaseConnection()->exec_SELECTgetSingleRow(
'uid_foreign',
'tx_blogexample_post_tag_mm',
'uid_local ='.$post->getUid(),
'',
'sorting DESC');
255 $this->assertSame(
'11', $tag[
'uid_foreign']);
265 $count = $this->
getDatabaseConnection()->exec_SELECTcountRows(
'*',
'tx_blogexample_domain_model_tag');
266 $this->assertSame(10, $count);
268 $postRepository = $this->objectManager->get(
'ExtbaseTeam\\BlogExample\\Domain\\Repository\\PostRepository');
269 $post = $postRepository->findByUid(1);
270 $tags = $post->getTags();
271 $tagsArray = $tags->toArray();
272 $latestTag = array_pop($tagsArray);
274 $this->assertEquals(10, $latestTag->getUid());
276 $post->removeTag($latestTag);
278 $postRepository->update($post);
279 $this->persistentManager->persistAll();
281 $countPosts = $this->
getDatabaseConnection()->exec_SELECTcountRows(
'*',
'tx_blogexample_domain_model_tag',
'deleted=0' );
282 $this->assertEquals(10, $countPosts);
284 $tag = $this->
getDatabaseConnection()->exec_SELECTgetSingleRow(
'uid_foreign',
'tx_blogexample_post_tag_mm',
'uid_local ='.$post->getUid(),
'',
'sorting DESC');
285 $this->assertSame(
'9', $tag[
'uid_foreign']);
287 $tag = $this->
getDatabaseConnection()->exec_SELECTgetSingleRow(
'uid_foreign',
'tx_blogexample_post_tag_mm',
'uid_local ='.$post->getUid().
' AND uid_foreign='.$latestTag->getUid());
288 $this->assertSame(NULL, $tag[
'uid_foreign']);
297 $countTags = $this->
getDatabaseConnection()->exec_SELECTcountRows(
'*',
'tx_blogexample_post_tag_mm',
'uid_local=1');
298 $this->assertSame(10, $countTags);
300 $postRepository = $this->objectManager->get(
'ExtbaseTeam\\BlogExample\\Domain\\Repository\\PostRepository');
301 $post = $postRepository->findByUid(1);
302 $tags = clone $post->getTags();
306 foreach ($tags as $tag) {
309 $newTag = $this->objectManager->get(
'ExtbaseTeam\\BlogExample\\Domain\\Model\\Tag',
'INSERTED TAG at position 6 : ' . strftime(
''));
310 $post->addTag($newTag);
315 $postRepository->update($post);
316 $this->persistentManager->persistAll();
318 $countTags = $this->
getDatabaseConnection()->exec_SELECTcountRows(
'*',
'tx_blogexample_post_tag_mm',
'uid_local=1');
319 $this->assertSame(11, $countTags);
321 $tag = $this->
getDatabaseConnection()->exec_SELECTgetSingleRow(
'uid_foreign',
'tx_blogexample_post_tag_mm',
'uid_local ='.$post->getUid(),
'',
'sorting DESC');
322 $this->assertSame(
'10', $tag[
'uid_foreign']);
324 $tag = $this->
getDatabaseConnection()->exec_SELECTgetSingleRow(
'uid_foreign',
'tx_blogexample_post_tag_mm',
'uid_local ='.$post->getUid().
' AND sorting=6');
325 $this->assertSame(
'11', $tag[
'uid_foreign']);
335 $countTags = $this->
getDatabaseConnection()->exec_SELECTcountRows(
'*',
'tx_blogexample_post_tag_mm',
'uid_local=1');
336 $this->assertSame(10, $countTags);
338 $postRepository = $this->objectManager->get(
'ExtbaseTeam\\BlogExample\\Domain\\Repository\\PostRepository');
339 $post = $postRepository->findByUid(1);
340 $tags = clone $post->getTags();
342 foreach ($tags as $tag) {
344 $post->removeTag($tag);
349 $postRepository->update($post);
350 $this->persistentManager->persistAll();
352 $countTags = $this->
getDatabaseConnection()->exec_SELECTcountRows(
'*',
'tx_blogexample_post_tag_mm',
'uid_local=1');
353 $this->assertSame(9, $countTags);
355 $tag = $this->
getDatabaseConnection()->exec_SELECTgetSingleRow(
'uid_foreign,sorting',
'tx_blogexample_post_tag_mm',
'uid_local ='.$post->getUid(),
'',
'sorting DESC');
356 $this->assertSame(
'10', $tag[
'uid_foreign']);
357 $this->assertSame(
'10', $tag[
'sorting']);
359 $tag = $this->
getDatabaseConnection()->exec_SELECTgetSingleRow(
'uid_foreign',
'tx_blogexample_post_tag_mm',
'uid_local ='.$post->getUid().
' AND sorting=5');
360 $this->assertSame(NULL, $tag[
'uid_foreign']);
369 $countTags = $this->
getDatabaseConnection()->exec_SELECTcountRows(
'*',
'tx_blogexample_post_tag_mm',
'uid_local=1');
370 $this->assertSame(10, $countTags);
372 $postRepository = $this->objectManager->get(
'ExtbaseTeam\\BlogExample\\Domain\\Repository\\PostRepository');
373 $post = $postRepository->findByUid(1);
374 $tags = clone $post->getTags();
375 $tagsArray = $tags->toArray();
376 $latestTag = array_pop($tagsArray);
377 $post->removeTag($latestTag);
381 $tagCount = $tags->count();
382 foreach ($tags as $tag) {
383 if ($counter != $tagCount) {
387 $post->addTag($latestTag);
391 $post->addTag($latestTag);
393 $postRepository->update($post);
394 $this->persistentManager->persistAll();
396 $countTags = $this->
getDatabaseConnection()->exec_SELECTcountRows(
'*',
'tx_blogexample_post_tag_mm',
'uid_local=1');
397 $this->assertSame(10, $countTags);
399 $tag = $this->
getDatabaseConnection()->exec_SELECTgetSingleRow(
'uid_foreign,sorting',
'tx_blogexample_post_tag_mm',
'uid_local ='.$post->getUid(),
'',
'sorting DESC');
400 $this->assertSame(
'9', $tag[
'uid_foreign']);
401 $this->assertSame(
'10', $tag[
'sorting']);
404 $tag = $this->
getDatabaseConnection()->exec_SELECTgetSingleRow(
'uid_foreign',
'tx_blogexample_post_tag_mm',
'uid_local ='.$post->getUid().
' AND sorting='.$sorting);
405 $this->assertSame(
'10', $tag[
'uid_foreign']);
414 $rawPost = $this->
getDatabaseConnection()->exec_SELECTgetSingleRow(
'*',
'tx_blogexample_domain_model_post',
'uid=1');
416 $postRepository = $this->objectManager->get(
'ExtbaseTeam\\BlogExample\\Domain\\Repository\\PostRepository');
417 $post = $postRepository->findByUid(1);
418 $post->setTitle(
"newTitle");
420 $postRepository->update($post);
421 $this->persistentManager->persistAll();
423 $rawPost2 = $this->
getDatabaseConnection()->exec_SELECTgetSingleRow(
'*',
'tx_blogexample_domain_model_post',
'uid=1');
424 $this->assertTrue($rawPost2[
'tstamp'] > $rawPost[
'tstamp']);
432 public function mmRelationWithoutMatchFieldIsResolved() {
434 $postRepository = $this->objectManager->get(
'ExtbaseTeam\\BlogExample\\Domain\\Repository\\PostRepository');
435 $posts = $postRepository->findByTagAndBlog(
'Tag2', $this->blog);
436 $this->assertSame(1, count($posts));
442 public function mmRelationWithMatchFieldIsResolvedFromLocalSide() {
443 $countCategories = $this->
getDatabaseConnection()->exec_SELECTcountRows(
'*',
'sys_category_record_mm',
'uid_foreign=1 AND tablenames="tx_blogexample_domain_model_post" AND fieldname="categories"');
444 $this->assertSame(3, $countCategories);
447 $postRepository = $this->objectManager->get(
'ExtbaseTeam\\BlogExample\\Domain\\Repository\\PostRepository');
448 $post = $postRepository->findByUid(1);
449 $this->assertSame(3, count($post->getCategories()));
457 public function mmRelationWithMatchFieldIsResolvedFromForeignSide() {
459 $postRepository = $this->objectManager->get(
'ExtbaseTeam\\BlogExample\\Domain\\Repository\\PostRepository');
460 $posts = $postRepository->findByCategory(1);
461 $this->assertSame(2, count($posts));
463 $posts = $postRepository->findByCategory(4);
464 $this->assertSame(0, count($posts));
471 $countCategories = $this->
getDatabaseConnection()->exec_SELECTcountRows(
'*',
'sys_category_record_mm',
'uid_foreign=1 AND tablenames="tx_blogexample_domain_model_post" AND fieldname="categories"');
472 $this->assertSame(3, $countCategories);
474 $postRepository = $this->objectManager->get(
'ExtbaseTeam\\BlogExample\\Domain\\Repository\\PostRepository');
475 $post = $postRepository->findByUid(1);
477 $newCategory = $this->objectManager->get(
'\\TYPO3\\CMS\\Extbase\\Domain\\Model\\Category');
478 $newCategory->setTitle(
'New Category');
480 $post->addCategory($newCategory);
482 $postRepository->update($post);
483 $this->persistentManager->persistAll();
487 'sys_category_record_mm',
488 'uid_foreign=1 AND tablenames="tx_blogexample_domain_model_post" AND fieldname="categories"' 490 $this->assertSame(4, $countCategories);
498 public function adjustingMmRelationWithTablesnameAndFieldnameFieldDoNotTouchOtherRelations() {
500 $postRepository = $this->objectManager->get(
'ExtbaseTeam\\BlogExample\\Domain\\Repository\\PostRepository');
502 $post = $postRepository->findByUid(1);
504 foreach ($post->getCategories() as $category) {
505 $post->removeCategory($category);
506 $post->addCategory($category);
509 $postRepository->update($post);
510 $this->persistentManager->persistAll();
515 'sys_category_record_mm',
516 'tablenames = "tx_blogexample_domain_model_blog" 517 AND fieldname = "categories" 518 AND uid_foreign = ' . $this->blog->getUid() .
'' 521 $this->assertSame($this->blog->getCategories()->count(), $newBlogCategoryCount);
527 protected function updateAndPersistBlog() {
529 $blogRepository = $this->objectManager->get(
'ExtbaseTeam\\BlogExample\\Domain\\Repository\\BlogRepository');
530 $blogRepository->update($this->blog);
531 $this->persistentManager->persistAll();
movePostFromEndToTheMiddle()
mmRelationWithMatchFieldIsCreatedFromLocalSide()
removeMiddlePostFromBlog()
static makeInstance($className)
removeMiddleTagFromPost()
timestampFieldIsUpdatedOnPostSave()
attachPostToBlogAtTheEnd()
addPostToBlogInTheMiddle()
moveTagFromEndToTheMiddle()
addTagToPostInTheMiddle()
$numberOfRecordsInFixture
attachTagToPostAtTheEnd()