Initial commit - Typo3 11.5.41
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace GeorgRinger\News\Tests\Functional\ViewHelpers\Iterator;
|
||||
|
||||
/**
|
||||
* This file is part of the "news" Extension for TYPO3 CMS.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Fluid\View\StandaloneView;
|
||||
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
|
||||
|
||||
/**
|
||||
* Test for ChunkViewHelper
|
||||
*/
|
||||
class ChunkViewHelperTest extends FunctionalTestCase
|
||||
{
|
||||
protected $testExtensionsToLoad = ['typo3conf/ext/news'];
|
||||
protected $coreExtensionsToLoad = ['extbase', 'fluid'];
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function chunkIsProperlyCreated(): void
|
||||
{
|
||||
$standaloneView = GeneralUtility::makeInstance(StandaloneView::class);
|
||||
$standaloneView->setTemplateSource(
|
||||
'{namespace n=GeorgRinger\News\ViewHelpers}' . LF .
|
||||
'<f:for each="{news -> n:iterator.chunk(count: 3)}" as="col" iteration="cycle">' .
|
||||
'<div class="row"><f:for each="{col}" as="item"><div class="col">{item.title}</div></f:for></div>' .
|
||||
'</f:for>'
|
||||
);
|
||||
$standaloneView->assign('news', [
|
||||
['title' => 'el1'],
|
||||
['title' => 'el2'],
|
||||
['title' => 'el3'],
|
||||
['title' => 'el4'],
|
||||
]);
|
||||
|
||||
$expected = '<div class="row">' .
|
||||
'<div class="col">el1</div>' .
|
||||
'<div class="col">el2</div>' .
|
||||
'<div class="col">el3</div>' .
|
||||
'</div>' .
|
||||
'<div class="row">' .
|
||||
'<div class="col">el4</div>' .
|
||||
'</div>';
|
||||
$this->assertEquals(trim($expected), trim($standaloneView->render()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
namespace GeorgRinger\News\Tests\Functional\ViewHelpers;
|
||||
|
||||
/**
|
||||
* This file is part of the "news" Extension for TYPO3 CMS.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use DateTime;
|
||||
use GeorgRinger\News\Domain\Model\News;
|
||||
use GeorgRinger\News\ViewHelpers\SimplePrevNextViewHelper;
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
|
||||
|
||||
/**
|
||||
* Class SimplePrevNextViewHelperTest
|
||||
*
|
||||
*/
|
||||
class SimplePrevNextViewHelperTest extends FunctionalTestCase
|
||||
{
|
||||
|
||||
/** @var \GeorgRinger\News\ViewHelpers\SimplePrevNextViewHelper|\PHPUnit\Framework\MockObject\MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface */
|
||||
protected $mockedViewHelper;
|
||||
|
||||
/** @var News */
|
||||
protected $news;
|
||||
|
||||
protected $testExtensionsToLoad = ['typo3conf/ext/news'];
|
||||
protected $coreExtensionsToLoad = ['extbase', 'fluid'];
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user