Initial commit - Typo3 11.5.41

This commit is contained in:
Matteo Gallo
2026-07-03 17:53:31 +02:00
commit 5ca4743197
6811 changed files with 568848 additions and 0 deletions

View File

@@ -0,0 +1,198 @@
<?php
declare(strict_types=1);
namespace GeorgRinger\News\Tests\Unit\Backend\FieldInformation;
/**
* 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\Backend\FieldInformation\StaticText;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use TYPO3\CMS\Backend\Form\NodeFactory;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\TestingFramework\Core\BaseTestCase;
class StaticTextTest extends BaseTestCase
{
use ProphecyTrait;
/**
* @var StaticText
*/
protected $subject;
/**
* @var NodeFactory|ObjectProphecy
*/
protected $nodeFactoryProphecy;
/**
* @var LanguageService|ObjectProphecy
*/
protected $languageServiceProphecy;
protected function setUp(): void
{
parent::setUp();
$this->languageServiceProphecy = $this->prophesize(LanguageService::class);
$this->languageServiceProphecy
->sL('label1')
->willReturn('label bold');
$this->languageServiceProphecy
->sL('label2')
->willReturn('label italic');
$this->languageServiceProphecy
->sL('label3')
->willReturn('label both');
$this->languageServiceProphecy
->sL('label4')
->willReturn('label unformatted');
$GLOBALS['LANG'] = $this->languageServiceProphecy->reveal();
$this->nodeFactoryProphecy = $this->prophesize(NodeFactory::class);
}
protected function tearDown(): void
{
unset(
$this->subject,
$this->nodeFactoryProphecy
);
parent::tearDown();
}
/**
* @test
*/
public function renderWillNotAddAnyLabels(): void
{
$this->subject = new StaticText(
$this->nodeFactoryProphecy->reveal(),
[]
);
$nodeConfiguration = $this->subject->render();
$this->assertArrayHasKey(
'requireJsModules',
$nodeConfiguration
);
$this->assertEquals(
['TYPO3/CMS/News/TagSuggestWizard'],
$nodeConfiguration['requireJsModules']
);
$this->assertArrayHasKey(
'html',
$nodeConfiguration
);
$this->assertEquals(
'<div class="form-control-wrap news-taggable"></div>',
$nodeConfiguration['html']
);
}
/**
* @test
*/
public function renderWillAddVariousFormattedLabels(): void
{
$this->subject = new StaticText(
$this->nodeFactoryProphecy->reveal(),
[
'renderData' => [
'fieldInformationOptions' => [
'labels' => [
0 => [
'label' => 'label1',
'bold' => '1'
],
1 => [
'label' => 'label2',
'italic' => 'something'
],
2 => [
'label' => 'label3',
'italic' => 30,
'bold' => 'hello',
],
3 => [
'label' => 'label4',
],
]
]
]
]
);
$nodeConfiguration = $this->subject->render();
$this->assertArrayHasKey(
'html',
$nodeConfiguration
);
$this->assertStringContainsString(
'<strong>label bold</strong>',
$nodeConfiguration['html']
);
$this->assertStringContainsString(
'<em>label italic</em>',
$nodeConfiguration['html']
);
$this->assertStringContainsString(
'<strong><em>label both</em></strong>',
$nodeConfiguration['html']
);
$this->assertStringContainsString(
'label unformatted',
$nodeConfiguration['html']
);
}
/**
* @test
*/
public function renderWillDivideLabelsWithBreak(): void
{
$this->subject = new StaticText(
$this->nodeFactoryProphecy->reveal(),
[
'renderData' => [
'fieldInformationOptions' => [
'labels' => [
0 => [
'label' => 'label1',
],
1 => [
'label' => 'label2',
],
]
]
]
]
);
$nodeConfiguration = $this->subject->render();
$this->assertArrayHasKey(
'html',
$nodeConfiguration
);
$this->assertStringContainsString(
'label bold<br />label italic',
$nodeConfiguration['html']
);
}
}

View File

@@ -0,0 +1,107 @@
<?php
namespace GeorgRinger\News\Tests\Unit\Backend\FormDataProvider;
/**
* 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\Backend\FormDataProvider\NewsRowInitializeNew;
use GeorgRinger\News\Domain\Model\Dto\EmConfiguration;
use TYPO3\TestingFramework\Core\BaseTestCase;
class NewsRowInitializeNewTest extends BaseTestCase
{
/**
* @test
*
* @return void
*/
public function dateTimeIsFilled(): void
{
$provider = $this->getAccessibleMock(NewsRowInitializeNew::class, ['dummy'], [], '', false);
$mockedEmConfiguration = $this->getAccessibleMock(EmConfiguration::class, ['getDateTimeRequired'], [], '', false);
$mockedEmConfiguration->expects($this->once())->method('getDateTimeRequired')->will($this->returnValue(true));
$provider->_set('emConfiguration', $mockedEmConfiguration);
$GLOBALS['EXEC_TIME'] = time();
$result = [
'command' => 'new',
'tableName' => 'tx_news_domain_model_news'
];
$expected = [
'command' => 'new',
'tableName' => 'tx_news_domain_model_news',
'databaseRow' => [
'datetime' => $GLOBALS['EXEC_TIME']
]
];
$this->assertEquals($expected, $provider->addData($result));
}
/**
* @test
*
* @return void
*/
public function dateTimeIsNotFilledIfSetInExtensionManagerConfiguration(): void
{
$mockedProvider = $this->getAccessibleMock(NewsRowInitializeNew::class, ['dummy'], [], '', false);
$configuration = ['dateTimeNotRequired' => true];
$settings = new EmConfiguration($configuration);
$mockedProvider->_set('emConfiguration', $settings);
$result = [
'command' => 'new',
'tableName' => 'tx_news_domain_model_news'
];
$expected = [
'command' => 'new',
'tableName' => 'tx_news_domain_model_news',
];
$this->assertEquals($expected, $mockedProvider->addData($result));
}
/**
* @test
*
* @return void
*/
public function archiveTimeIsFilled(): void
{
$provider = $this->getAccessibleMock(NewsRowInitializeNew::class, ['dummy'], [], '', false);
$mockedEmConfiguration = $this->getAccessibleMock(EmConfiguration::class, ['getDateTimeRequired'], [], '', false);
$mockedEmConfiguration->expects($this->once())->method('getDateTimeRequired')->will($this->returnValue(true));
$provider->_set('emConfiguration', $mockedEmConfiguration);
$GLOBALS['EXEC_TIME'] = time();
$result = [
'command' => 'new',
'tableName' => 'tx_news_domain_model_news',
'pageTsConfig' => [
'tx_news.' => [
'predefine.' => [
'archive' => '+10 days'
]
]
]
];
$expected = $result;
$expected['databaseRow']['datetime'] = $GLOBALS['EXEC_TIME'];
$expected['databaseRow']['archive'] = strtotime('+10 days');
$this->assertEquals($expected, $provider->addData($result));
}
}

View File

@@ -0,0 +1,62 @@
<?php
namespace GeorgRinger\News\Tests\Unit\Controller;
/**
* 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\Controller\TagController;
use GeorgRinger\News\Domain\Model\Dto\NewsDemand;
use GeorgRinger\News\Domain\Repository\TagRepository;
use TYPO3\CMS\Fluid\View\TemplateView;
use TYPO3\TestingFramework\Core\BaseTestCase;
/**
* Testcase for the TagController class.
*
*
*/
class TagControllerTest extends BaseTestCase
{
private $tagRepository = null;
/**
* Set up framework
*
*/
public function setup(): void
{
$this->tagRepository = $this->prophesize(TagRepository::class);
}
/**
* Test for creating correct demand call
*
* @test
*
* @return void
*/
public function listActionFindsDemandedTagsByDemandFromSettings(): void
{
$this->markTestSkipped('May not be relevant anymore. Reason: failing because of using DI');
$demand = new NewsDemand();
$settings = ['list' => 'foo', 'orderBy' => 'datetime'];
$fixture->_set('tagRepository', $this->tagRepository->reveal());
$fixture->setView($this->getMockBuilder(TemplateView::class)->disableOriginalConstructor()->getMock());
$fixture->_set('settings', $settings);
$fixture->expects($this->once())->method('createDemandObjectFromSettings')
->will($this->returnValue($demand));
$this->tagRepository->findDemanded($demand)->shouldBeCalled();
$fixture->listAction();
// datetime must be removed
$this->assertEquals($fixture->_get('settings'), ['list' => 'foo']);
}
}

View File

