TYPO3 CMS  TYPO3_6-2
InTest.php
Go to the documentation of this file.
1 <?php
3 
19 
21 
25  protected $blogRepository;
26 
30  protected $postRepository;
31 
35  protected $testExtensionsToLoad = array('typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example');
36 
40  protected $coreExtensionsToLoad = array('extbase', 'fluid');
41 
45  protected $objectManager;
46 
50  public function setUp() {
51  parent::setUp();
52 
53  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/core/Tests/Functional/Fixtures/pages.xml');
54  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/blogs.xml');
55  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/posts.xml');
56  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/tags.xml');
57  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/post-tag-mm.xml');
58 
59  $this->objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
60  $this->blogRepository = $this->objectManager->get('ExtbaseTeam\\BlogExample\\Domain\\Repository\\BlogRepository');
61  $this->postRepository = $this->objectManager->get('ExtbaseTeam\\BlogExample\\Domain\\Repository\\PostRepository');
62 
63  }
64 
69  $blog1 = $this->blogRepository->findByUid(1);
70  $blog2 = $this->blogRepository->findByUid(2);
71 
72  $inQuery = $this->postRepository->createQuery();
73 
74  $inQuery->matching(
75  $inQuery->in('blog', array($blog1, $blog2))
76  );
77 
78  $this->assertSame(11, $inQuery->count());
79  }
80 
85  $blog1 = $this->blogRepository->findByUid(1);
86  $blog2 = $this->blogRepository->findByUid(2);
87 
88  $inQuery = $this->postRepository->createQuery();
89 
90  $inQuery->matching(
91  $inQuery->in('blog', array($blog1, $blog2))
92  );
93 
94  $this->assertSame(11, $inQuery->count());
95 
96  $newInQuery = $this->postRepository->createQuery();
97 
98  $newInQuery->matching(
99  $newInQuery->in('blog', array($blog1))
100  );
101 
102  $this->assertSame(10, $newInQuery->count());
103  }
104 
109  $blog1 = $this->blogRepository->findByUid(1);
110  $blog2 = $this->blogRepository->findByUid(2);
111 
112  $objectStorage = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage');
113  $objectStorage->attach($blog1);
114  $objectStorage->attach($blog2);
115 
116  $inQuery = $this->postRepository->createQuery();
117 
118  $inQuery->matching(
119  $inQuery->in('blog', $objectStorage)
120  );
121 
122  $this->assertSame(11, $inQuery->count());
123  }
124 
129  $blog1 = $this->blogRepository->findByUid(1);
130  $blog2 = $this->blogRepository->findByUid(2);
131 
132  $objectStorage = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage');
133  $objectStorage->attach($blog1);
134  $objectStorage->attach($blog2);
135 
136  $inQuery = $this->postRepository->createQuery();
137 
138  $inQuery->matching(
139  $inQuery->in('blog', $objectStorage)
140  );
141 
142  $this->assertSame(11, $inQuery->count());
143 
144  $newObjectStorage = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage');
145  $newObjectStorage->attach($blog1);
146 
147  $newInQuery = $this->postRepository->createQuery();
148 
149  $newInQuery->matching(
150  $newInQuery->in('blog', $newObjectStorage)
151  );
152 
153  $this->assertSame(10, $newInQuery->count());
154  }
155 
160  $queryResult = $this->blogRepository->findAll();
161 
162  $inQuery = $this->postRepository->createQuery();
163 
164  $inQuery->matching(
165  $inQuery->in('blog', $queryResult)
166  );
167 
168  $this->assertSame(11, $inQuery->count());
169  }
170 
171 
176  $queryResult = $this->blogRepository->findAll();
177 
178  $inQuery = $this->postRepository->createQuery();
179 
180  $inQuery->matching(
181  $inQuery->in('blog', $queryResult)
182  );
183 
184  $this->assertSame(11, $inQuery->count());
185 
186  $newInQuery = $this->postRepository->createQuery();
187 
188  $newInQuery->matching(
189  $newInQuery->in('blog', $queryResult)
190  );
191 
192  $this->assertSame(11, $newInQuery->count());
193  }
194 
199  $blog = $this->blogRepository->findByUid(1);
200 
201  $this->assertInstanceOf(
202  '\TYPO3\CMS\Extbase\Persistence\Generic\LazyObjectStorage',
203  $blog->getPosts()
204  );
205 
206  $inQuery = $this->postRepository->createQuery();
207 
208  $inQuery->matching(
209  $inQuery->in('uid', $blog->getPosts())
210  );
211 
212  $this->assertSame(10, $inQuery->count());
213  }
214 
219  $blog = $this->blogRepository->findByUid(1);
220 
221  $this->assertInstanceOf(
222  '\TYPO3\CMS\Extbase\Persistence\Generic\LazyObjectStorage',
223  $blog->getPosts()
224  );
225 
226  $inQuery = $this->postRepository->createQuery();
227 
228  $inQuery->matching(
229  $inQuery->in('uid', $blog->getPosts())
230  );
231 
232  $this->assertSame(10, $inQuery->count());
233 
234 
235  $newInQuery = $this->postRepository->createQuery();
236 
237  $newInQuery->matching(
238  $newInQuery->in('uid', $blog->getPosts())
239  );
240 
241  $this->assertSame(10, $newInQuery->count());
242  }
243 }