TYPO3 CMS  TYPO3_6-2
CountTest.php
Go to the documentation of this file.
1 <?php
3 
19 
21 
25  protected $numberOfRecordsInFixture = 11;
26 
30  protected $persistentManager;
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  protected $blogRepository;
51 
55  public function setUp() {
56  parent::setUp();
57 
58  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/core/Tests/Functional/Fixtures/pages.xml');
59  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/blogs.xml');
60  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/posts.xml');
61  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/tags.xml');
62  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/post-tag-mm.xml');
63 
64  $this->objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
65  $this->persistentManager = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager');
66  $this->postRepository = $this->objectManager->get('ExtbaseTeam\\BlogExample\\Domain\\Repository\\PostRepository');
67  }
68 
72  public function simpleCountTest() {
73  $query = $this->postRepository->createQuery();
74  $this->assertSame($this->numberOfRecordsInFixture, $query->count());
75  }
76 
80  public function offsetCountTest() {
81  $query = $this->postRepository->createQuery();
82 
83  $query->setOffset(6);
84 
85  $this->assertSame(($this->numberOfRecordsInFixture - 6), $query->count());
86  }
87 
91  public function exceedingOffsetCountTest() {
92  $query = $this->postRepository->createQuery();
93 
94  $query->setOffset(($this->numberOfRecordsInFixture + 5));
95 
96  $this->assertSame(0, $query->count());
97  }
98 
102  public function limitCountTest() {
103  $query = $this->postRepository->createQuery();
104 
105  $query->setLimit(4);
106 
107  $this->assertSame(4, $query->count());
108  }
109 
113  public function limitAndOffsetCountTest() {
114  $query = $this->postRepository->createQuery();
115 
116  $query
117  ->setOffset(($this->numberOfRecordsInFixture - 3))
118  ->setLimit(4);
119 
120  $this->assertSame(3, $query->count());
121  }
122 
126  public function inConstraintCountTest() {
127  $query = $this->postRepository->createQuery();
128 
129  $query->matching(
130  $query->in('uid', array(1,2,3))
131  );
132 
133  $this->assertSame(3, $query->count());
134  }
135 
141  public function subpropertyJoinCountTest() {
142  $query = $this->postRepository->createQuery();
143 
144  $query->matching(
145  $query->equals('blog.title', 'Blog1')
146  );
147 
148  $this->assertSame(10, $query->count());
149  }
150 
157  $query = $this->postRepository->createQuery();
158 
159  $query->matching(
160  $query->logicalOr(
161  $query->equals('tags.uid', 1),
162  $query->equals('tags.uid', 2)
163  )
164  );
165 
166  $this->assertSame(10, $query->count());
167  }
168 }