@@ -0,0 +1,847 @@
<?php
namespace GeorgRinger\News\Tests\Unit\Domain\Model;
use GeorgRinger\News\Domain\Model\Category;
use GeorgRinger\News\Domain\Model\FileReference;
/**
* 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\Extbase\Persistence\ObjectStorage;
use TYPO3\TestingFramework\Core\BaseTestCase;
/**
* Tests for \GeorgRinger\News\Domain\Model\Category
*
*/
class CategoryTest extends BaseTestCase
{
/**
* @var Category
*/
protected $instance;
protected function setUp(): void
{
$this->instance = new Category();
}
protected function tearDown(): void
{
unset($this->instance);
parent::tearDown();
}
/**
* @test
*/
public function getSortingInitiallyReturnsZero(): void
{
$this->assertSame(
0,
$this->instance->getSorting()
);
}
/**
* @test
*/
public function setSortingWithStringConvertsValueToInt(): void
{
$this->instance->setSorting('123');
$this->assertSame(
123,
$this->instance->getSorting()
);
}
/**
* @test
*/
public function setSortingWithIntSetsSorting(): void
{
$value = 123;
$this->instance->setSorting($value);
$this->assertSame(
$value,
$this->instance->getSorting()
);
}
/**
* @test
*/
public function getCrdateInitiallyReturnsNull(): void
{
$this->assertNull(
$this->instance->getCrdate()
);
}
/**
* @test
*/
public function setCrdateSetsCrdate(): void
{
$date = new \DateTime('now');
$this->instance->setCrdate($date);
$this->assertSame(
$date,
$this->instance->getCrdate()
);
}
/**
* @test
*/
public function getTstampInitiallyReturnsNull(): void
{
$this->assertNull(
$this->instance->getTstamp()
);
}
/**
* @test
*/
public function setTstampSetsTstamp(): void
{
$date = new \DateTime('now');
$this->instance->setTstamp($date);
$this->assertSame(
$date,
$this->instance->getTstamp()
);
}
/**
* @test
*/
public function getStarttimeInitiallyReturnsNull(): void
{
$this->assertNull(
$this->instance->getStarttime()
);
}
/**
* @test
*/
public function setStarttimeSetsStarttime(): void
{
$date = new \DateTime('now');
$this->instance->setStarttime($date);
$this->assertSame(
$date,
$this->instance->getStarttime()
);
}
/**
* @test
*/
public function getEndtimeInitiallyReturnsNull(): void
{
$this->assertNull(
$this->instance->getEndtime()
);
}
/**
* @test
*/
public function setEndtimeSetsEndtime(): void
{
$date = new \DateTime('now');
$this->instance->setEndtime($date);
$this->assertSame(
$date,
$this->instance->getEndtime()
);
}
/**
* @test
*/
public function getHiddenInitiallyReturnsFalse(): void
{
$this->assertFalse(
$this->instance->getHidden()
);
}
/**
* @test
*/
public function setHiddenWithStringSetsHidden(): void
{
$this->instance->setHidden('1');
$this->assertTrue(
$this->instance->getHidden()
);
}
/**
* @test
*/
public function setHiddenWithIntSetsHidden(): void
{
$this->instance->setHidden(1);
$this->assertTrue(
$this->instance->getHidden()
);
}
/**
* @test
*/
public function setHiddenWithTrueSetsHidden(): void
{
$this->instance->setHidden(true);
$this->assertTrue(
$this->instance->getHidden()
);
}
/**
* @test
*/
public function setHiddenWithFalseSetsHidden(): void
{
$this->instance->setHidden(false);
$this->assertFalse(
$this->instance->getHidden()
);
}
/**
* @test
*/
public function getSysLanguageUidInitiallyReturnsZero(): void
{
$this->assertSame(
0,
$this->instance->getSysLanguageUid()
);
}
/**
* @test
*/
public function setSysLanguageUidWithStringConvertsToInt(): void
{
$this->instance->setSysLanguageUid('2');
$this->assertSame(
2,
$this->instance->getSysLanguageUid()
);
}
/**
* @test
*/
public function setSysLanguageUidSetsSysLanguageUid(): void
{
$value = 3;
$this->instance->setSysLanguageUid($value);
$this->assertSame(
$value,
$this->instance->getSysLanguageUid()
);
}
/**
* @test
*/
public function getL10nParentInitiallyReturnsZero(): void
{
$this->assertSame(
0,
$this->instance->getL10nParent()
);
}
/**
* @test
*/
public function setL10nParentWithStringConvertsToInt(): void
{
$this->instance->setL10nParent('2');
$this->assertSame(
2,
$this->instance->getL10nParent()
);
}
/**
* @test
*/
public function setL10nParentSetsL10nParent(): void
{
$value = 3;
$this->instance->setL10nParent($value);
$this->assertSame(
$value,
$this->instance->getL10nParent()
);
}
/**
* @test
*/
public function getTitleInitiallyReturnsEmptyString(): void
{
$this->assertSame(
'',
$this->instance->getTitle()
);
}
/**
* @test
*/
public function setTitleWithIntConvertsToSting(): void
{
$this->instance->setTitle(123);
$this->assertSame(
'123',
$this->instance->getTitle()
);
}
/**
* @test
*/
public function setTitleSetsTitle(): void
{
$value = 'Hello';
$this->instance->setTitle($value);
$this->assertSame(
$value,
$this->instance->getTitle()
);
}
/**
* @test
*/
public function getDescriptionInitiallyReturnsEmptyString(): void
{
$this->assertSame(
'',
$this->instance->getDescription()
);
}
/**
* @test
*/
public function setDescriptionWithIntConvertsToSting(): void
{
$this->instance->setDescription(123);
$this->assertSame(
'123',
$this->instance->getDescription()
);
}
/**
* @test
*/
public function setDescriptionSetsDescription(): void
{
$value = 'Hello';
$this->instance->setDescription($value);
$this->assertSame(
$value,
$this->instance->getDescription()
);
}
/**
* @test
*/
public function getParentcategoryInitiallyReturnsNull(): void
{
$this->assertNull(
$this->instance->getParentcategory()
);
}
/**
* @test
*/
public function setParentcategorySetsParentcategory(): void
{
$value = new Category();
$value->setTitle('TYPO3');
$this->instance->setParentcategory($value);
$this->assertSame(
$value,
$this->instance->getParentcategory()
);
}
/**
* @test
*/
public function getImagesInitiallyReturnsObjectStorage(): void
{
$value = new ObjectStorage();
$this->assertEquals(
$value,
$this->instance->getImages()
);
}
/**
* @test
*/
public function setImagesSetsImages(): void
{
$value = new ObjectStorage();
$this->instance->setImages($value);
$this->assertSame(
$value,
$this->instance->getImages()
);
}
/**
* @test
*/
public function addImageAddsImage(): void
{
$fileReference = new FileReference();
$images = new ObjectStorage();
$images->attach($fileReference);
$this->instance->addImage($fileReference);
$this->assertEquals(
$images,
$this->instance->getImages()
);
}
/**
* @test
*/
public function removeImageRemovesImage(): void
{
$fileReference = new FileReference();
$images = new ObjectStorage();
$images->attach($fileReference);
$expectedImages = clone $images;
$expectedImages->detach($fileReference);
$this->instance->setImages($images);
$this->instance->removeImage($fileReference);
$this->assertEquals(
$expectedImages,
$this->instance->getImages()
);
}
/**
* @test
*/
public function getFirstImageInitiallyReturnsNull(): void
{
$this->assertNull(
$this->instance->getFirstImage()
);
}
/**
* @test
*/
public function getFirstImageReturnsFileReference(): void
{
$fileReference1 = new FileReference();
$fileReference1->setTitle('Image 1');
$fileReference2 = new FileReference();
$fileReference2->setTitle('Image 2');
$images = new ObjectStorage();
$images->attach($fileReference1);
$images->attach($fileReference2);
$this->instance->setImages($images);
$this->assertSame(
$fileReference1,
$this->instance->getFirstImage()
);
}
/**
* @test
*/
public function getShortcutInitiallyReturnsZero(): void
{
$this->assertSame(
0,
$this->instance->getShortcut()
);
}
/**
* @test
*/
public function setShortcutWithStringConvertsToInt(): void
{
$this->instance->setShortcut('43');
$this->assertSame(
43,
$this->instance->getShortcut()
);
}
/**
* @test
*/
public function setShortcutSetsShortcut(): void
{
$value = 23;
$this->instance->setShortcut($value);
$this->assertSame(
$value,
$this->instance->getShortcut()
);
}
/**
* @test
*/
public function getSinglePidInitiallyReturnsZero(): void
{
$this->assertSame(
0,
$this->instance->getSinglePid()
);
}
/**
* @test
*/
public function setSinglePidWithStringConvertsToInt(): void
{
$this->instance->setSinglePid('43');
$this->assertSame(
43,
$this->instance->getSinglePid()
);
}
/**
* @test
*/
public function setSinglePidSetsSinglePid(): void
{
$value = 23;
$this->instance->setSinglePid($value);
$this->assertSame(
$value,
$this->instance->getSinglePid()
);
}
/**
* @test
*/
public function getImportIdInitiallyReturnsEmptyString(): void
{
$this->assertSame(
'',
$this->instance->getImportId()
);
}
/**
* @test
*/
public function setImportIdWithIntConvertsToString(): void
{
$this->instance->setImportId(24);
$this->assertSame(
'24',
$this->instance->getImportId()
);
}
/**
* @test
*/
public function setImportIdSetsImportId(): void
{
$value = '1324';
$this->instance->setImportId($value);
$this->assertSame(
$value,
$this->instance->getImportId()
);
}
/**
* @test
*/
public function getImportSourceInitiallyReturnsEmptyString(): void
{
$this->assertSame(
'',
$this->instance->getImportSource()
);
}
/**
* @test
*/
public function setImportSourceWithIntConvertsToString(): void
{
$this->instance->setImportSource(24);
$this->assertSame(
'24',
$this->instance->getImportSource()
);
}
/**
* @test
*/
public function setImportSourceSetsImportSource(): void
{
$value = '1324';
$this->instance->setImportSource($value);
$this->assertSame(
$value,
$this->instance->getImportSource()
);
}
/**
* @test
*/
public function getFeGroupInitiallyReturnsEmptyString(): void
{
$this->assertSame(
'',
$this->instance->getImportSource()
);
}
/**
* @test
*/
public function setFeGroupWithIntConvertsToString(): void
{
$this->instance->setFeGroup(24);
$this->assertSame(
'24',
$this->instance->getFeGroup()
);
}
/**
* @test
*/
public function setFeGroupSetsFeGroup(): void
{
$value = '1324';
$this->instance->setFeGroup($value);
$this->assertSame(
$value,
$this->instance->getFeGroup()
);
}
/**
* @test
*/
public function getSeoTitleInitiallyReturnsEmptyString(): void
{
$this->assertSame(
'',
$this->instance->getSeoTitle()
);
}
/**
* @test
*/
public function setSeoTitleWithIntConvertsToString(): void
{
$this->instance->setSeoTitle(24);
$this->assertSame(
'24',
$this->instance->getSeoTitle()
);
}
/**
* @test
*/
public function setSeoTitleSetsSeoTitle(): void
{
$value = 'TYPO3';
$this->instance->setSeoTitle($value);
$this->assertSame(
$value,
$this->instance->getSeoTitle()
);
}
/**
* @test
*/
public function getSeoDescriptionInitiallyReturnsEmptyString(): void
{
$this->assertSame(
'',
$this->instance->getSeoDescription()
);
}
/**
* @test
*/
public function setSeoDescriptionWithIntConvertsToString(): void
{
$this->instance->setSeoDescription(24);
$this->assertSame(
'24',
$this->instance->getSeoDescription()
);
}
/**
* @test
*/
public function setSeoDescriptionSetsSeoDescription(): void
{
$value = 'TYPO3';
$this->instance->setSeoDescription($value);
$this->assertSame(
$value,
$this->instance->getSeoDescription()
);
}
/**
* @test
*/
public function getSeoHeadlineInitiallyReturnsEmptyString(): void
{
$this->assertSame(
'',
$this->instance->getSeoHeadline()
);
}
/**
* @test
*/
public function setSeoHeadlineWithIntConvertsToString(): void
{
$this->instance->setSeoHeadline(24);
$this->assertSame(
'24',
$this->instance->getSeoHeadline()
);
}
/**
* @test
*/
public function setSeoHeadlineSetsSeoHeadline(): void
{
$value = 'TYPO3';
$this->instance->setSeoHeadline($value);
$this->assertSame(
$value,
$this->instance->getSeoHeadline()
);
}
/**
* @test
*/
public function getSeoTextInitiallyReturnsEmptyString(): void
{
$this->assertSame(
'',
$this->instance->getSeoText()
);
}
/**
* @test
*/
public function setSeoTextWithIntConvertsToString(): void
{
$this->instance->setSeoText(24);
$this->assertSame(
'24',
$this->instance->getSeoText()
);
}
/**
* @test
*/
public function setSeoTextSetsSeoText(): void
{
$value = 'TYPO3';
$this->instance->setSeoText($value);
$this->assertSame(
$value,
$this->instance->getSeoText()
);
}
/**
* @test
*/
public function getSlugInitiallyReturnsEmptyString(): void
{
$this->assertSame(
'',
$this->instance->getSlug()
);
}
/**
* @test
*/
public function setSlugWithIntConvertsToString(): void
{
$this->instance->setSlug(24);
$this->assertSame(
'24',
$this->instance->getSlug()
);
}
/**
* @test
*/
public function setSlugSetsSlug(): void
{
$value = 'TYPO3';
$this->instance->setSlug($value);
$this->assertSame(
$value,
$this->instance->getSlug()
);
}
}

