mockedViewHelper = $this->getAccessibleMock(SimplePrevNextViewHelper::class, ['dummy'], [], '', true, true, false); $this->news = new News(); $this->news->_setProperty('uid', 123); $this->news->setPid(9); $this->importDataSet(__DIR__ . '/../Fixtures/tx_news_domain_model_news.xml'); } /** * @test * * @return void */ public function allNeighboursCanBeFound(): void { $this->setDate(1396035186); $actual = $this->mockedViewHelper->_call('getNeighbours', $this->news, '', 'datetime'); $exp = [ 'prev' => $this->getRow(102), 'next' => $this->getRow(104) ]; $this->assertEquals($exp, $actual); } /** * @test * * @return void */ public function nextNeighbourCanBeFound(): void { $this->setDate(1395516730); $actual = $this->mockedViewHelper->_call('getNeighbours', $this->news, '', 'datetime'); $exp = [ 'next' => $this->getRow(102) ]; $this->assertEquals($exp, $actual); } /** * @test * * @return void */ public function previousNeighbourCanBeFound(): void { $this->setDate(1396640035); $actual = $this->mockedViewHelper->_call('getNeighbours', $this->news, '', 'datetime'); $exp = [ 'prev' => $this->getRow(105) ]; $this->assertEquals($exp, $actual); } /** * @param int $timestamp * * @return void */ protected function setDate($timestamp): void { $date = new DateTime(); $date->setTimestamp($timestamp); $this->news->_setProperty('datetime', $date); } /** * @param int $id */ protected function getRow(int $id) { $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) ->getQueryBuilderForTable('tx_news_domain_model_news'); return $queryBuilder ->select('*') ->from('tx_news_domain_model_news') ->where( $queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($id, \PDO::PARAM_INT)) ) ->setMaxResults(1) ->execute()->fetch(); } }