Initial commit - Typo3 11.5.41
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace GeorgRinger\News\Tests\Unit\ViewHelpers\Be;
|
||||
|
||||
/**
|
||||
* 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 GeorgRinger\News\ViewHelpers\Be\IsCheckboxActiveViewHelper;
|
||||
use TYPO3\TestingFramework\Core\BaseTestCase;
|
||||
|
||||
/**
|
||||
* Tests for IsCheckboxActiveViewhelper
|
||||
*
|
||||
*/
|
||||
class IsCheckboxActiveViewhelperTest extends BaseTestCase
|
||||
{
|
||||
const OK_RESULT = 'checked="checked"';
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function activeCheckboxReturnsCorrectValue(): void
|
||||
{
|
||||
$viewHelper = new IsCheckboxActiveViewHelper();
|
||||
$viewHelper->setArguments([
|
||||
'id' => 10,
|
||||
'categories' => [5, 7, 10, 12]
|
||||
]);
|
||||
$actualResult = $viewHelper->render();
|
||||
|
||||
$this->assertEquals(self::OK_RESULT, $actualResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function nonActiveCheckboxReturnsNothing(): void
|
||||
{
|
||||
$viewHelper = new IsCheckboxActiveViewHelper();
|
||||
$viewHelper->setArguments([
|
||||
'id' => 8,
|
||||
'categories' => [5, 7, 10, 12]
|
||||
]);
|
||||
$actualResult = $viewHelper->render();
|
||||
|
||||
$this->assertEquals('', $actualResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function noCategoriesReturnNothing(): void
|
||||
{
|
||||
$viewHelper = new IsCheckboxActiveViewHelper();
|
||||
|
||||
$this->assertEquals('', $viewHelper->render());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace GeorgRinger\News\Tests\Unit\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 GeorgRinger\News\Domain\Model\News;
|
||||
use GeorgRinger\News\ViewHelpers\ExcludeDisplayedNewsViewHelper;
|
||||
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;
|
||||
use TYPO3\TestingFramework\Core\BaseTestCase;
|
||||
|
||||
/**
|
||||
* Tests for ExcludeDisplayedNewsViewHelper
|
||||
*
|
||||
*/
|
||||
class ExcludeDisplayedNewsViewHelperTest extends BaseTestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function newsIsAddedToExcludedList(): void
|
||||
{
|
||||
$viewHelper = new ExcludeDisplayedNewsViewHelper();
|
||||
$viewHelper->setRenderingContext($this->getMockBuilder(RenderingContext::class)->disableOriginalConstructor()->getMock());
|
||||
|
||||
$newsItem1 = new News();
|
||||
$newsItem1->_setProperty('uid', '123');
|
||||
|
||||
$viewHelper->setArguments(['newsItem' => $newsItem1]);
|
||||
$viewHelper->render();
|
||||
$this->assertEquals($GLOBALS['EXT']['news']['alreadyDisplayed'], ['123' => '123']);
|
||||
|
||||
$newsItem1 = new News();
|
||||
$newsItem1->_setProperty('uid', '123');
|
||||
$this->assertEquals($GLOBALS['EXT']['news']['alreadyDisplayed'], ['123' => '123']);
|
||||
|
||||
$newsItem2 = new News();
|
||||
$newsItem2->_setProperty('uid', '12');
|
||||
$viewHelper->setArguments(['newsItem' => $newsItem2]);
|
||||
$viewHelper->render();
|
||||
$this->assertEquals($GLOBALS['EXT']['news']['alreadyDisplayed'], ['123' => '123', '12' => '12']);
|
||||
|
||||
$newsItem3 = new News();
|
||||
$newsItem3->_setProperty('uid', '12');
|
||||
$newsItem3->_setProperty('_localizedUid', '456');
|
||||
$viewHelper->setArguments(['newsItem' => $newsItem3]);
|
||||
$viewHelper->render();
|
||||
$this->assertEquals($GLOBALS['EXT']['news']['alreadyDisplayed'], ['123' => '123', '12' => '12', '456' => '456']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace GeorgRinger\News\Tests\Unit\ViewHelpers\Format;
|
||||
|
||||
/**
|
||||
* 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 GeorgRinger\News\ViewHelpers\Format\NothingViewHelper;
|
||||
use TYPO3\TestingFramework\Core\BaseTestCase;
|
||||
|
||||
/**
|
||||
* Tests for NothingViewHelper
|
||||
*
|
||||
*/
|
||||
class NothingViewHelperTest extends BaseTestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test of nothing viewHelper
|
||||
*
|
||||
* @test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function noResultExpected(): void
|
||||
{
|
||||
$viewHelper = $this->getAccessibleMock(NothingViewHelper::class, ['renderChildren']);
|
||||
$viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('whatever content'));
|
||||
$actualResult = $viewHelper->render();
|
||||
$this->assertEquals(null, $actualResult);
|
||||
}
|
||||
}
|
||||
221
typo3conf/ext/news/Tests/Unit/ViewHelpers/LinkViewHelperTest.php
Normal file
221
typo3conf/ext/news/Tests/Unit/ViewHelpers/LinkViewHelperTest.php
Normal file
@@ -0,0 +1,221 @@
|
||||
<?php
|
||||
|
||||
namespace GeorgRinger\News\Tests\Unit\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 GeorgRinger\News\Domain\Model\Category;
|
||||
use GeorgRinger\News\Domain\Model\News;
|
||||
use GeorgRinger\News\Service\SettingsService;
|
||||
use GeorgRinger\News\ViewHelpers\LinkViewHelper;
|
||||
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
|
||||
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
|
||||
use TYPO3\TestingFramework\Core\BaseTestCase;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\TagBuilder;
|
||||
|
||||
/**
|
||||
* Test for LinkViewHelper
|
||||
*/
|
||||
class LinkViewHelperTest extends BaseTestCase
|
||||
{
|
||||
protected $mockedContentObjectRenderer;
|
||||
|
||||
protected $mockedViewHelper;
|
||||
|
||||
/** @var News */
|
||||
protected $newsItem;
|
||||
|
||||
/**
|
||||
* Set up
|
||||
*/
|
||||
public function setup(): void
|
||||
{
|
||||
$this->newsItem = new News();
|
||||
|
||||
$this->mockedViewHelper = $this->getAccessibleMock(LinkViewHelper::class, ['init', 'renderChildren']);
|
||||
$this->mockedContentObjectRenderer = $this->getAccessibleMock(ContentObjectRenderer::class, ['typoLink_URL', 'typoLink']);
|
||||
$pluginSettings = $this->getAccessibleMock(SettingsService::class, ['getSettings']);
|
||||
$tag = $this->getAccessibleMock(TagBuilder::class, ['addAttribute', 'setContent', 'render']);
|
||||
$this->mockedViewHelper->_set('cObj', $this->mockedContentObjectRenderer);
|
||||
$this->mockedViewHelper->_set('tag', $tag);
|
||||
$this->mockedViewHelper->_set('pluginSettingsService', $pluginSettings);
|
||||
$this->mockedViewHelper->_set('arguments', ['newsItem' => $this->newsItem]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function internalPageIsUsed(): void
|
||||
{
|
||||
$url = '123';
|
||||
$result = ['parameter' => $url];
|
||||
|
||||
$this->mockedContentObjectRenderer->expects($this->once())->method('typoLink_URL')->with($result);
|
||||
|
||||
$this->newsItem->setType(1);
|
||||
$this->newsItem->setInternalurl($url);
|
||||
|
||||
$this->mockedViewHelper->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function externalUrlIsUsed(): void
|
||||
{
|
||||
$url = 'http://www.typo3.org';
|
||||
$result = ['parameter' => $url];
|
||||
|
||||
$this->mockedContentObjectRenderer->expects($this->once())->method('typoLink_URL')->with($result);
|
||||
|
||||
$this->newsItem->setType(2);
|
||||
$this->newsItem->setExternalurl($url);
|
||||
|
||||
$this->mockedViewHelper->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function humanReadAbleDateIsAddedToConfiguration(): void
|
||||
{
|
||||
$dateTime = new \DateTime('2014-05-16');
|
||||
$newsItem = new \GeorgRinger\News\Domain\Model\News();
|
||||
$newsItem->_setProperty('uid', 123);
|
||||
$newsItem->setDatetime($dateTime);
|
||||
|
||||
$tsSettings = [
|
||||
'link' => [
|
||||
'hrDate' => [
|
||||
'_typoScriptNodeValue' => 1,
|
||||
'day' => 'j',
|
||||
'month' => 'n',
|
||||
'year' => 'Y',
|
||||
]
|
||||
]
|
||||
];
|
||||
$configuration = [];
|
||||
$expected = '&tx_news_pi1[news]=123&tx_news_pi1[controller]=News&tx_news_pi1[action]=detail&tx_news_pi1[day]=16&tx_news_pi1[month]=5&tx_news_pi1[year]=2014';
|
||||
|
||||
$result = $this->mockedViewHelper->_call('getLinkToNewsItem', $newsItem, $tsSettings, $configuration);
|
||||
$this->assertEquals($expected, $result['additionalParams']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getDetailPidFromCategoriesReturnsCorrectValue(): void
|
||||
{
|
||||
$viewHelper = $this->getAccessibleMock(LinkViewHelper::class, ['dummy']);
|
||||
|
||||
$newsItem = new \GeorgRinger\News\Domain\Model\News();
|
||||
|
||||
$categories = new ObjectStorage();
|
||||
$category1 = new Category();
|
||||
$categories->attach($category1);
|
||||
|
||||
$category2 = new Category();
|
||||
$category2->setSinglePid('123');
|
||||
$categories->attach($category2);
|
||||
|
||||
$category3 = new Category();
|
||||
$category3->setSinglePid('456');
|
||||
$categories->attach($category3);
|
||||
|
||||
$newsItem->setCategories($categories);
|
||||
|
||||
$result = $viewHelper->_call('getDetailPidFromCategories', [], $newsItem);
|
||||
$this->assertEquals(123, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @dataProvider getDetailPidFromDefaultDetailPidReturnsCorrectValueDataProvider
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getDetailPidFromDefaultDetailPidReturnsCorrectValue($settings, $expected): void
|
||||
{
|
||||
$viewHelper = $this->getAccessibleMock(LinkViewHelper::class, ['dummy']);
|
||||
|
||||
$result = $viewHelper->_call('getDetailPidFromDefaultDetailPid', $settings, null);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return (int|null|string[])[][]
|
||||
*
|
||||
* @psalm-return array{0: array{0: null, 1: int}, 1: array{0: array<empty, empty>, 1: int}, 2: array{0: array{defaultDetailPid: string}, 1: int}, 3: array{0: array{defaultDetailPid: string}, 1: int}}
|
||||
*/
|
||||
public function getDetailPidFromDefaultDetailPidReturnsCorrectValueDataProvider(): array
|
||||
{
|
||||
return [
|
||||
[null, 0],
|
||||
[[], 0],
|
||||
[['defaultDetailPid' => '789'], 789],
|
||||
[['defaultDetailPid' => '45xy'], 45],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @dataProvider getDetailPidFromFlexformReturnsCorrectValueDataProvider
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getDetailPidFromFlexformReturnsCorrectValue($settings, $expected): void
|
||||
{
|
||||
$viewHelper = $this->getAccessibleMock(LinkViewHelper::class, ['dummy']);
|
||||
|
||||
$result = $viewHelper->_call('getDetailPidFromFlexform', $settings, null);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function getDetailPidFromFlexformReturnsCorrectValueDataProvider(): array
|
||||
{
|
||||
return [
|
||||
[null, 0],
|
||||
[[], 0],
|
||||
[['detailPid' => '123'], 123],
|
||||
[['detailPid' => '456xy'], 456],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function noNewsReturnsChildren(): void
|
||||
{
|
||||
$settingService = $this->getAccessibleMock(SettingsService::class, ['getConfiguration', 'getSettings']);
|
||||
$viewHelper = $this->getAccessibleMock(LinkViewHelper::class, ['renderChildren', 'getSettings']);
|
||||
$viewHelper->_set('pluginSettingsService', $settingService);
|
||||
$viewHelper->setArguments([
|
||||
'newsItem' => null,
|
||||
'settings' => [
|
||||
'useStdWrap' => false
|
||||
],
|
||||
'configuration' => [],
|
||||
'uriOnly' => false,
|
||||
'content' => ''
|
||||
]);
|
||||
$result = $viewHelper->_call('render');
|
||||
$this->assertEquals('', $result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
namespace GeorgRinger\News\Tests\Unit\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 GeorgRinger\News\ViewHelpers\PaginateBodytextViewHelper;
|
||||
use TYPO3\TestingFramework\Core\BaseTestCase;
|
||||
|
||||
/**
|
||||
* Tests for PaginateBodytextViewHelper
|
||||
*/
|
||||
class PaginateBodytextViewHelperTest extends BaseTestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test if given tag is a closing tag
|
||||
*
|
||||
* @test
|
||||
*
|
||||
* @dataProvider givenTagIsAClosingTagDataProvider
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function givenTagIsAClosingTag($tag, $expectedResult): void
|
||||
{
|
||||
$mockTemplateParser = $this->getAccessibleMock(PaginateBodytextViewHelper::class, ['dummy']);
|
||||
$result = $mockTemplateParser->_call('isClosingTag', $tag);
|
||||
$this->assertEquals($expectedResult, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return (bool|string)[][]
|
||||
*
|
||||
* @psalm-return array{'working example 1': array{0: string, 1: true}, 'working example 2': array{0: string, 1: false}}
|
||||
*/
|
||||
public function givenTagIsAClosingTagDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'working example 1' => [
|
||||
'</div>', true
|
||||
],
|
||||
'working example 2' => [
|
||||
'<div>', false
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if given tag is a self closing tag
|
||||
*
|
||||
* @test
|
||||
*
|
||||
* @dataProvider givenTagIsSelfClosingTagDataProvider
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function givenTagIsSelfClosingTag($tag, $expectedResult): void
|
||||
{
|
||||
$mockTemplateParser = $this->getAccessibleMock(PaginateBodytextViewHelper::class, ['dummy']);
|
||||
$result = $mockTemplateParser->_call('isSelfClosingTag', $tag);
|
||||
$this->assertEquals($expectedResult, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return (bool|string)[][]
|
||||
*
|
||||
* @psalm-return array{'working example 1': array{0: string, 1: true}, 'working example 2': array{0: string, 1: false}}
|
||||
*/
|
||||
public function givenTagIsSelfClosingTagDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'working example 1' => [
|
||||
'<hr />', true
|
||||
],
|
||||
'working example 2' => [
|
||||
'<div>', false
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if given tag is an opening tag
|
||||
*
|
||||
* @test
|
||||
*
|
||||
* @dataProvider givenTagIsAnOpeningTagDataProvider
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function givenTagIsAnOpeningTag($tag, $expectedResult): void
|
||||
{
|
||||
$mockTemplateParser = $this->getAccessibleMock(PaginateBodytextViewHelper::class, ['dummy']);
|
||||
$result = $mockTemplateParser->_call('isOpeningTag', $tag);
|
||||
$this->assertEquals($expectedResult, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return (bool|string)[][]
|
||||
*
|
||||
* @psalm-return array{0: array{0: string, 1: true}, 1: array{0: string, 1: false}, 2: array{0: string, 1: false}, 3: array{0: string, 1: false}}
|
||||
*/
|
||||
public function givenTagIsAnOpeningTagDataProvider(): array
|
||||
{
|
||||
return [
|
||||
['<div>', true],
|
||||
['</div>', false],
|
||||
['<div/>', false],
|
||||
['<div />', false]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if given tag is an opening tag
|
||||
*
|
||||
* @test
|
||||
*
|
||||
* @dataProvider extractTagReturnsCorrectOneDataProvider
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function extractTagReturnsCorrectOne($tag, $expectedResult): void
|
||||
{
|
||||
$mockTemplateParser = $this->getAccessibleMock(PaginateBodytextViewHelper::class, ['dummy']);
|
||||
$result = $mockTemplateParser->_call('extractTag', $tag);
|
||||
$this->assertEquals($expectedResult, $result, sprintf('"%s" (%s) : "%s" (%s)', $tag, strlen($tag), $expectedResult, strlen($expectedResult)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[][]
|
||||
*
|
||||
* @psalm-return array{0: array{0: string, 1: string}, 1: array{0: string, 1: string}, 2: array{0: string, 1: string}, 3: array{0: string, 1: string}}
|
||||
*/
|
||||
public function extractTagReturnsCorrectOneDataProvider(): array
|
||||
{
|
||||
return [
|
||||
['this <strong>is</strong> a <div>real</div>test', 'this <strong>'],
|
||||
['this <br /> linebreak', 'this <br />'],
|
||||
['this <br> linebreak', 'this <br>'],
|
||||
['this is a test', 'this is a test'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace GeorgRinger\News\Tests\Unit\ViewHelpers;
|
||||
|
||||
use GeorgRinger\News\ViewHelpers\SimplePrevNextViewHelper;
|
||||
use TYPO3\TestingFramework\Core\BaseTestCase;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test for SimplePrevNextViewHelper
|
||||
*/
|
||||
class SimplePrevNextViewHelperTest extends BaseTestCase
|
||||
{
|
||||
|
||||
/** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface */
|
||||
protected $viewHelper;
|
||||
|
||||
public function setup(): void
|
||||
{
|
||||
$this->viewHelper = $this->getAccessibleMock(SimplePrevNextViewHelper::class, ['getRawRecord']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function wrongIdWillReturnNullForObject(): void
|
||||
{
|
||||
$this->viewHelper->expects($this->any())->method('getRawRecord')->withAnyParameters()->will($this->returnValue(null));
|
||||
|
||||
$out = $this->viewHelper->_call('getObject', 0);
|
||||
$this->assertEquals($out, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function queryResultWillReturnCorrectOutputForAllLinks(): void
|
||||
{
|
||||
$viewHelper = $this->getAccessibleMock(SimplePrevNextViewHelper::class, ['getObject']);
|
||||
|
||||
$in = [
|
||||
'prev' => ['uid' => 123],
|
||||
'next' => ['uid' => 789],
|
||||
];
|
||||
$exp = ['prev' => 123, 'next' => 789];
|
||||
$viewHelper->expects(self::exactly(2))->method('getObject')->willReturnOnConsecutiveCalls(123, 789);
|
||||
$out = $viewHelper->_call('mapResultToObjects', $in);
|
||||
$this->assertEquals($out, $exp);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function queryResultWillReturnCorrectOutputFor2Links(): void
|
||||
{
|
||||
$viewHelper = $this->getAccessibleMock(SimplePrevNextViewHelper::class, ['getObject']);
|
||||
|
||||
$in = [
|
||||
'prev' => ['uid' => 147],
|
||||
];
|
||||
$exp = ['prev' => 147];
|
||||
$viewHelper->expects(self::exactly(1))->method('getObject')->willReturnOnConsecutiveCalls(147);
|
||||
$out = $viewHelper->_call('mapResultToObjects', $in);
|
||||
$this->assertEquals($out, $exp);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function queryResultWillReturnCorrectOutputFor1Link(): void
|
||||
{
|
||||
$viewHelper = $this->getAccessibleMock(SimplePrevNextViewHelper::class, ['getObject']);
|
||||
|
||||
$in = [
|
||||
'next' => ['uid' => 369],
|
||||
];
|
||||
$exp = ['next' => 369];
|
||||
$viewHelper->expects(self::exactly(1))->method('getObject')->willReturnOnConsecutiveCalls(369);
|
||||
$out = $viewHelper->_call('mapResultToObjects', $in);
|
||||
$this->assertEquals($out, $exp);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace GeorgRinger\News\Tests\Unit\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 GeorgRinger\News\ViewHelpers\TargetLinkViewHelper;
|
||||
use TYPO3\TestingFramework\Core\BaseTestCase;
|
||||
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
|
||||
|
||||
/**
|
||||
* Test for TargetLinkViewHelper
|
||||
*/
|
||||
class TargetLinkViewHelperTest extends BaseTestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @return \GeorgRinger\News\ViewHelpers\TargetLinkViewHelper
|
||||
* @support
|
||||
*/
|
||||
protected function getPreparedInstance()
|
||||
{
|
||||
$instance = $this->getMockBuilder(TargetLinkViewHelper::class)->setMethods(['dummy'])->getMock();
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function canCreateViewHelperClassInstance(): void
|
||||
{
|
||||
$instance = $this->getPreparedInstance();
|
||||
$this->assertInstanceOf(TargetLinkViewHelper::class, $instance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if correct target is returned
|
||||
*
|
||||
* @test
|
||||
*
|
||||
* @dataProvider correctTargetIsReturnedDataProvider
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function correctTargetIsReturned($link, $expectedResult): void
|
||||
{
|
||||
$viewHelper = $this->getMockBuilder(TargetLinkViewHelper::class)->setMethods(['dummy'])->getMock();
|
||||
$viewHelper->setRenderingContext($this->getMockBuilder(RenderingContextInterface::class)->getMock());
|
||||
$viewHelper->setArguments([
|
||||
'link' => $link,
|
||||
]);
|
||||
|
||||
$this->assertEquals($viewHelper->render(), $expectedResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function correctTargetIsReturnedDataProvider()
|
||||
{
|
||||
return [
|
||||
'noTargetSetAndUrlDefined' => [
|
||||
'www.typo3.org', ''
|
||||
],
|
||||
'noTargetSetAndIdDefined' => [
|
||||
'123', ''
|
||||
],
|
||||
'IdAndTargetDefined' => [
|
||||
'123 _blank', '_blank'
|
||||
],
|
||||
'UrlAndPopupDefined' => [
|
||||
'www.typo3.org 300x400', ''
|
||||
],
|
||||
'ComplexExample' => [
|
||||
'www.typo3.org _fo my-class', '_fo'
|
||||
],
|
||||
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user