View File

@@ -0,0 +1,96 @@
<?php
namespace GeorgRinger\News\Tests\Unit\Domain\Model\Dto;
/**
* 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\Dto\AdministrationDemand;
use TYPO3\TestingFramework\Core\BaseTestCase;
/**
* Tests for AdministrationDemand
*
*/
class AdministrationDemandTest extends BaseTestCase
{
/** @var AdministrationDemand */
protected $instance;
public function setup(): void
{
$this->instance = new AdministrationDemand();
}
/**
* Test if recursive can be set
*
* @test
*
* @return void
*/
public function recursiveCanBeSet(): void
{
$value = 'Test 123';
$this->instance->setRecursive($value);
$this->assertEquals($value, $this->instance->getRecursive());
}
/**
* Test if selectedCategories can be set
*
* @test
*
* @return void
*/
public function selectedCategoriesCanBeSet(): void
{
$value = ['Test 123'];
$this->instance->setCategories($value);
$this->assertEquals($value, $this->instance->getCategories());
}
/**
* Test if sortingField can be set
*
* @test
*
* @return void
*/
public function sortingFieldCanBeSet(): void
{
$value = 'title';
$this->instance->setSortingField($value);
$this->assertEquals($value, $this->instance->getSortingField());
}
/**
* Test if sortingDirection can be set
*
* @test
*
* @return void
*/
public function sortingDirectionCanBeSet(): void
{
$value = 'asc';
$this->instance->setSortingDirection($value);
$this->assertEquals($value, $this->instance->getSortingDirection());
}
/**
* @test
*
* @return void
*/
public function hiddenCanBeSet(): void
{
$value = 2;
$this->instance->setHidden($value);
$this->assertEquals($value, $this->instance->getHidden());
}
}

View File

@@ -0,0 +1,91 @@
<?php
namespace GeorgRinger\News\Tests\Unit\Domain\Model\Dto;
/**
* 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\Dto\EmConfiguration;
use TYPO3\TestingFramework\Core\BaseTestCase;
/**
* Tests for domains model News
*
*/
class EmConfigurationTest extends BaseTestCase
{
/**
* Test if the settings can be read
*
* @test
*
* @return void
*/
public function settingsCanBeRead(): void
{
$configuration = [
'tagPid' => 123,
'prependAtCopy' => true,
'categoryRestriction' => 'fo',
'contentElementRelation' => false,
'manualSorting' => false,
'archiveDate' => 'bar',
'dateTimeNotRequired' => true,
'showImporter' => true,
'showAdministrationModule' => false,
'rteForTeaser' => false,
'storageUidImporter' => 1,
'resourceFolderImporter' => 'fo',
'hidePageTreeForAdministrationModule' => true,
'slugBehaviour' => 'uniqueInSite',
];
$configurationInstance = $this->getAccessibleMock(EmConfiguration::class, ['dummy'], [], '', false);
foreach ($configuration as $key => $value) {
$configurationInstance->_set($key, $value);
}
foreach ($configuration as $key => $value) {
$functionName = 'get' . ucwords($key);
$this->assertEquals($value, $configurationInstance->$functionName());
}
}
/**
* Test if default settings can be read
*
* @test
*
* @return void
*/
public function defaultSettingsCanBeRead(): void
{
$configuration = [
'tagPid' => 0,
'prependAtCopy' => true,
'categoryRestriction' => '',
'contentElementRelation' => true,
'manualSorting' => false,
'archiveDate' => 'date',
'dateTimeNotRequired' => false,
'showImporter' => false,
'showAdministrationModule' => true,
'rteForTeaser' => false,
'storageUidImporter' => 1,
'resourceFolderImporter' => '/news_import',
'hidePageTreeForAdministrationModule' => false,
'slugBehaviour' => 'unique',
];
$configurationInstance = $this->getAccessibleMock(EmConfiguration::class, ['dummy'], [], '', false);
foreach ($configuration as $key => $value) {
$functionName = 'get' . ucwords($key);
$this->assertEquals($value, $configurationInstance->$functionName());
}
}
}

View File

@@ -0,0 +1,349 @@
<?php
namespace GeorgRinger\News\Tests\Unit\Domain\Model\Dto;
/**
* 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\Dto\NewsDemand;
use GeorgRinger\News\Domain\Model\Dto\Search;
use TYPO3\TestingFramework\Core\BaseTestCase;
/**
* Tests for NewsDemand
*/
class NewsDemandTest extends BaseTestCase
{
/** @var NewsDemand */
protected $instance;
public function setup(): void
{
$this->instance = new NewsDemand();
}
/**
* @test
*
* @return void
*/
public function categoriesCanBeSet(): void
{
$value = ['Test 123'];
$this->instance->setCategories($value);
$this->assertEquals($value, $this->instance->getCategories());
}
/**
* @test
*
* @return void
*/
public function categoryConjunctionCanBeSet(): void
{
$value = 'AND';
$this->instance->setCategoryConjunction($value);
$this->assertEquals($value, $this->instance->getCategoryConjunction());
}
/**
* @test
*
* @return void
*/
public function includeSubCategoriesCanBeSet(): void
{
$value = true;
$this->instance->setIncludeSubCategories($value);
$this->assertEquals($value, $this->instance->getIncludeSubCategories());
}
/**
* @test
*
* @return void
*/
public function authorCanBeSet(): void
{
$value = '7elix';
$this->instance->setAuthor($value);
$this->assertEquals($value, $this->instance->getAuthor());
}
/**
* @test
*
* @return void
*/
public function tagsCanBeSet(): void
{
$value = '1,2,3';
$this->instance->setTags($value);
$this->assertEquals($value, $this->instance->getTags());
}
/**
* @test
*
* @return void
*/
public function archiveRestrictionCanBeSet(): void
{
$value = 'archive';
$this->instance->setArchiveRestriction($value);
$this->assertEquals($value, $this->instance->getArchiveRestriction());
}
/**
* @test
*
* @return void
*/
public function timeRestrictionCanBeSet(): void
{
$value = '2014-04-01';
$this->instance->setTimeRestriction($value);
$this->assertEquals($value, $this->instance->getTimeRestriction());
}
/**
* @test
*
* @return void
*/
public function timeRestrictionHighCanBeSet(): void
{
$value = '2014-05-01';
$this->instance->setTimeRestrictionHigh($value);
$this->assertEquals($value, $this->instance->getTimeRestrictionHigh());
}
/**
* @test
*
* @return void
*/
public function topNewsRestrictionCanBeSet(): void
{
$value = 1;
$this->instance->setTopNewsRestriction($value);
$this->assertEquals($value, $this->instance->getTopNewsRestriction());
}
/**
* @test
*
* @return void
*/
public function dateFieldCanBeSet(): void
{
$value = 'datetime';
$this->instance->setDateField($value);
$this->assertEquals($value, $this->instance->getDateField());
$value = 'archive';
$this->instance->setDateField($value);
$this->assertEquals($value, $this->instance->getDateField());
$value = 'invalid';
$this->instance->setDateField($value);
$this->assertEquals('', $this->instance->getDateField());
}
/**
* @test
*
* @return void
*/
public function monthCanBeSet(): void
{
$value = 4;
$this->instance->setMonth($value);
$this->assertEquals($value, $this->instance->getMonth());
}
/**
* @test
*
* @return void
*/
public function yearCanBeSet(): void
{
$value = 2014;
$this->instance->setYear($value);
$this->assertEquals($value, $this->instance->getYear());
}
/**
* @test
*
* @return void
*/
public function dayCanBeSet(): void
{
$value = 1;
$this->instance->setDay($value);
$this->assertEquals($value, $this->instance->getDay());
}
/**
* @test
*
* @return void
*/
public function searchFieldsCanBeSet(): void
{
$value = 'field1,field2';
$this->instance->setSearchFields($value);
$this->assertEquals($value, $this->instance->getSearchFields());
}
/**
* @test
*
* @return void
*/
public function searchCanBeSet(): void
{
$value = new Search();
$value->setSubject('fo');
$this->instance->setSearch($value);
$this->assertEquals($value, $this->instance->getSearch());
}
/**
* @test
*
* @return void
*/
public function orderCanBeSet(): void
{
$value = 'order';
$this->instance->setOrder($value);
$this->assertEquals($value, $this->instance->getOrder());
}
/**
* @test
*
* @return void
*/
public function orderByAllowedCanBeSet(): void
{
$value = 'order,order2';
$this->instance->setOrderByAllowed($value);
$this->assertEquals($value, $this->instance->getOrderByAllowed());
}
/**
* @test
*
* @return void
*/
public function topNewsFirstCanBeSet(): void
{
$value = true;
$this->instance->setTopNewsFirst($value);
$this->assertEquals($value, $this->instance->getTopNewsFirst());
}
/**
* @test
*
* @return void
*/
public function storagePageCanBeSet(): void
{
$value = 456;
$this->instance->setStoragePage($value);
$this->assertEquals($value, $this->instance->getStoragePage());
}
/**
* @test
*
* @return void
*/
public function limitCanBeSet(): void
{
$value = 10;
$this->instance->setLimit($value);
$this->assertEquals($value, $this->instance->getLimit());
}
/**
* @test
*
* @return void
*/
public function offsetCanBeSet(): void
{
$value = 20;
$this->instance->setOffset($value);
$this->assertEquals($value, $this->instance->getOffset());
}
/**
* @test
*
* @return void
*/
public function excludeAlreadyDisplayedNewsCanBeSet(): void
{
$value = true;
$this->instance->setExcludeAlreadyDisplayedNews($value);
$this->assertEquals($value, $this->instance->getExcludeAlreadyDisplayedNews());
}
/**
* @test
*
* @return void
*/
public function hideIdListCanBeSet(): void
{
$value = '123,456';
$this->instance->setHideIdList($value);
$this->assertEquals($value, $this->instance->getHideIdList());
}
/**
* @test
*
* @return void
*/
public function actionCanBeSet(): void
{
$value = 'anAction';
$this->instance->setAction($value);
$this->assertEquals($value, $this->instance->getAction());
}
/**
* @test
*
* @return void
*/
public function classCanBeSet(): void
{
$value = 'FooBar';
$this->instance->setClass($value);
$this->assertEquals($value, $this->instance->getClass());
}
/**
* @test
*
* @return void
*/
public function typesCanBeSet(): void
{
$value = ['12', '34'];
$this->instance->setTypes($value);
$this->assertEquals($value, $this->instance->getTypes());
}
}

