/** * @return void */ protected function setDefaultOrderings() { $orderBy = $orderDir = ''; if ($this->request->hasArgument('orderBy') && in_array($this->request->getArgument('orderBy'), $this->allowedOrderBy)) { $orderBy = $this->request->getArgument('orderBy'); } if ($this->request->hasArgument('orderDir') && ($this->request->getArgument('orderDir') == \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING || $this->request->getArgument('orderDir') == \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING)) { $orderDir = $this->request->getArgument('orderDir'); } elseif ($this->settings['orderDir'] == \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING || $this->settings['orderDir'] == \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING) { $orderDir = $this->settings['orderDir']; } if (empty($orderDir)) { $orderDir = \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING; } if ($orderBy) { $defaultOrderings = array_merge(array($orderBy => $orderDir), (array) $this->settings['orderings']); $this->repository->setDefaultOrderings($defaultOrderings); } }
/** * @test */ public function createQuerySetsDefaultOrderingIfDefined() { $orderings = array('foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING); $mockQuery = $this->getMock(\TYPO3\CMS\Extbase\Persistence\QueryInterface::class); $mockQuery->expects($this->once())->method('setOrderings')->with($orderings); $mockPersistenceManager = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager::class); $mockPersistenceManager->expects($this->exactly(2))->method('createQueryForType')->with('ExpectedType')->will($this->returnValue($mockQuery)); $this->repository->_set('objectType', 'ExpectedType'); $this->inject($this->repository, 'persistenceManager', $mockPersistenceManager); $this->repository->setDefaultOrderings($orderings); $this->repository->createQuery(); $this->repository->setDefaultOrderings(array()); $this->repository->createQuery(); }