View File

@@ -0,0 +1,80 @@
<?php
namespace GeorgRinger\News\Tests\Unit\Domain\Model\Dto;
/**
* 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\Dto\Search;
use TYPO3\TestingFramework\Core\BaseTestCase;
/**
* Tests for domains model News
*
*/
class SearchTest extends BaseTestCase
{
/**
* Test if subject can be set
*
* @test
*
* @return void
*/
public function subjectCanBeSet(): void
{
$domainModelInstance = new Search();
$subject = 'Test 123';
$domainModelInstance->setSubject($subject);
$this->assertEquals($subject, $domainModelInstance->getSubject());
}
/**
* Test if fields can be set
*
* @test
*
* @return void
*/
public function fieldsCanBeSet(): void
{
$domainModelInstance = new Search();
$fields = 'field1,field2';
$domainModelInstance->setFields($fields);
$this->assertEquals($fields, $domainModelInstance->getFields());
}
/**
* Test if minimumDate can be set
*
* @test
*
* @return void
*/
public function minimumDateCanBeSet(): void
{
$domainModelInstance = new Search();
$value = '123';
$domainModelInstance->setMinimumDate($value);
$this->assertEquals($value, $domainModelInstance->getMinimumDate());
}
/**
* Test if minimumDate can be set
*
* @test
*
* @return void
*/
public function maximumDateCanBeSet(): void
{
$domainModelInstance = new Search();
$value = '456';
$domainModelInstance->setMaximumDate($value);
$this->assertEquals($value, $domainModelInstance->getMaximumDate());
}
}

View File

@@ -0,0 +1,109 @@
<?php
namespace GeorgRinger\News\Tests\Unit\Domain\Model;
/**
* 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\FileReference;
use TYPO3\TestingFramework\Core\BaseTestCase;
/**
* Tests for GeorgRinger\News\Domain\Model\FileReference
*/
class FileReferenceTest extends BaseTestCase
{
/**
* Test if fileUid can be set
*
* @test
*
* @return void
*/
public function fileUidCanBeSet(): void
{
$domainModelInstance = new FileReference();
$value = 781;
$domainModelInstance->setFileUid($value);
$this->assertEquals($value, $domainModelInstance->getFileUid());
}
/**
* Test if alternative can be set
*
* @test
*
* @return void
*/
public function alternativeBeSet(): void
{
$domainModelInstance = new FileReference();
$value = 'Test 123';
$domainModelInstance->setAlternative($value);
$this->assertEquals($value, $domainModelInstance->getAlternative());
}
/**
* Test if description can be set
*
* @test
*
* @return void
*/
public function descriptionBeSet(): void
{
$domainModelInstance = new FileReference();
$value = 'Test 123';
$domainModelInstance->setDescription($value);
$this->assertEquals($value, $domainModelInstance->getDescription());
}
/**
* Test if link can be set
*
* @test
*
* @return void
*/
public function linkBeSet(): void
{
$domainModelInstance = new FileReference();
$value = 'Test 123';
$domainModelInstance->setLink($value);
$this->assertEquals($value, $domainModelInstance->getLink());
}
/**
* Test if title can be set
*
* @test
*
* @return void
*/
public function titleBeSet(): void
{
$domainModelInstance = new FileReference();
$value = 'Test 123';
$domainModelInstance->setTitle($value);
$this->assertEquals($value, $domainModelInstance->getTitle());
}
/**
* Test if showInPreview can be set
*
* @test
*
* @return void
*/
public function showInPreviewBeSet(): void
{
$domainModelInstance = new FileReference();
$value = 2;
$domainModelInstance->setShowinpreview($value);
$this->assertEquals($value, $domainModelInstance->getShowinpreview());
}
}

View File

@@ -0,0 +1,103 @@
<?php
namespace GeorgRinger\News\Tests\Unit\Domain\Model;
/**
* 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\Link;
use TYPO3\TestingFramework\Core\BaseTestCase;
/**
* Tests for domains model Link
*/
class LinkTest extends BaseTestCase
{
/**
* @var Link
*/
protected $linkDomainModelInstance;
/**
* Setup
*
*/
protected function setUp(): void
{
$this->linkDomainModelInstance = new Link();
}
/**
* Test if title can be set
*
* @test
*
* @return void
*/
public function titleCanBeSet(): void
{
$title = 'File title';
$this->linkDomainModelInstance->setTitle($title);
$this->assertEquals($title, $this->linkDomainModelInstance->getTitle());
}
/**
* Test if crdate can be set
*
* @test
*
* @return void
*/
public function crdateCanBeSet(): void
{
$time = new \DateTime();
$this->linkDomainModelInstance->setCrdate($time);
$this->assertEquals($time, $this->linkDomainModelInstance->getCrdate());
}
/**
* Test if tstamp can be set
*
* @test
*
* @return void
*/
public function tstampCanBeSet(): void
{
$time = new \DateTime();
$this->linkDomainModelInstance->setTstamp($time);
$this->assertEquals($time, $this->linkDomainModelInstance->getTstamp());
}
/**
* Test if description can be set
*
* @test
*
* @return void
*/
public function descriptionCanBeSet(): void
{
$description = 'This is a description';
$this->linkDomainModelInstance->setDescription($description);
$this->assertEquals($description, $this->linkDomainModelInstance->getDescription());
}
/**
* Test if uri can be set
*
* @test
*
* @return void
*/
public function uriCanBeSet(): void
{
$uri = 'http://typo3.org';
$this->linkDomainModelInstance->setUri($uri);
$this->assertEquals($uri, $this->linkDomainModelInstance->getUri());
}
}

View File

@@ -0,0 +1,408 @@
<?php
namespace GeorgRinger\News\Tests\Unit\Domain\Model;
use GeorgRinger\News\Domain\Model\Category;
/**
* 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\FileReference;
use GeorgRinger\News\Domain\Model\Link;
use GeorgRinger\News\Domain\Model\News;
use GeorgRinger\News\Domain\Model\Tag;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
use TYPO3\TestingFramework\Core\BaseTestCase;
/**
* Tests for domains model News
*
*/
class NewsTest extends BaseTestCase
{
/**
* @var News
*/
protected $newsDomainModelInstance;
/**
* Set up framework
*
*/
protected function setUp(): void
{
$this->newsDomainModelInstance = new News();
}
/**
* Test if title can be set
*
* @test
*
* @return void
*/
public function titleCanBeSet(): void
{
$title = 'News title';
$this->newsDomainModelInstance->setTitle($title);
$this->assertEquals($title, $this->newsDomainModelInstance->getTitle());
}
/**
* Test if teaser can be set
*
* @test
*
* @return void
*/
public function teaserCanBeSet(): void
{
$teaser = 'News teaser';
$this->newsDomainModelInstance->setTeaser($teaser);
$this->assertEquals($teaser, $this->newsDomainModelInstance->getTeaser());
}
/**
* Test if bodytext can be set
*
* @test
*
* @return void
*/
public function bodytextCanBeSet(): void
{
$bodytext = 'News bodytext';
$this->newsDomainModelInstance->setBodytext($bodytext);
$this->assertEquals($bodytext, $this->newsDomainModelInstance->getBodytext());
}
/**
* Test if datetime can be set
*
* @test
*
* @return void
*/
public function datetimeCanBeSet(): void
{
$datetime = new \DateTime();
$this->newsDomainModelInstance->setDatetime($datetime);
$this->assertEquals($datetime, $this->newsDomainModelInstance->getDatetime());
}
/**
* Test if archive can be set
*
* @test
*
* @return void
*/
public function archiveCanBeSet(): void
{
$archive = new \DateTime();
$this->newsDomainModelInstance->setArchive($archive);
$this->assertEquals($archive, $this->newsDomainModelInstance->getArchive());
}
/**
* Test if author can be set
*
* @test
*
* @return void
*/
public function authorCanBeSet(): void
{
$author = 'News author';
$this->newsDomainModelInstance->setAuthor($author);
$this->assertEquals($author, $this->newsDomainModelInstance->getAuthor());
}
/**
* Test if emailadr can be set
*
* @test
*
* @return void
*/
public function authorEmailCanBeSet(): void
{
$authorEmail = 'author@news.org';
$this->newsDomainModelInstance->setAuthorEmail($authorEmail);
$this->assertEquals($authorEmail, $this->newsDomainModelInstance->getAuthorEmail());
}
/**
* Test if type can be set
*
* @test
*
* @return void
*/
public function typeCanBeSet(): void
{
$type = 123;
$this->newsDomainModelInstance->setType($type);
$this->assertEquals($type, $this->newsDomainModelInstance->getType());
}
/**
* Test if keyword can be set
*
* @test
*
* @return void
*/
public function keywordsCanBeSet(): void
{
$keywords = 'news1 keyword, news keyword';
$this->newsDomainModelInstance->setKeywords($keywords);
$this->assertEquals($keywords, $this->newsDomainModelInstance->getKeywords());
}
/**
* Test if internalurl can be set
*
* @test
*
* @return void
*/
public function internalurlCanBeSet(): void
{
$internalurl = 'http://foo.org/';
$this->newsDomainModelInstance->setInternalurl($internalurl);
$this->assertEquals($internalurl, $this->newsDomainModelInstance->getInternalurl());
}
/**
* Test if externalurl can be set
*
* @test
*
* @return void
*/
public function externalurlCanBeSet(): void
{
$externalurl = 'http://bar.org/';
$this->newsDomainModelInstance->setExternalurl($externalurl);
$this->assertEquals($externalurl, $this->newsDomainModelInstance->getExternalurl());
}
/**
* Test if topnews can be set
*
* @test
*
* @return void
*/
public function isttopnewsCanBeSet(): void
{
$istopnews = true;
$this->newsDomainModelInstance->setIstopnews($istopnews);
$this->assertEquals($istopnews, $this->newsDomainModelInstance->getIstopnews());
}
/**
* Test if editlock can be set
*
* @test
*
* @return void
*/
public function editlockCanBeSet(): void
{
$editlock = 2;
$this->newsDomainModelInstance->setEditlock($editlock);
$this->assertEquals($editlock, $this->newsDomainModelInstance->getEditlock());
}
/**
* Test if importid can be set
*
* @test
*
* @return void
*/
public function importIdCanBeSet(): void
{
$importId = 2;
$this->newsDomainModelInstance->setImportId($importId);
$this->assertEquals($importId, $this->newsDomainModelInstance->getImportId());
}
/**
* Test if importSource can be set
*
* @test
*
* @return void
*/
public function importSourceCanBeSet(): void
{
$importSource = 'test';
$this->newsDomainModelInstance->setImportSource($importSource);
$this->assertEquals($importSource, $this->newsDomainModelInstance->getImportSource());
}
/**
* Test if sorting can be set
*
* @test
*
* @return void
*/
public function sortingCanBeSet(): void
{
$sorting = 2;
$this->newsDomainModelInstance->setSorting($sorting);
$this->assertEquals($sorting, $this->newsDomainModelInstance->getSorting());
}
/**
* Test if tag can be set
*
* @test
*
* @return void
*/
public function tagsCanBeSet(): void
{
$tags = new ObjectStorage();
$tag = new Tag();
$tag->setTitle('Tag');
$tags->attach($tag);
$this->newsDomainModelInstance->setTags($tags);
$this->assertEquals($tags, $this->newsDomainModelInstance->getTags());
}
/**
* Test if content elements can be set
*
* @test
*
* @return void
*/
public function contentElementsCanBeSet(): void
{
$ce = new ObjectStorage();
$item = new \SplObjectStorage();
$ce->attach($item);
$this->newsDomainModelInstance->setContentElements($ce);
$this->assertEquals($ce, $this->newsDomainModelInstance->getContentElements());
}
/**
* Test if category can be set
*
* @test
*
* @return void
*/
public function categoryCanBeSet(): void
{
$category = new Category();
$category->setTitle('fo');
$categories = new ObjectStorage();
$categories->attach($category);
$this->newsDomainModelInstance->setCategories($categories);
$this->assertEquals($categories, $this->newsDomainModelInstance->getCategories());
}
/**
* Test if related links can be set
*
* @test
*
* @return void
*/
public function relatedLinksCanBeSet(): void
{
$link = new Link();
$link->setTitle('fo');
$related = new ObjectStorage();
$related->attach($link);
$this->newsDomainModelInstance->setRelatedLinks($related);
$this->assertEquals($related, $this->newsDomainModelInstance->getRelatedLinks());
}
/**
* @test
*
* @return void
*/
public function falMediaCanBeAdded(): void
{
$mediaItem = new FileReference();
$mediaItem->setTitle('Fo');
$news = new News();
$news->addFalMedia($mediaItem);
$this->assertEquals($news->getFalMedia()->current(), $mediaItem);
$this->assertEquals($news->getMedia()->current(), $mediaItem);
}
/**
* @test
*
* @return void
*/
public function falMediaPreviewsAreReturned(): void
{
$news = new News();
$mockedElement1 = $this->getAccessibleMock(FileReference::class, ['getProperty']);
$mockedElement1->_set('uid', 1);
$mockedElement1->_set('showinpreview', 1);
$mockedElement1->expects($this->any())->method('getProperty')->will($this->returnValue(1));
$mediaItem1 = new FileReference();
$mediaItem1->_setProperty('originalResource', $mockedElement1);
$mediaItem1->_setProperty('uid', 1);
$news->addFalMedia($mediaItem1);
$mockedElement2 = $this->getAccessibleMock(FileReference::class, ['getProperty']);
$mockedElement2->_set('uid', 2);
$mockedElement2->_set('showinpreview', 0);
$mockedElement2->expects($this->any())->method('getProperty')->will($this->returnValue(0));
$mediaItem2 = new FileReference();
$mediaItem2->_setProperty('originalResource', $mockedElement2);
$mediaItem2->_setProperty('uid', 2);
$news->addFalMedia($mediaItem2);
$mockedElement3 = $this->getAccessibleMock(FileReference::class, ['getProperty']);
$mockedElement3->_set('uid', 3);
$mockedElement3->_set('showinpreview', 1);
$mockedElement3->expects($this->any())->method('getProperty')->will($this->returnValue(1));
$mediaItem3 = new FileReference();
$mediaItem3->_setProperty('uid', 3);
$mediaItem3->_setProperty('originalResource', $mockedElement3);
$news->addFalMedia($mediaItem3);
$mockedElement4 = $this->getAccessibleMock(FileReference::class, ['getProperty']);
$mockedElement4->_set('uid', 4);
$mockedElement4->_set('showinpreview', 2);
$mockedElement4->expects($this->any())->method('getProperty')->will($this->returnValue(2));
$mediaItem4 = new FileReference();
$mediaItem4->_setProperty('uid', 4);
$mediaItem4->_setProperty('originalResource', $mockedElement4);
$news->addFalMedia($mediaItem4);
$this->assertEquals(3, count($news->getMediaPreviews()));
$this->assertEquals(3, count($news->getMediaNonPreviews()));
$this->assertEquals(4, count($news->getFalMedia()));
$this->assertEquals(4, count($news->getMedia()));
}
}

View File

@@ -0,0 +1,76 @@
<?php
namespace GeorgRinger\News\Tests\Unit\Domain\Model;
/**
* 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\Tag;
use TYPO3\TestingFramework\Core\BaseTestCase;
/**
* Tests for domains model Tag
*
*/
class TagTest extends BaseTestCase
{
/**
* @var Tag
*/
protected $tagDomainModelInstance;
/**
* Setup
*
*/
protected function setUp(): void
{
$this->tagDomainModelInstance = new Tag();
}
/**
* Test if title can be set
*
* @test
*
* @return void
*/
public function titleCanBeSet(): void
{
$title = 'Tag title';
$this->tagDomainModelInstance->setTitle($title);
$this->assertEquals($title, $this->tagDomainModelInstance->getTitle());
}
/**
* Test if crdate can be set
*
* @test
*
* @return void
*/
public function crdateCanBeSet(): void
{
$time = new \DateTime('now');
$this->tagDomainModelInstance->setCrdate($time);
$this->assertEquals($time, $this->tagDomainModelInstance->getCrdate());
}
/**
* Test if tstamp can be set
*
* @test
*
* @return void
*/
public function tstampCanBeSet(): void
{
$time = new \DateTime('now');
$this->tagDomainModelInstance->setTstamp($time);
$this->assertEquals($time, $this->tagDomainModelInstance->getTstamp());
}
}

View File

@@ -0,0 +1,322 @@
<?php
namespace GeorgRinger\News\Tests\Unit\Domain\Model;
/**
* 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\TtContent;
use TYPO3\TestingFramework\Core\BaseTestCase;
/**
* Tests for tt_content model
*
*/
class TtContentTest extends BaseTestCase
{
/**
* @var TtContent
*/
protected $ttContentDomainModelInstance;
/**
* Setup
*
*/
protected function setUp(): void
{
$this->ttContentDomainModelInstance = new TtContent();
}
/**
* @test
*
* @return void
*/
public function crdateCanBeSet(): void
{
$fieldValue = new \DateTime();
$this->ttContentDomainModelInstance->setCrdate($fieldValue);
$this->assertEquals($fieldValue, $this->ttContentDomainModelInstance->getCrdate());
}
/**
* @test
*
* @return void
*/
public function tstampCanBeSet(): void
{
$fieldValue = new \DateTime();
$this->ttContentDomainModelInstance->setTstamp($fieldValue);
$this->assertEquals($fieldValue, $this->ttContentDomainModelInstance->getTstamp());
}
/**
* @test
*
* @return void
*/
public function cTypeCanBeSet(): void
{
$fieldValue = 'fo123';
$this->ttContentDomainModelInstance->setCType($fieldValue);
$this->assertEquals($fieldValue, $this->ttContentDomainModelInstance->getCType());
}
/**
* @test
*
* @return void
*/
public function headerCanBeSet(): void
{
$fieldValue = 'fo123';
$this->ttContentDomainModelInstance->setHeader($fieldValue);
$this->assertEquals($fieldValue, $this->ttContentDomainModelInstance->getHeader());
}
/**
* @test
*
* @return void
*/
public function headerPositionCanBeSet(): void
{
$fieldValue = 'fo123';
$this->ttContentDomainModelInstance->setHeaderPosition($fieldValue);
$this->assertEquals($fieldValue, $this->ttContentDomainModelInstance->getHeaderPosition());
}
/**
* @test
*
* @return void
*/
public function bodytextCanBeSet(): void
{
$fieldValue = 'fo123';
$this->ttContentDomainModelInstance->setBodytext($fieldValue);
$this->assertEquals($fieldValue, $this->ttContentDomainModelInstance->getBodytext());
}
/**
* @test
*
* @return void
*/
public function colPosCanBeSet(): void
{
$fieldValue = 1;
$this->ttContentDomainModelInstance->setColPos($fieldValue);
$this->assertEquals($fieldValue, $this->ttContentDomainModelInstance->getColPos());
}
/**
* @test
*
* @return void
*/
public function imageCanBeSet(): void
{
$fieldValue = 'fo123';
$this->ttContentDomainModelInstance->setImage($fieldValue);
$this->assertEquals($fieldValue, $this->ttContentDomainModelInstance->getImage());
}
/**
* @test
*
* @return void
*/
public function imageWidthCanBeSet(): void
{
$fieldValue = 123;
$this->ttContentDomainModelInstance->setImagewidth($fieldValue);
$this->assertEquals($fieldValue, $this->ttContentDomainModelInstance->getImagewidth());
}
/**
* @test
*
* @return void
*/
public function imageOrientCanBeSet(): void
{
$fieldValue = 3;
$this->ttContentDomainModelInstance->setImageorient($fieldValue);
$this->assertEquals($fieldValue, $this->ttContentDomainModelInstance->getImageorient());
}
/**
* @test
*
* @return void
*/
public function imageCaptionCanBeSet(): void
{
$fieldValue = 'Test123';
$this->ttContentDomainModelInstance->setImagecaption($fieldValue);
$this->assertEquals($fieldValue, $this->ttContentDomainModelInstance->getImagecaption());
}
/**
* @test
*
* @return void
*/
public function imageColsCanBeSet(): void
{
$fieldValue = 123;
$this->ttContentDomainModelInstance->setImagecols($fieldValue);
$this->assertEquals($fieldValue, $this->ttContentDomainModelInstance->getImagecols());
}
/**
* @test
*
* @return void
*/
public function imageBorderCanBeSet(): void
{
$fieldValue = 123;
$this->ttContentDomainModelInstance->setImageborder($fieldValue);
$this->assertEquals($fieldValue, $this->ttContentDomainModelInstance->getImageborder());
}
/**
* @test
*
* @return void
*/
public function mediaCanBeSet(): void
{
$fieldValue = 'Test 123';
$this->ttContentDomainModelInstance->setMedia($fieldValue);
$this->assertEquals($fieldValue, $this->ttContentDomainModelInstance->getMedia());
}
/**
* @test
*
* @return void
*/
public function layoutCanBeSet(): void
{
$fieldValue = 'Test 123';
$this->ttContentDomainModelInstance->setLayout($fieldValue);
$this->assertEquals($fieldValue, $this->ttContentDomainModelInstance->getLayout());
}
/**
* @test
*
* @return void
*/
public function colsCanBeSet(): void
{
$fieldValue = 123;
$this->ttContentDomainModelInstance->setCols($fieldValue);
$this->assertEquals($fieldValue, $this->ttContentDomainModelInstance->getCols());
}
/**
* @test
*
* @return void
*/
public function subheaderCanBeSet(): void
{
$fieldValue = 'Test 123';
$this->ttContentDomainModelInstance->setSubheader($fieldValue);
$this->assertEquals($fieldValue, $this->ttContentDomainModelInstance->getSubheader());
}
/**
* @test
*
* @return void
*/
public function headerLinkCanBeSet(): void
{
$fieldValue = 'Test 123';
$this->ttContentDomainModelInstance->setHeaderLink($fieldValue);
$this->assertEquals($fieldValue, $this->ttContentDomainModelInstance->getHeaderLink());
}
/**
* @test
*
* @return void
*/
public function imageLinkCanBeSet(): void
{
$fieldValue = 'Test 123';
$this->ttContentDomainModelInstance->setImageLink($fieldValue);
$this->assertEquals($fieldValue, $this->ttContentDomainModelInstance->getImageLink());
}
/**
* @test
*
* @return void
*/
public function imageZoomCanBeSet(): void
{
$fieldValue = 'Test 123';
$this->ttContentDomainModelInstance->setImageZoom($fieldValue);
$this->assertEquals($fieldValue, $this->ttContentDomainModelInstance->getImageZoom());
}
/**
* @test
*
* @return void
*/
public function altTextCanBeSet(): void
{
$fieldValue = 'Test 123';
$this->ttContentDomainModelInstance->setAltText($fieldValue);
$this->assertEquals($fieldValue, $this->ttContentDomainModelInstance->getAltText());
}
/**
* @test
*
* @return void
*/
public function titleTextCanBeSet(): void
{
$fieldValue = 'Test 123';
$this->ttContentDomainModelInstance->setTitleText($fieldValue);
$this->assertEquals($fieldValue, $this->ttContentDomainModelInstance->getTitleText());
}
/**
* @test
*
* @return void
*/
public function headerLayoutCanBeSet(): void
{
$fieldValue = 'Test 123';
$this->ttContentDomainModelInstance->setHeaderLayout($fieldValue);
$this->assertEquals($fieldValue, $this->ttContentDomainModelInstance->getHeaderLayout());
}
/**
* @test
*
* @return void
*/
public function listTypeCanBeSet(): void
{
$fieldValue = 'Test 123';
$this->ttContentDomainModelInstance->setListType($fieldValue);
$this->assertEquals($fieldValue, $this->ttContentDomainModelInstance->getListType());
}
}

View File

@@ -0,0 +1,112 @@
<?php
namespace GeorgRinger\News\Tests\Unit\Domain\Repository;
/**
* 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\Repository\CategoryRepository;
use TYPO3\TestingFramework\Core\BaseTestCase;
/**
* Tests for domain repository categoryRepository
*
*/
class CategoryRepositoryTest extends BaseTestCase
{
/**
* Test if category ids are replaced
*
* @param array $expectedResult
* @param array $given
*
* @test
*
* @dataProvider categoryIdsAreCorrectlyReplacedDataProvider
*
* @return void
*/
public function categoryIdsAreCorrectlyReplaced($expectedResult, $given): void
{
$mockTemplateParser = $this->getAccessibleMock(CategoryRepository::class, ['dummy'], [], '', false);
$result = $mockTemplateParser->_call('replaceCategoryIds', $given['idList'], $given['toBeChanged']);
$this->assertEquals($expectedResult, $result);
}
/**
* Data provider
*
* @return array
*/
public function categoryIdsAreCorrectlyReplacedDataProvider(): array
{
return [
'emptyRows' => [
[1, 2, 3],
[
'idList' => [1, 2, 3],
'toBeChanged' => []
]
],
'oneIdReplaced' => [
[1, 5, 3],
[
'idList' => [1, 2, 3],
'toBeChanged' => [
0 => [
'l10n_parent' => 2,
'uid' => 5,
]
]
]
],
'noIdReplaced' => [
[1, 2, 3],
[
'idList' => [1, 2, 3],
'toBeChanged' => [
0 => [
'l10n_parent' => 6,
'uid' => 5,
],
1 => [
'l10n_parent' => 8,
'uid' => 10,
]
]
]
],
'allIdsReplaced' => [
[4, 5, 6],
[
'idList' => [1, 2, 3],
'toBeChanged' => [
[
'l10n_parent' => 2,
'uid' => 5,
],
[
'l10n_parent' => 1,
'uid' => 4,
],
[
'l10n_parent' => 3,
'uid' => 6,
],
[
'l10n_parent' => 8,
'uid' => 10,
]
]
]
],
];
}
}

View File

@@ -0,0 +1,163 @@
<?php
namespace GeorgRinger\News\Tests\Unit\Domain\Repository;
/**
* 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\Dto\NewsDemand;
use GeorgRinger\News\Domain\Model\Dto\Search;
use GeorgRinger\News\Domain\Repository\NewsRepository;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
use TYPO3\TestingFramework\Core\BaseTestCase;
use UnexpectedValueException;
/**
* Tests for domain repository newsRepository
*
*
*/
class NewsRepositoryTest extends BaseTestCase
{
/** @var \GeorgRinger\News\Domain\Repository\NewsRepository|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface */
protected $mockedNewsRepository;
public function setup(): void
{
$this->mockedNewsRepository = $this->getAccessibleMock(NewsRepository::class, ['getQueryBuilder'], [], '', false);
$mockedQueryBuilder = $this->getAccessibleMock(QueryBuilder::class, ['escapeStrForLike', 'createNamedParameter'], [], '', false);
$this->mockedNewsRepository->expects($this->any())->method('getQueryBuilder')->withAnyParameters()->will($this->returnValue($mockedQueryBuilder));
}
/**
* @test
*
* @return void
*/
public function getSearchConstraintsThrowsErrorIfNoSearchFieldIsGiven(): void
{
$this->expectException(UnexpectedValueException::class);
$mockedQuery = $this->getMockBuilder(QueryInterface::class)->getMock();
$search = new Search();
$search->setSubject('fo');
$demand = new NewsDemand();
$demand->setSearch($search);
$this->mockedNewsRepository->_call('getSearchConstraints', $mockedQuery, $demand);
}
//
/**
* @test
*
* @return void
*/
public function getSearchConstraintsThrowsErrorIfNoDateFieldForMaximumDateIsGiven(): void
{
$this->expectException(UnexpectedValueException::class);
$mockedQuery = $this->getMockBuilder(QueryInterface::class)->getMock();
$search = new Search();
$search->setMaximumDate('2014-04-01');
$demand = new NewsDemand();
$demand->setSearch($search);
$this->mockedNewsRepository->_call('getSearchConstraints', $mockedQuery, $demand);
}
//
/**
* @test
*
* @return void
*/
public function getSearchConstraintsThrowsErrorIfNoDateFieldForMinimumDateIsGiven(): void
{
$this->expectException(UnexpectedValueException::class);
$mockedQuery = $this->getMockBuilder(QueryInterface::class)->getMock();
$search = new Search();
$search->setDateField('');
$search->setMinimumDate('2014-04-01');
$demand = new NewsDemand();
$demand->setSearch($search);
$this->mockedNewsRepository->_call('getSearchConstraints', $mockedQuery, $demand);
}
//
/**
* @test
*
* @return void
*/
public function emptyConstraintIsReturnedForEmptySearchDemand(): void
{
$mockedQuery = $this->getMockBuilder(QueryInterface::class)->getMock();
$demand = new NewsDemand();
$demand->setSearch(null);
$result = $this->mockedNewsRepository->_call('getSearchConstraints', $mockedQuery, $demand);
$this->assertEmpty($result);
}
/**
* @test
*
* @return void
*/
public function constraintsAreReturnedForSearchSubject(): void
{
$mockedQuery = $this->getMockBuilder(QueryInterface::class)->getMock();
$search = new Search();
$search->setSubject('Lorem');
$search->setFields('title,fo');
$demand = new NewsDemand();
$demand->setSearch($search);
$result = $this->mockedNewsRepository->_call('getSearchConstraints', $mockedQuery, $demand);
$this->assertEquals(1, count($result));
}
/**
* @test
*
* @return void
*/
public function constraintsAreReturnedForDateFields(): void
{
$mockedQuery = $this->getMockBuilder(QueryInterface::class)->getMock();
$search = new Search();
$search->setMinimumDate('2014-01-01');
$search->setDateField('datetime');
$demand = new NewsDemand();
$demand->setSearch($search);
$result = $this->mockedNewsRepository->_call('getSearchConstraints', $mockedQuery, $demand);
$this->assertEquals(1, count($result));
$search->setMaximumDate('2015-01-01');
$demand->setSearch($search);
$result = $this->mockedNewsRepository->_call('getSearchConstraints', $mockedQuery, $demand);
$this->assertEquals(2, count($result));
$search->setMaximumDate('xyz');
$demand->setSearch($search);
$result = $this->mockedNewsRepository->_call('getSearchConstraints', $mockedQuery, $demand);
$this->assertEquals(1, count($result));
}
}

View File

@@ -0,0 +1,269 @@
<?php
namespace GeorgRinger\News\Tests\Unit\Hooks;
/**
* 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\Hooks\PageLayoutView;
use GeorgRinger\News\Utility\TemplateLayout;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\TestingFramework\Core\BaseTestCase;
/**
* Tests for PageLayoutView
*
*/
class PageLayoutViewTest extends BaseTestCase
{
/** @var PageLayoutView|\PHPUnit\Framework\MockObject\MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface */
protected $pageLayoutView;
public function setup(): void
{
parent::setUp();
$languageService = $this->getAccessibleMock(LanguageService::class, ['sl'], [], '', false, false);
$languageService->expects($this->any())->method('sL')->will($this->returnValue('any language'));
$GLOBALS['LANG'] = $languageService;
$this->pageLayoutView = $this->getAccessibleMock(PageLayoutView::class, ['dummy'], [], '', false);
$this->pageLayoutView->_set('databaseConnection', $this->getMockBuilder('TYPO3\CMS\\Core\\Utility\\GeneralUtility\\DatabaseConnection')->setMethods(['exec_SELECTquery', 'exec_SELECTgetRows'])->getMock());
}
/**
* @test
*
* @return void
*/
public function getArchiveSettingAddsValueIfFilled(): void
{
$flexform = [];
$this->addContentToFlexform($flexform, 'settings.archiveRestriction', 'something');
$this->pageLayoutView->_set('flexformData', $flexform);
$this->pageLayoutView->_call('getArchiveSettings');
$this->assertEquals(count($this->pageLayoutView->_get('tableData')), 1);
}
/**
* @test
*
* @return void
*/
public function getDetailPidSettingAddsValueIfFilled(): void
{
$flexform = [];
$this->addContentToFlexform($flexform, 'settings.detailPid', '9999999999', 'additional');
$this->pageLayoutView->_set('flexformData', $flexform);
$this->pageLayoutView->_call('getDetailPidSetting');
$this->assertEquals(count($this->pageLayoutView->_get('tableData')), 1);
}
/**
* @test
*
* @return void
*/
public function getTagRestrictionSettingAddsValueIfFilled(): void
{
$flexform = [];
$this->addContentToFlexform($flexform, 'settings.tags', '9999999999', 'additional');
$this->pageLayoutView->_set('flexformData', $flexform);
$this->pageLayoutView->_call('getTagRestrictionSetting');
$this->assertEquals(count($this->pageLayoutView->_get('tableData')), 1);
}
/**
* @test
*
* @return void
*/
public function getListPidSettingAddsValueIfFilled(): void
{
$flexform = [];
$this->addContentToFlexform($flexform, 'settings.listPid', '9999999999', 'additional');
$this->pageLayoutView->_set('flexformData', $flexform);
$this->pageLayoutView->_call('getListPidSetting');
$this->assertEquals(count($this->pageLayoutView->_get('tableData')), 1);
}
/**
* @test
*
* @return void
*/
public function getOrderBySettingAddsValueIfFilled(): void
{
$flexform = [];
$this->addContentToFlexform($flexform, 'settings.orderBy', 'fo');
$this->pageLayoutView->_set('flexformData', $flexform);
$this->pageLayoutView->_call('getOrderSettings');
$this->assertEquals(count($this->pageLayoutView->_get('tableData')), 1);
}
/**
* @test
*
* @return void
*/
public function getOrderDirectionSettingAddsValueIfFilled(): void
{
$flexform = [];
$this->addContentToFlexform($flexform, 'settings.orderDirection', 'asc');
$this->assertEquals($this->pageLayoutView->_call('getOrderDirectionSetting'), '');
$this->pageLayoutView->_set('flexformData', $flexform);
$out = $this->pageLayoutView->_call('getOrderDirectionSetting');
$this->assertEquals((strlen($out) > 1), true);
}
/**
* @test
*
* @return void
*/
public function getTopNewsFirstSettingAddsValueIfFilled(): void
{
$flexform = [];
$this->addContentToFlexform($flexform, 'settings.topNewsFirst', '1', 'additional');
$this->assertEquals($this->pageLayoutView->_call('getTopNewsFirstSetting'), '');
$this->pageLayoutView->_set('flexformData', $flexform);
$out = $this->pageLayoutView->_call('getTopNewsFirstSetting');
$this->assertEquals((strlen($out) > 1), true);
}
/**
* @test
*
* @return void
*/
public function getOffsetLimitSettingsAddsValueIfFilled(): void
{
$flexform = [];
$this->addContentToFlexform($flexform, 'settings.offset', '1', 'additional');
$this->pageLayoutView->_set('flexformData', $flexform);
$this->pageLayoutView->_call('getOffsetLimitSettings');
$this->assertEquals(count($this->pageLayoutView->_get('tableData')), 1);
$this->addContentToFlexform($flexform, 'settings.limit', '1', 'additional');
$this->pageLayoutView->_set('flexformData', $flexform);
$this->pageLayoutView->_call('getOffsetLimitSettings');
$this->assertEquals(count($this->pageLayoutView->_get('tableData')), 2);
$this->addContentToFlexform($flexform, 'settings.hidePagination', '0', 'additional');
$this->pageLayoutView->_set('flexformData', $flexform);
$this->pageLayoutView->_call('getOffsetLimitSettings');
$this->assertEquals(count($this->pageLayoutView->_get('tableData')), 2);
$this->addContentToFlexform($flexform, 'settings.hidePagination', '1', 'additional');
$this->pageLayoutView->_set('flexformData', $flexform);
$this->pageLayoutView->_call('getOffsetLimitSettings');
$this->assertEquals(count($this->pageLayoutView->_get('tableData')), 3);
}
/**
* @test
*
* @return void
*/
public function getDateMenuSettingsAddsValueIfFilled(): void
{
$flexform = [];
$this->addContentToFlexform($flexform, 'settings.dateField', 'field');
$this->pageLayoutView->_set('flexformData', $flexform);
$this->pageLayoutView->_call('getDateMenuSettings');
$this->assertEquals(count($this->pageLayoutView->_get('tableData')), 1);
}
/**
* @test
*
* @return void
*/
public function getTimeRestrictionSettingAddsValueIfFilled(): void
{
$flexform = [];
$this->addContentToFlexform($flexform, 'settings.timeRestriction', 'fo');
$this->pageLayoutView->_set('flexformData', $flexform);
$this->pageLayoutView->_call('getTimeRestrictionSetting');
$this->assertEquals(count($this->pageLayoutView->_get('tableData')), 1);
$this->addContentToFlexform($flexform, 'settings.timeRestrictionHigh', 'bar');
$this->pageLayoutView->_set('flexformData', $flexform);
$this->pageLayoutView->_call('getTimeRestrictionSetting');
$this->assertEquals(count($this->pageLayoutView->_get('tableData')), 2);
}
/**
* @test
*
* @return void
*/
public function getTemplateLayoutSettingsAddsValueIfFilled(): void
{
$flexform = [];
$mockedTemplateLayout = $this->getAccessibleMock(TemplateLayout::class, ['getAvailableTemplateLayouts']);
$mockedTemplateLayout->expects($this->once())->method('getAvailableTemplateLayouts')->will($this->returnValue([['bar', 'fo']]));
$this->addContentToFlexform($flexform, 'settings.templateLayout', 'fo', 'template');
$this->pageLayoutView->_set('flexformData', $flexform);
$this->pageLayoutView->_set('templateLayoutsUtility', $mockedTemplateLayout);
$this->pageLayoutView->_call('getTemplateLayoutSettings', 1);
$this->assertEquals(count($this->pageLayoutView->_get('tableData')), 1);
}
/**
* @test
*
* @return void
*/
public function getOverrideDemandSettingsAddsValueIfFilled(): void
{
$flexform = [];
$this->addContentToFlexform($flexform, 'settings.disableOverrideDemand', '1', 'additional');
$this->pageLayoutView->_set('flexformData', $flexform);
$this->pageLayoutView->_call('getOverrideDemandSettings');
$this->assertEquals(count($this->pageLayoutView->_get('tableData')), 1);
}
/**
* Add content to given flexform
*
* @param array $flexform configuration
* @param string $key key of field
* @param string $value value of field
* @param string $sheet name of sheet
*
* @return void
*/
protected function addContentToFlexform(array &$flexform, $key, $value, $sheet = 'sDEF'): void
{
$flexform = [
'data' => [
$sheet => [
'lDEF' => [
$key => [
'vDEF' => $value
]
]
]
]
];
}
}

View File

@@ -0,0 +1,59 @@
<?php
namespace GeorgRinger\News\Tests\Unit\Service;
/**
* 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\Service\CategoryService;
use TYPO3\TestingFramework\Core\BaseTestCase;
/**
* Test class for CategoryService
*
*/
class CategoryServiceTest extends BaseTestCase
{
/**
* @test
*
* @dataProvider removeValuesFromStringDataProvider
*
* @return void
*/
public function removeValuesFromString($expected, $given): void
{
$result = CategoryService::removeValuesFromString($given[0], $given[1]);
$this->assertEquals($expected, $result);
}
/**
* Data provider
*
* @return array
*/
public function removeValuesFromStringDataProvider()
{
return [
'simpleExampleWithRemovalAtEnd' => [
'1,2,3,4', ['1,2,3,4,5', '5']
],
'simpleExampleWithMixedRemovals' => [
'1,2,3,4', ['1,7,2,9,3,4', '9,7']
],
'removalIsSame' => [
'', ['1,2,3', '3,2,1']
],
'noRemovalFound' => [
'1,2,3', ['1,2,3', '9,8,7']
],
'noInputGiven' => [
'', ['', '9,8,7']
],
];
}
}

View File

@@ -0,0 +1,51 @@
<?php
namespace GeorgRinger\News\Tests\Unit\Utility;
/**
* 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\Utility\ImportJob;
use TYPO3\TestingFramework\Core\BaseTestCase;
/**
* Test class for ImportJob
*
*/
class ImportJobTest extends BaseTestCase
{
/**
* @test
*
* @return void
*/
public function classCanBeRegistered(): void
{
$importJobInstance = new ImportJob();
$jobs = [];
$this->assertEquals($importJobInstance->getRegisteredJobs(), $jobs);
// Add job #1
$jobs[] = [
'className' => 'Class 1',
'title' => 'Some title',
'description' => ''
];
$importJobInstance->register('Class 1', 'Some title', '');
$this->assertEquals($importJobInstance->getRegisteredJobs(), $jobs);
// Add job #2
$jobs[] = [
'className' => 'Class 2',
'title' => '',
'description' => 'Some description'
];
$importJobInstance->register('Class 2', '', 'Some description');
$this->assertEquals($importJobInstance->getRegisteredJobs(), $jobs);
}
}

View File

@@ -0,0 +1,113 @@
<?php
namespace GeorgRinger\News\Tests\Unit\Utility;
/**
* 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\Utility\TemplateLayout;
use TYPO3\TestingFramework\Core\BaseTestCase;
/**
* TemplateLayout utility class unit tests
*/
class TemplateLayoutTest extends BaseTestCase
{
/**
* @test
*
* @return void
*/
public function templatesFoundInTypo3ConfVars(): void
{
$GLOBALS['TYPO3_CONF_VARS']['EXT']['news']['templateLayouts'] = [
0 => [
0 => 'Layout 1',
1 => 'layout1'
],
1 => [
0 => 'Layout 2',
1 => 'layout2'
],
];
$templateLayoutUtility = $this->getAccessibleMock(TemplateLayout::class, ['getTemplateLayoutsFromTsConfig']);
$templateLayoutUtility->expects($this->once())->method('getTemplateLayoutsFromTsConfig')->will($this->returnValue([]));
$templateLayouts = $templateLayoutUtility->_call('getAvailableTemplateLayouts', 1);
$this->assertSame($GLOBALS['TYPO3_CONF_VARS']['EXT']['news']['templateLayouts'], $templateLayouts);
}
/**
* @test
*
* @return void
*/
public function templatesFoundInPageTsConfig(): void
{
$tsConfigArray = [
'layout1' => 'Layout 1',
'layout2' => 'Layout 2',
];
$result = [
0 => [
0 => 'Layout 1',
1 => 'layout1'
],
1 => [
0 => 'Layout 2',
1 => 'layout2'
],
];
// clear TYPO3_CONF_VARS
unset($GLOBALS['TYPO3_CONF_VARS']['EXT']['news']['templateLayouts']);
$templateLayoutUtility = $this->getAccessibleMock(TemplateLayout::class, ['getTemplateLayoutsFromTsConfig']);
$templateLayoutUtility->expects($this->once())->method('getTemplateLayoutsFromTsConfig')->will($this->returnValue($tsConfigArray));
$templateLayouts = $templateLayoutUtility->_call('getAvailableTemplateLayouts', 1);
$this->assertSame($result, $templateLayouts);
}
/**
* @test
*
* @return void
*/
public function templatesFoundInCombinedResources(): void
{
$tsConfigArray = [
'layout1' => 'Layout 1',
'layout2' => 'Layout 2',
];
$GLOBALS['TYPO3_CONF_VARS']['EXT']['news']['templateLayouts'] = [
0 => [
0 => 'Layout 4',
1 => 'layout4'
],
];
$result = [
0 => [
0 => 'Layout 4',
1 => 'layout4'
],
1 => [
0 => 'Layout 1',
1 => 'layout1'
],
2 => [
0 => 'Layout 2',
1 => 'layout2'
],
];
$templateLayoutUtility = $this->getAccessibleMock(TemplateLayout::class, ['getTemplateLayoutsFromTsConfig']);
$templateLayoutUtility->expects($this->once())->method('getTemplateLayoutsFromTsConfig')->will($this->returnValue($tsConfigArray));
$templateLayouts = $templateLayoutUtility->_call('getAvailableTemplateLayouts', 1);
$this->assertSame($result, $templateLayouts);
}
}

View File

@@ -0,0 +1,273 @@
<?php
namespace GeorgRinger\News\Tests\Unit\Utility;
/**
* 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\Utility\TypoScript;
use TYPO3\TestingFramework\Core\BaseTestCase;
/**
* Test class for TypoScript
*
*/
class TypoScriptTest extends BaseTestCase
{
/**
* @test
*
* @dataProvider overrideWorksDataProvider
*
* @return void
*/
public function overrideWorks($base, $overload, $expected): void
{
$utility = new TypoScript();
$result = $utility->override($base, $overload);
$this->assertEquals($expected, $result);
}
/**
* Data provider
*
* @return array
*/
public function overrideWorksDataProvider()
{
return [
'basic' => [
[
'value_1' => 'fo',
'value_2' => ''
],
[],
[
'value_1' => 'fo',
'value_2' => ''
]
],
'simple' => [
[
'value_1' => 'fo',
'value_2' => ''
],
[
'settings' => [
'value_2' => 'bar',
'overrideFlexformSettingsIfEmpty' => 'value_2'
]
],
[
'value_1' => 'fo',
'value_2' => 'bar'
]
],
'simple2' => [
[
'value_1' => 'fo',
'sub' => [
'sub_1' => 'xy'
]
],
[
'settings' => [
'value_2' => 'bar',
'overrideFlexformSettingsIfEmpty' => 'value_2'
]
],
[
'value_1' => 'fo',
'value_2' => 'bar',
'sub' => [
'sub_1' => 'xy'
]
]
],
'deep' => [
[
'value_1' => 'fo',
'sub_1' => [
'sub_1a' => ''
],
'sub_2' => [
'sub_2a' => 'xy',
],
],
[
'settings' => [
'value_2' => 'bar',
'sub_1' => [
'sub_1a' => 'lorem'
],
'sub_2' => [
'sub_2a' => 'xy',
'sub_2b' => 'abc'
],
'overrideFlexformSettingsIfEmpty' => 'value_2, sub_1.sub_1a,sub_2.sub_2b'
]
],
[
'value_1' => 'fo',
'value_2' => 'bar',
'sub_1' => [
'sub_1a' => 'lorem'
],
'sub_2' => [
'sub_2a' => 'xy',
],
]
],
];
}
/**
* @test
*
* @dataProvider correctValueIsReturnedDataProvider
*
* @return void
*/
public function correctValueIsReturned($path, $expected): void
{
$mockedUtility = $this->getAccessibleMock(TypoScript::class, ['dummy']);
$in = [
'level_1' => [
'in_1' => 'value in 1',
'level_2' => [
'level_3' => [
'in_3' => 'value in 3'
]
]
]
];
$path = explode('.', $path);
$result = $mockedUtility->_call('getValue', $in, $path);
$this->assertEquals($expected, $result);
}
/**
* Data provider
*
* @return array
*/
public function correctValueIsReturnedDataProvider()
{
return [
'valueFoundInDeepLevel' => [
'level_1.level_2.level_3.in_3', 'value in 3'
],
'valueFoundInFirstLevel' => [
'level_1.in_1', 'value in 1'
],
'firstLevelNotFound' => [
'wrong.wronger.stillWrong', null
],
'lastLevelNotFound' => [
'level_1.level_2.level_3.in_Nothing', null
],
];
}
/**
* @test
*
* @dataProvider correctValueIsSetDataProvider
*
* @return void
*/
public function correctValueIsSet($path, $newValue, $expected): void
{
$mockedUtility = $this->getAccessibleMock(TypoScript::class, ['dummy'], [], '', true, false);
$in = [
'level_1' => [
'in_1' => 'value in 1',
'level_2' => [
'level_3' => [
'in_3' => 'value in 3'
]
]
]
];
$path = explode('.', $path);
$result = $mockedUtility->_call('setValue', $in, $path, $newValue);
$this->assertEquals($expected, $result);
}
/**
* Data provider
*
* @return array
*/
public function correctValueIsSetDataProvider()
{
return [
'overrideValueLow' => [
'level_1.in_1',
'new value in 1',
[
'level_1' => [
'in_1' => 'new value in 1',
'level_2' => [
'level_3' => [
'in_3' => 'value in 3'
]
]
]
]
],
'overrideValueDeep' => [
'level_1.level_2.level_3.in_3',
'new value in 3',
[
'level_1' => [
'in_1' => 'value in 1',
'level_2' => [
'level_3' => [
'in_3' => 'new value in 3'
]
]
]
]
],
'newValueDeep' => [
'level_1.level_2.level_3.level_4.level_5.in_5',
'new value in 5',
[
'level_1' => [
'in_1' => 'value in 1',
'level_2' => [
'level_3' => [
'in_3' => 'value in 3',
'level_4' => [
'level_5' => [
'in_5' => 'new value in 5'
]
]
]
]
]
]
],
'overrideArrayWithValue' => [
'level_1.level_2',
'new value as 2',
[
'level_1' => [
'in_1' => 'value in 1',
'level_2' => 'new value as 2'
]
]
],
];
}
}

View File

@@ -0,0 +1,54 @@
<?php
namespace GeorgRinger\News\Tests\Unit\Utility;
/**
* 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\Utility\Url;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\TestingFramework\Core\BaseTestCase;
/**
* Test class for Url
*
*/
class UrlTest extends BaseTestCase
{
/**
* @test
*
* @dataProvider correctUrlIsDeliveredDataProvider
*
* @return void
*/
public function correctUrlIsDelivered($actual, $expected): void
{
$this->assertEquals($expected, Url::prependDomain($actual));
}
/**
* Data provider
*
* @return array
*/
public function correctUrlIsDeliveredDataProvider()
{
$currentDomain = GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
return [
'absoluteUrlIsUsed' => [
$currentDomain . 'index.php?id=123', $currentDomain . 'index.php?id=123'
],
'relativeUrlIsUsed' => [
'index.php?id=123', $currentDomain . 'index.php?id=123'
],
'domainOnlyIsGiven' => [
$currentDomain, $currentDomain
],
];
}
}

View File

@@ -0,0 +1,81 @@
<?php
namespace GeorgRinger\News\Tests\Unit\Utility;
/**
* 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\Utility\Validation;
use TYPO3\TestingFramework\Core\BaseTestCase;
/**
* Tests for Validation
*
*/
class ValidationTest extends BaseTestCase
{
const ALLOWED_FIELDS = 'author,uid,title,teaser,author,tstamp,crdate,datetime,categories.title';
/**
* Test if default file format works
*
* @test
*
* @dataProvider orderDataProvider
*
* @return void
*/
public function testForValidOrdering($expectedFields, $expected): void
{
$validation = Validation::isValidOrdering($expectedFields, self::ALLOWED_FIELDS);
$this->assertEquals($validation, $expected);
}
/**
* @return (bool|string)[][]
*
* @psalm-return array{allowedOrdering: array{0: string, 1: true}, allowedOrderingWithSorting: array{0: string, 1: true}, allowedOrderingWithSorting2: array{0: string, 1: true}, allowedOrderingWithSorting3: array{0: string, 1: true}, allowedOrderingWithDotsAndSorting: array{0: string, 1: true}, nonAllowedField: array{0: string, 1: false}, nonAllowedSorting: array{0: string, 1: false}, nonAllowedDoubleSorting: array{0: string, 1: false}, nonAllowedDoubleFields: array{0: string, 1: false}, emptySorting: array{0: string, 1: true}, emptySorting2: array{0: string, 1: true}}
*/
public function orderDataProvider(): array
{
return [
'allowedOrdering' => [
'title,uid', true
],
'allowedOrderingWithSorting' => [
'title ASC, uid', true
],
'allowedOrderingWithSorting2' => [
'title ASC, uid DESC', true
],
'allowedOrderingWithSorting3' => [
'title, uid desc,teaser', true
],
'allowedOrderingWithDotsAndSorting' => [
'categories.title DESC, uid ASC,author,teaser desc', true
],
'nonAllowedField' => [
'title,teaserFo,uid', false
],
'nonAllowedSorting' => [
'title,teaser ASCx,uid', false
],
'nonAllowedDoubleSorting' => [
'title,teaser ASC DESC,uid', false
],
'nonAllowedDoubleFields' => [
'title teaser,uid', false
],
'emptySorting' => [
'', true
],
'emptySorting2' => [
' ', true
],
];
}
}

View File

@@ -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());
}
}

View File

@@ -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']);
}
}

View File

@@ -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);
}
}

View 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);
}
}

View File

@@ -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'],
];
}
}

View File

@@ -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);
}
}

View File

@@ -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'
],
];
}
}