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,24 @@
<phpunit backupGlobals="false"
bootstrap="FunctionalTestsBootstrap.php"
cacheResult="false"
colors="true"
convertErrorsToExceptions="true"
convertWarningsToExceptions="true"
convertDeprecationsToExceptions="false"
convertNoticesToExceptions="true"
forceCoversAnnotation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
verbose="false"
beStrictAboutTestsThatDoNotTestAnything="false"
failOnWarning="true"
failOnRisky="true">
<testsuites>
<testsuite name="News tests">
<directory>../Functional/</directory>
</testsuite>
</testsuites>
</phpunit>

View File

@@ -0,0 +1,30 @@
<?php
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
/**
* Boilerplate for a functional test phpunit boostrap file.
*
* This file is loosely maintained within TYPO3 testing-framework, extensions
* are encouraged to not use it directly, but to copy it to an own place,
* usually in parallel to a FunctionalTests.xml file.
*
* This file is defined in FunctionalTests.xml and called by phpunit
* before instantiating the test suites.
*/
(static function () {
$testbase = new \TYPO3\TestingFramework\Core\Testbase();
$testbase->defineOriginalRootPath();
$testbase->createDirectory(ORIGINAL_ROOT . 'typo3temp/var/tests');
$testbase->createDirectory(ORIGINAL_ROOT . 'typo3temp/var/transient');
})();

View File

@@ -0,0 +1,24 @@
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="UnitTestsBootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertWarningsToExceptions="true"
convertDeprecationsToExceptions="false"
forceCoversAnnotation="false"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
strict="false"
verbose="false">
<testsuites>
<testsuite name="EXT:news tests">
<directory>../Unit/</directory>
</testsuite>
</testsuites>
</phpunit>

View File

@@ -0,0 +1,84 @@
<?php
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
/**
* Boilerplate for a functional test phpunit boostrap file.
*
* This file is loosely maintained within TYPO3 testing-framework, extensions
* are encouraged to not use it directly, but to copy it to an own place,
* usually in parallel to a UnitTests.xml file.
*
* This file is defined in UnitTests.xml and called by phpunit
* before instantiating the test suites.
*
* The recommended way to execute the suite is "runTests.sh". See the
* according script within TYPO3 core's Build/Scripts directory and
* adapt to extensions needs.
*/
(static function () {
$testbase = new \TYPO3\TestingFramework\Core\Testbase();
// These if's are for core testing (package typo3/cms) only. cms-composer-installer does
// not create the autoload-include.php file that sets these env vars and sets composer
// mode to true. testing-framework can not be used without composer anyway, so it is safe
// to do this here. This way it does not matter if 'bin/phpunit' or 'vendor/phpunit/phpunit/phpunit'
// is called to run the tests since the 'relative to entry script' path calculation within
// SystemEnvironmentBuilder is not used. However, the binary must be called from the document
// root since getWebRoot() uses 'getcwd()'.
if (!getenv('TYPO3_PATH_ROOT')) {
putenv('TYPO3_PATH_ROOT=' . rtrim($testbase->getWebRoot(), '/'));
}
if (!getenv('TYPO3_PATH_WEB')) {
putenv('TYPO3_PATH_WEB=' . rtrim($testbase->getWebRoot(), '/'));
}
$testbase->defineSitePath();
$requestType = \TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::REQUESTTYPE_BE | \TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::REQUESTTYPE_CLI;
\TYPO3\TestingFramework\Core\SystemEnvironmentBuilder::run(0, $requestType);
$testbase->createDirectory(\TYPO3\CMS\Core\Core\Environment::getPublicPath() . '/typo3conf/ext');
$testbase->createDirectory(\TYPO3\CMS\Core\Core\Environment::getPublicPath() . '/typo3temp/assets');
$testbase->createDirectory(\TYPO3\CMS\Core\Core\Environment::getPublicPath() . '/typo3temp/var/tests');
$testbase->createDirectory(\TYPO3\CMS\Core\Core\Environment::getPublicPath() . '/typo3temp/var/transient');
// Retrieve an instance of class loader and inject to core bootstrap
$classLoader = require $testbase->getPackagesPath() . '/autoload.php';
\TYPO3\CMS\Core\Core\Bootstrap::initializeClassLoader($classLoader);
// Initialize default TYPO3_CONF_VARS
$configurationManager = new \TYPO3\CMS\Core\Configuration\ConfigurationManager();
$GLOBALS['TYPO3_CONF_VARS'] = $configurationManager->getDefaultConfiguration();
$cache = new \TYPO3\CMS\Core\Cache\Frontend\PhpFrontend(
'core',
new \TYPO3\CMS\Core\Cache\Backend\NullBackend('production', [])
);
// Set all packages to active
if (interface_exists(\TYPO3\CMS\Core\Package\Cache\PackageCacheInterface::class)) {
$packageManager = \TYPO3\CMS\Core\Core\Bootstrap::createPackageManager(\TYPO3\CMS\Core\Package\UnitTestPackageManager::class, \TYPO3\CMS\Core\Core\Bootstrap::createPackageCache($cache));
} else {
// v10 compatibility layer
// @deprecated Will be removed when v10 compat is dropped from testing-framework
$packageManager = \TYPO3\CMS\Core\Core\Bootstrap::createPackageManager(\TYPO3\CMS\Core\Package\UnitTestPackageManager::class, $cache);
}
\TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Package\PackageManager::class, $packageManager);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::setPackageManager($packageManager);
$testbase->dumpClassLoadingInformation();
\TYPO3\CMS\Core\Utility\GeneralUtility::purgeInstances();
})();

View File

@@ -0,0 +1,161 @@
<?php
declare(strict_types=1);
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\NewsController;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Http\ServerRequest;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Core\Bootstrap;
use TYPO3\CMS\Extbase\Service\EnvironmentService;
use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
/**
* Class NewsControllerTest
*/
class NewsControllerTest extends FunctionalTestCase
{
use ProphecyTrait;
/**
* @var NewsController
*/
protected $subject;
/**
* @var string[]
*/
protected $testExtensionsToLoad = [
'typo3conf/ext/news'
];
/**
* @var string[]
*/
protected $coreExtensionsToLoad = [
'extbase',
'fluid'
];
protected function setUp(): void
{
parent::setUp();
$this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/pages.xml');
$this->setUpFrontendRootPage(
1,
[
__DIR__ . '/../Fixtures/TypoScript/setup.typoscript'
]
);
// This part is needed for TYPO3 10 compatibility
/** @var EnvironmentService|ObjectProphecy $environmentServiceProphecy */
$environmentServiceProphecy = $this->prophesize(EnvironmentService::class);
$environmentServiceProphecy
->isEnvironmentInFrontendMode()
->willReturn(true);
$environmentServiceProphecy
->isEnvironmentInBackendMode()
->willReturn(false);
GeneralUtility::setSingletonInstance(EnvironmentService::class, $environmentServiceProphecy->reveal());
$serverRequest = new ServerRequest();
$applicationType = SystemEnvironmentBuilder::REQUESTTYPE_FE;
$serverRequest = $serverRequest->withAttribute('applicationType', $applicationType);
/** @var TypoScriptFrontendController|ObjectProphecy $typoScriptFrontendControllerProphecy */
$typoScriptFrontendControllerProphecy = $this->prophesize(TypoScriptFrontendController::class);
/** @var FrontendUserAuthentication|ObjectProphecy $frontendUserAuthenticationProphecy */
$frontendUserAuthenticationProphecy = $this->prophesize(FrontendUserAuthentication::class);
$GLOBALS['TYPO3_REQUEST'] = $serverRequest;
$GLOBALS['LANG'] = GeneralUtility::makeInstance(LanguageService::class);
$GLOBALS['TSFE'] = $typoScriptFrontendControllerProphecy->reveal();
$GLOBALS['TSFE']->fe_user = $frontendUserAuthenticationProphecy->reveal();
}
protected function tearDown(): void
{
unset(
$this->subject
);
parent::tearDown();
}
/**
* @test
*/
public function listActionWillReturnNoNews(): void
{
$extbaseBootstrap = GeneralUtility::makeInstance(Bootstrap::class);
$content = $extbaseBootstrap->run(
'',
[
'extensionName' => 'News',
'pluginName' => 'Pi1'
]
);
$this->assertStringContainsString(
'No news available.',
$content
);
}
/**
* @test
*/
public function listActionWillShowNewsOfStoragePage1(): void
{
$date = new \DateTime('now');
$connection = GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionForTable('tx_news_domain_model_news');
$connection->insert(
'tx_news_domain_model_news',
[
'uid' => 1,
'pid' => 1,
'title' => 'My first news',
'datetime' => (int)$date->format('U')
]
);
$extbaseBootstrap = GeneralUtility::makeInstance(Bootstrap::class);
$content = $extbaseBootstrap->run(
'',
[
'extensionName' => 'News',
'pluginName' => 'Pi1'
]
);
$this->assertStringContainsString(
'<span itemprop="headline">My first news</span>',
$content
);
$this->assertStringContainsString(
'<time itemprop="datePublished" datetime="' . $date->format('Y-m-d') . '">',
$content
);
}
}

View File

@@ -0,0 +1,183 @@
# ==============================================
# FE-Plugin configuration for EXT:news
# ==============================================
plugin.tx_news {
mvc.callDefaultActionIfActionCantBeResolved = 1
view {
templateRootPaths {
0 = EXT:news/Resources/Private/Templates/
}
partialRootPaths {
0 = EXT:news/Resources/Private/Partials/
}
layoutRootPaths {
0 = EXT:news/Resources/Private/Layouts/
}
widget.GeorgRinger\News\ViewHelpers\Widget\PaginateViewHelper.templateRootPath = EXT:news/Resources/Private/Templates/
}
# ====================================
# Settings available inside Controller and View by accessing $this->settings or {settings.xyz}
# ====================================
settings {
cssFile =
#Displays a dummy image if the news have no media items
displayDummyIfNoMedia = 1
# Output format
format = html
# general settings
overrideFlexformSettingsIfEmpty = cropMaxCharacters,dateField,timeRestriction,timeRestrictionHigh,archiveRestriction,orderBy,orderDirection,backPid,listPid,startingpoint,recursive,list.paginate.itemsPerPage,list.paginate.templatePath
allowEmptyStringsForOverwriteDemand = 0
includeSubCategories = 0
analytics {
social {
facebookLike = 1
facebookShare = 1
twitter = 1
}
}
detailPidDetermination = flexform, categories, default
defaultDetailPid = 0
dateField = datetime
link {
typesOpeningInNewWindow = 2
hrDate = 0
hrDate {
day = j
month = n
year = Y
}
}
cropMaxCharacters = 150
orderBy = datetime
orderDirection = desc
topNewsFirst = 0
orderByAllowed = sorting,author,uid,title,teaser,author,tstamp,crdate,datetime,categories.title
facebookLocale = en_US
googlePlusLocale = en
demandClass =
# --------------
# Search
# --------------
search {
fields = teaser,title,bodytext
splitSearchWord = 0
}
# --------------
# Detail
# --------------
detail {
errorHandling = showStandaloneTemplate,EXT:news/Resources/Private/Templates/News/DetailNotFound.html,404
checkPidOfNewsRecord = 0
registerProperties = keywords,title
showPrevNext = 0
showSocialShareButtons = 1
showMetaTags = 1
# media configuration
media {
image {
lazyLoading = 0
maxWidth = 282
maxHeight =
# Get lightbox settings from fluid_styled_content
lightbox {
enabled = {$styles.content.textmedia.linkWrap.lightboxEnabled}
class = {$styles.content.textmedia.linkWrap.lightboxCssClass}
width = {$styles.content.textmedia.linkWrap.width}
height = {$styles.content.textmedia.linkWrap.height}
rel = lightbox[myImageSet]
}
}
video {
width = 282
height = 159
}
}
pageTitle = 1
pageTitle {
provider = GeorgRinger\News\Seo\NewsTitleProvider
properties = title,teaser
}
}
# --------------
# List
# --------------
list {
# media configuration
media {
image {
lazyLoading = 0
maxWidth = 100
maxHeight = 100
}
dummyImage = EXT:news/Resources/Public/Images/dummy-preview-image.png
}
# Paginate configuration.
paginate {
class = GeorgRinger\NumberedPagination\NumberedPagination
itemsPerPage = 10
insertAbove = 1
insertBelow = 1
maximumNumberOfLinks = 3
}
}
}
}
# ==============================================
# Persistence object mapping configuration
# ==============================================
config.tx_extbase.persistence.classes {
GeorgRinger\News\Domain\Model\News {
subclasses {
0 = GeorgRinger\News\Domain\Model\NewsDefault
1 = GeorgRinger\News\Domain\Model\NewsInternal
2 = GeorgRinger\News\Domain\Model\NewsExternal
}
}
GeorgRinger\News\Domain\Model\NewsDefault {
mapping {
recordType = 0
tableName = tx_news_domain_model_news
}
}
GeorgRinger\News\Domain\Model\NewsInternal {
mapping {
recordType = 1
tableName = tx_news_domain_model_news
}
}
GeorgRinger\News\Domain\Model\NewsExternal {
mapping {
recordType = 2
tableName = tx_news_domain_model_news
}
}
}

View File

@@ -0,0 +1,22 @@
tx_news_domain_model_news,,,,
,uid,pid,title
,1,0,News1
,2,0,News2
,3,0,News3
,4,0,News4
,5,0,News5
,6,0,News6
,7,0,News7
,8,0,News8
,9,0,News9
,10,0,News10
,11,0,News11
,12,0,News12
,13,0,News13
,14,0,News14
,15,0,News15
,16,0,News16
,17,0,News17
,18,0,News18
,19,0,News19
,20,0,News20
1 tx_news_domain_model_news,,,,
2 ,uid,pid,title
3 ,1,0,News1
4 ,2,0,News2
5 ,3,0,News3
6 ,4,0,News4
7 ,5,0,News5
8 ,6,0,News6
9 ,7,0,News7
10 ,8,0,News8
11 ,9,0,News9
12 ,10,0,News10
13 ,11,0,News11
14 ,12,0,News12
15 ,13,0,News13
16 ,14,0,News14
17 ,15,0,News15
18 ,16,0,News16
19 ,17,0,News17
20 ,18,0,News18
21 ,19,0,News19
22 ,20,0,News20

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<dataset>
<!--findRecordsByImportSource-->
<sys_category>
<uid>456</uid>
<pid>1</pid>
<title>findRecordByImportSource</title>
<import_source>functional_test</import_source>
<import_id>2</import_id>
<l10n_diffsource></l10n_diffsource>
<description></description>
</sys_category>
</dataset>

View File

@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<dataset>
<tx_news_domain_model_tag>
<uid>1</uid>
<pid>1</pid>
<title>Tag 1</title>
</tx_news_domain_model_tag>
<tx_news_domain_model_tag>
<uid>2</uid>
<pid>1</pid>
<title>Tag 2</title>
</tx_news_domain_model_tag>
<tx_news_domain_model_tag>
<uid>3</uid>
<pid>1</pid>
<title>Tag 3</title>
</tx_news_domain_model_tag>
<tx_news_domain_model_tag>
<uid>4</uid>
<pid>1</pid>
<title>Tag 4</title>
</tx_news_domain_model_tag>
<tx_news_domain_model_tag>
<uid>5</uid>
<pid>1</pid>
<title>Tag 5</title>
</tx_news_domain_model_tag>
</dataset>

View File

@@ -0,0 +1,251 @@
<?xml version="1.0" encoding="utf-8"?>
<dataset>
<!--findRecordsByUid-->
<tx_news_domain_model_news>
<uid>1</uid>
<pid>1</pid>
<type>0</type>
<title>findRecordsByUid</title>
</tx_news_domain_model_news>
<!--findRecordsByImportSource-->
<tx_news_domain_model_news>
<uid>456</uid>
<pid>1</pid>
<type>0</type>
<title>findRecordsByImportSource</title>
<import_source>functional_test</import_source>
<import_id>2</import_id>
</tx_news_domain_model_news>
<!--findTopNewsRecords-->
<tx_news_domain_model_news>
<pid>2</pid>
<type>1</type>
<istopnews>1</istopnews>
</tx_news_domain_model_news>
<tx_news_domain_model_news>
<pid>2</pid>
<type>1</type>
<istopnews>1</istopnews>
</tx_news_domain_model_news>
<tx_news_domain_model_news>
<pid>2</pid>
<type>2</type>
<istopnews>1</istopnews>
</tx_news_domain_model_news>
<tx_news_domain_model_news>
<pid>2</pid>
<type>2</type>
<istopnews>0</istopnews>
</tx_news_domain_model_news>
<tx_news_domain_model_news>
<pid>2</pid>
<type>2</type>
<istopnews>0</istopnews>
</tx_news_domain_model_news>
<!--findRecordsByStartingpointRestriction-->
<tx_news_domain_model_news>
<pid>3</pid>
</tx_news_domain_model_news>
<tx_news_domain_model_news>
<pid>3</pid>
</tx_news_domain_model_news>
<tx_news_domain_model_news>
<pid>4</pid>
</tx_news_domain_model_news>
<tx_news_domain_model_news>
<pid>4</pid>
</tx_news_domain_model_news>
<tx_news_domain_model_news>
<pid>4</pid>
</tx_news_domain_model_news>
<tx_news_domain_model_news>
<pid>4</pid>
</tx_news_domain_model_news>
<tx_news_domain_model_news>
<pid>5</pid>
</tx_news_domain_model_news>
<!--findRecordsByArchiveRestriction-->
<!--22.3.2014-->
<tx_news_domain_model_news>
<pid>7</pid>
<archive>1395516100</archive>
</tx_news_domain_model_news>
<!--27.3.-->
<tx_news_domain_model_news>
<pid>7</pid>
<archive>1395948100</archive>
</tx_news_domain_model_news>
<!--1.4.2014-->
<tx_news_domain_model_news>
<pid>7</pid>
<archive>1396380100</archive>
</tx_news_domain_model_news>
<!--6.4.2014-->
<tx_news_domain_model_news>
<pid>7</pid>
<archive>1396812100</archive>
</tx_news_domain_model_news>
<!--11.4.2014-->
<tx_news_domain_model_news>
<pid>7</pid>
<archive>1397244100</archive>
</tx_news_domain_model_news>
<!--findRecordsByMonthAndYear-->
<tx_news_domain_model_news>
<pid>8</pid>
<datetime>1298156400</datetime>
</tx_news_domain_model_news>
<tx_news_domain_model_news>
<pid>8</pid>
<datetime>1298329200</datetime>
</tx_news_domain_model_news>
<tx_news_domain_model_news>
<pid>8</pid>
<datetime>1298934000</datetime>
</tx_news_domain_model_news>
<tx_news_domain_model_news>
<pid>8</pid>
<datetime>1298934000</datetime>
</tx_news_domain_model_news>
<tx_news_domain_model_news>
<pid>8</pid>
<datetime>1299711600</datetime>
</tx_news_domain_model_news>
<tx_news_domain_model_news>
<pid>8</pid>
<datetime>1301522400</datetime>
</tx_news_domain_model_news>
<tx_news_domain_model_news>
<pid>8</pid>
<datetime>1301608800</datetime>
</tx_news_domain_model_news>
<!--findLatestLimitRecords-->
<!--SimplePrevNextViewHelperTest-->
<!--22.3.2014-->
<tx_news_domain_model_news>
<uid>101</uid>
<pid>9</pid>
<datetime>1395516730</datetime>
</tx_news_domain_model_news>
<!--25.3.2014-->
<tx_news_domain_model_news>
<uid>102</uid>
<pid>9</pid>
<datetime>1395775956</datetime>
</tx_news_domain_model_news>
<!--28.3.2014-->
<tx_news_domain_model_news>
<uid>103</uid>
<pid>9</pid>
<datetime>1396035186</datetime>
</tx_news_domain_model_news>
<!--29.3.2014-->
<tx_news_domain_model_news>
<uid>104</uid>
<pid>9</pid>
<datetime>1396121600</datetime>
</tx_news_domain_model_news>
<!--2.4.2014-->
<tx_news_domain_model_news>
<uid>105</uid>
<pid>9</pid>
<datetime>1396467221</datetime>
</tx_news_domain_model_news>
<!--4.4.2014 -->
<tx_news_domain_model_news>
<uid>106</uid>
<pid>9</pid>
<datetime>1396640035</datetime>
</tx_news_domain_model_news>
<!--Tags-->
<tx_news_domain_model_news>
<uid>130</uid>
<pid>10</pid>
<title>tag1,tag2,tag3</title>
<tags>3</tags>
</tx_news_domain_model_news>
<tx_news_domain_model_news_tag_mm>
<uid_local>130</uid_local>
<uid_foreign>1</uid_foreign>
<sorting>1</sorting>
</tx_news_domain_model_news_tag_mm>
<tx_news_domain_model_news_tag_mm>
<uid_local>130</uid_local>
<uid_foreign>2</uid_foreign>
<sorting>2</sorting>
</tx_news_domain_model_news_tag_mm>
<tx_news_domain_model_news_tag_mm>
<uid_local>130</uid_local>
<uid_foreign>3</uid_foreign>
<sorting>3</sorting>
</tx_news_domain_model_news_tag_mm>
<tx_news_domain_model_news>
<uid>131</uid>
<pid>10</pid>
<title>tag3</title>
<tags>1</tags>
</tx_news_domain_model_news>
<tx_news_domain_model_news_tag_mm>
<uid_local>131</uid_local>
<uid_foreign>3</uid_foreign>
<sorting>1</sorting>
</tx_news_domain_model_news_tag_mm>
<tx_news_domain_model_news>
<uid>132</uid>
<pid>10</pid>
<title>tag4</title>
<tags>1</tags>
</tx_news_domain_model_news>
<tx_news_domain_model_news_tag_mm>
<uid_local>132</uid_local>
<uid_foreign>4</uid_foreign>
<sorting>1</sorting>
</tx_news_domain_model_news_tag_mm>
<tx_news_domain_model_news>
<uid>133</uid>
<pid>10</pid>
<title>tag5</title>
<tags>1</tags>
</tx_news_domain_model_news>
<tx_news_domain_model_news_tag_mm>
<uid_local>133</uid_local>
<uid_foreign>5</uid_foreign>
<sorting>1</sorting>
</tx_news_domain_model_news_tag_mm>
<tx_news_domain_model_news>
<uid>134</uid>
<pid>10</pid>
<title>tag4,tag5</title>
<tags>2</tags>
</tx_news_domain_model_news>
<tx_news_domain_model_news_tag_mm>
<uid_local>134</uid_local>
<uid_foreign>4</uid_foreign>
<sorting>1</sorting>
</tx_news_domain_model_news_tag_mm>
<tx_news_domain_model_news_tag_mm>
<uid_local>134</uid_local>
<uid_foreign>5</uid_foreign>
<sorting>2</sorting>
</tx_news_domain_model_news_tag_mm>
</dataset>

View File

@@ -0,0 +1,206 @@
<?php
namespace GeorgRinger\News\Tests\Functional\Pagination;
/**
* 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\Repository\NewsRepository;
use GeorgRinger\News\Pagination\QueryResultPaginator;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
class QueryResultPaginatorTest extends FunctionalTestCase
{
/**
* @var NewsRepository
*/
protected $newsRepository;
protected $testExtensionsToLoad = ['typo3conf/ext/news'];
protected function setUp(): void
{
parent::setUp();
$this->importCSVDataSet(__DIR__ . '/../Fixtures/news_pagination.csv');
$versionInformation = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(Typo3Version::class);
if ($versionInformation->getMajorVersion() === 11) {
$this->newsRepository = $this->getContainer()->get(NewsRepository::class);
} else {
$this->newsRepository = GeneralUtility::makeInstance(ObjectManager::class)->get(NewsRepository::class);
}
}
/**
* A short integration test to check that the fixtures are as expected
*
* @test
*/
public function integration(): void
{
$queryResult = $this->newsRepository->findAll();
self::assertCount(20, $queryResult);
}
/**
* @test
*/
public function checkPaginatorWithDefaultConfiguration(): void
{
$paginator = new QueryResultPaginator($this->newsRepository->findAll());
self::assertSame(2, $paginator->getNumberOfPages());
self::assertSame(0, $paginator->getKeyOfFirstPaginatedItem());
self::assertSame(9, $paginator->getKeyOfLastPaginatedItem());
self::assertCount(10, $paginator->getPaginatedItems());
}
/**
* @test
*/
public function paginatorRespectsItemsPerPageConfiguration(): void
{
$paginator = new QueryResultPaginator(
$this->newsRepository->findAll(),
1,
3
);
self::assertSame(7, $paginator->getNumberOfPages());
self::assertSame(0, $paginator->getKeyOfFirstPaginatedItem());
self::assertSame(2, $paginator->getKeyOfLastPaginatedItem());
self::assertCount(3, $paginator->getPaginatedItems());
}
/**
* @test
*/
public function paginatorRespectsItemsPerPageConfigurationAndCurrentPage(): void
{
$paginator = new QueryResultPaginator(
$this->newsRepository->findAll(),
3,
3
);
self::assertSame(7, $paginator->getNumberOfPages());
self::assertSame(6, $paginator->getKeyOfFirstPaginatedItem());
self::assertSame(8, $paginator->getKeyOfLastPaginatedItem());
self::assertCount(3, $paginator->getPaginatedItems());
}
/**
* @test
*/
public function paginatorProperlyCalculatesLastPage(): void
{
$paginator = new QueryResultPaginator(
$this->newsRepository->findAll(),
7,
3
);
self::assertSame(7, $paginator->getNumberOfPages());
self::assertSame(18, $paginator->getKeyOfFirstPaginatedItem());
self::assertSame(19, $paginator->getKeyOfLastPaginatedItem());
self::assertCount(2, $paginator->getPaginatedItems());
}
/**
* @test
*/
public function withCurrentPageNumberThrowsInvalidArgumentExceptionIfCurrentPageIsLowerThanOne(): void
{
$this->expectExceptionCode(1573047338);
$paginator = new QueryResultPaginator(
$this->newsRepository->findAll(),
1,
3
);
$paginator->withCurrentPageNumber(0);
}
/**
* @test
*/
public function paginatorSetsCurrentPageToLastPageIfCurrentPageExceedsMaximum(): void
{
$paginator = new QueryResultPaginator(
$this->newsRepository->findAll(),
3,
10
);
self::assertEquals(2, $paginator->getCurrentPageNumber());
self::assertEquals(2, $paginator->getNumberOfPages());
self::assertCount(10, $paginator->getPaginatedItems()); // true?
}
/**
* @test
*/
public function paginatorProperlyCalculatesOnlyOnePage(): void
{
$paginator = new QueryResultPaginator(
$this->newsRepository->findAll(),
1,
50
);
self::assertSame(1, $paginator->getNumberOfPages());
self::assertSame(0, $paginator->getKeyOfFirstPaginatedItem());
self::assertSame(19, $paginator->getKeyOfLastPaginatedItem());
self::assertCount(20, $paginator->getPaginatedItems());
}
/**
* @test
* @dataProvider paginatorProperlyCalculatesWithLimitAndOffsetDataProvider
*/
public function paginatorProperlyCalculatesWithLimitAndOffset(array $given, array $expected): void
{
$demand = new NewsDemand();
$demand->setOrder('uid asc');
$demand->setOrderByAllowed('uid');
$demand->setLimit($given['limit']);
$demand->setOffset($given['offset']);
$paginator = new QueryResultPaginator(
$this->newsRepository->findDemanded($demand),
$given['currentPage'],
3,
$given['limit'],
$given['offset']
);
self::assertSame($expected['firstItemTitle'], $paginator->getPaginatedItems()[0]->getTitle());
self::assertCount($expected['itemCount'], $paginator->getPaginatedItems());
self::assertSame($expected['numberOfPages'], $paginator->getNumberOfPages());
}
public function paginatorProperlyCalculatesWithLimitAndOffsetDataProvider(): array
{
return [
'with offset' => [
['currentPage' => 3, 'limit' => 0, 'offset' => 3],
['itemCount' => 3, 'firstItemTitle' => 'News10', 'numberOfPages' => 6],
],
'with limit' => [
['currentPage' => 2, 'limit' => 4, 'offset' => 0],
['itemCount' => 1, 'firstItemTitle' => 'News4', 'numberOfPages' => 2],
],
'with limit and offset' => [
['currentPage' => 2, 'limit' => 12, 'offset' => 5],
['itemCount' => 3, 'firstItemTitle' => 'News9', 'numberOfPages' => 4],
],
];
}
}

View File

@@ -0,0 +1,54 @@
<?php
namespace GeorgRinger\News\Tests\Functional\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\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
/**
* Functional test for the DataHandler
*/
class CategoryRepositoryTest extends FunctionalTestCase
{
/** @var \GeorgRinger\News\Domain\Repository\CategoryRepository */
protected $categoryRepository;
protected $testExtensionsToLoad = ['typo3conf/ext/news'];
public function setUp(): void
{
parent::setUp();
$versionInformation = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Information\Typo3Version::class);
if ($versionInformation->getMajorVersion() === 11) {
$this->categoryRepository = $this->getContainer()->get(CategoryRepository::class);
} else {
$this->categoryRepository = GeneralUtility::makeInstance(ObjectManager::class)->get(CategoryRepository::class);
}
$this->importDataSet(__DIR__ . '/../Fixtures/sys_category.xml');
}
/**
* Test if by import source is done
*
* @test
*
* @return void
*/
public function findRecordByImportSource(): void
{
$category = $this->categoryRepository->findOneByImportSourceAndImportId('functional_test', '2');
$this->assertEquals($category->getTitle(), 'findRecordByImportSource');
}
}

View File

@@ -0,0 +1,288 @@
<?php
namespace GeorgRinger\News\Tests\Functional\Repository;
use GeorgRinger\News\Domain\Model\Dto\NewsDemand;
use GeorgRinger\News\Domain\Repository\NewsRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
/**
* 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.
*/
/**
* Functional test for the \GeorgRinger\News\Domain\Repository\NewsRepository
*/
class NewsRepositoryTest extends FunctionalTestCase
{
/** @var \GeorgRinger\News\Domain\Repository\NewsRepository */
protected $newsRepository;
protected $testExtensionsToLoad = ['typo3conf/ext/news'];
protected $coreExtensionsToLoad = ['fluid'];
public function setUp(): void
{
parent::setUp();
$versionInformation = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Information\Typo3Version::class);
if ($versionInformation->getMajorVersion() === 11) {
$this->newsRepository = $this->getContainer()->get(NewsRepository::class);
} else {
$this->newsRepository = GeneralUtility::makeInstance(ObjectManager::class)->get(NewsRepository::class);
}
$this->importDataSet(__DIR__ . '/../Fixtures/tags.xml');
$this->importDataSet(__DIR__ . '/../Fixtures/tx_news_domain_model_news.xml');
}
/**
* Test if startingpoint is working
*
* @test
*
* @return void
*/
public function findRecordsByUid(): void
{
$news = $this->newsRepository->findByUid(1);
$this->assertEquals($news->getTitle(), 'findRecordsByUid');
}
/**
* Test if by import source is done
*
* @test
*
* @return void
*/
public function findRecordsByImportSource(): void
{
$news = $this->newsRepository->findOneByImportSourceAndImportId('functional_test', '2');
$this->assertEquals($news->getTitle(), 'findRecordsByImportSource');
}
/**
* Test if top news constraint works
*
* @test
*
* @return void
*/
public function findTopNewsRecords(): void
{
$demand = new NewsDemand();
$demand->setStoragePage(2);
// no matter about top news
$demand->setTopNewsRestriction(0);
$this->assertEquals((int)$this->newsRepository->findDemanded($demand)->count(), 5);
// Only Top news
$demand->setTopNewsRestriction(1);
$this->assertEquals((int)$this->newsRepository->findDemanded($demand)->count(), 3);
// Only non Top news
$demand->setTopNewsRestriction(2);
$this->assertEquals((int)$this->newsRepository->findDemanded($demand)->count(), 2);
}
/**
* Test if startingpoint is working
*
* @test
*
* @return void
*/
public function findRecordsByStartingpointRestriction(): void
{
$demand = new NewsDemand();
// simple starting point
$demand->setStoragePage(3);
$this->assertEquals((int)$this->newsRepository->findDemanded($demand)->count(), 2);
// multiple starting points
$demand->setStoragePage('4,5');
$this->assertEquals((int)$this->newsRepository->findDemanded($demand)->count(), 5);
// multiple starting points, including invalid values and commas
$demand->setStoragePage('5 , x ,3');
$this->assertEquals((int)$this->newsRepository->findDemanded($demand)->count(), 3);
}
/**
* Test if record are found by archived/non archived flag
*
* @test
*
* @return void
*/
public function findRecordsByArchiveRestriction(): void
{
$GLOBALS['SIM_EXEC_TIME'] = 1396812099;
$demand = new NewsDemand();
$demand->setStoragePage(7);
// Archived means: archive date must be lower than current time AND != 0
$demand->setArchiveRestriction('archived');
$this->assertEquals((int)$this->newsRepository->findDemanded($demand)->count(), 3);
// Active means: archive date must be in future or no archive date
$demand->setArchiveRestriction('active');
$this->assertEquals((int)$this->newsRepository->findDemanded($demand)->count(), 2);
// no value means: give all
$demand->setArchiveRestriction('');
$this->assertEquals((int)$this->newsRepository->findDemanded($demand)->count(), 5);
}
/**
* Test if record by month/year constraint works
*
* @test
*
* @return void
*/
public function findRecordsByMonthAndYear(): void
{
$this->markTestSkipped('Does not work in travis');
$demand = new NewsDemand();
$demand->setStoragePage(8);
$demand->setDateField('datetime');
$demand->setMonth('4');
$demand->setYear('2011');
$this->assertEquals((int)$this->newsRepository->findDemanded($demand)->count(), 1);
}
/**
* Test if latest limit constraint works
*
* @test
*
* @return void
*/
public function findLatestLimitRecords(): void
{
$demand = new NewsDemand();
$demand->setStoragePage(9);
$GLOBALS['SIM_EXEC_TIME'] = strtotime('2014-04-03');
// get all news maximum 6 days old
$demand->setTimeRestriction((6 * 86400));
$this->assertEquals((int)$this->newsRepository->findDemanded($demand)->count(), 4);
// no restriction should get you all
$demand->setTimeRestriction(0);
$this->assertEquals((int)$this->newsRepository->findDemanded($demand)->count(), 6);
}
/**
* Test if by import source is done
*
* @test
*
* @return void
*/
public function findRecordsByTags(): void
{
$demand = new NewsDemand();
$demand->setStoragePage(10);
$demand->setOrder('uid');
$demand->setOrderByAllowed('uid');
// given is 1 tag
$demand->setTags('3');
$news = $this->newsRepository->findDemanded($demand);
$this->assertEquals('130,131', $this->getIdListOfNews($news));
// given are 2 tags
$demand->setTags('1,5');
$news = $this->newsRepository->findDemanded($demand);
$this->assertEquals('130,133,134', $this->getIdListOfNews($news));
// given are 3 real tags & 1 not existing
$demand->setTags('5,3,1,10');
$news = $this->newsRepository->findDemanded($demand);
$this->assertEquals('130,131,133,134', $this->getIdListOfNews($news));
}
/**
* @test
*
* @return void
*/
public function findRecordsForDateMenu(): void
{
$demand = new NewsDemand();
$demand->setStoragePage('9');
$demand->setDateField('datetime');
$expected = [
'single' => [
'2014' => [
'03' => 4,
'04' => 2
]
],
'total' => [
'2014' => 6
]
];
$dateMenuData = $this->newsRepository->countByDate($demand);
$this->assertEquals($expected, $dateMenuData);
}
/**
* Test if records are found by type
*
* @test
*
* @return void
*/
public function findRecordsByType(): void
{
$demand = new NewsDemand();
$demand->setStoragePage('1,2');
// given is 1 tag
$demand->setTypes(['1']);
$count = $this->newsRepository->findDemanded($demand)->count();
$this->assertEquals(2, $count);
// given are 2 tags
$demand->setTypes(['1', 2]);
$count = $this->newsRepository->findDemanded($demand)->count();
$this->assertEquals(5, $count);
}
/**
* @param \TYPO3\CMS\Extbase\Persistence\QueryResultInterface $newsList
* @return string
*/
protected function getIdListOfNews(QueryResultInterface $newsList)
{
$idList = [];
foreach ($newsList as $news) {
$idList[] = $news->getUid();
}
return implode(',', $idList);
}
public function tearDown(): void
{
unset($this->newsRepository);
}
}

View File

@@ -0,0 +1,55 @@
<?php
namespace GeorgRinger\News\Tests\Functional\ViewHelpers\Iterator;
/**
* This file is part of the "news" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
/**
* Test for ChunkViewHelper
*/
class ChunkViewHelperTest extends FunctionalTestCase
{
protected $testExtensionsToLoad = ['typo3conf/ext/news'];
protected $coreExtensionsToLoad = ['extbase', 'fluid'];
/**
* @test
*
* @return void
*/
public function chunkIsProperlyCreated(): void
{
$standaloneView = GeneralUtility::makeInstance(StandaloneView::class);
$standaloneView->setTemplateSource(
'{namespace n=GeorgRinger\News\ViewHelpers}' . LF .
'<f:for each="{news -> n:iterator.chunk(count: 3)}" as="col" iteration="cycle">' .
'<div class="row"><f:for each="{col}" as="item"><div class="col">{item.title}</div></f:for></div>' .
'</f:for>'
);
$standaloneView->assign('news', [
['title' => 'el1'],
['title' => 'el2'],
['title' => 'el3'],
['title' => 'el4'],
]);
$expected = '<div class="row">' .
'<div class="col">el1</div>' .
'<div class="col">el2</div>' .
'<div class="col">el3</div>' .
'</div>' .
'<div class="row">' .
'<div class="col">el4</div>' .
'</div>';
$this->assertEquals(trim($expected), trim($standaloneView->render()));
}
}

View File

@@ -0,0 +1,124 @@
<?php
namespace GeorgRinger\News\Tests\Functional\ViewHelpers;
/**
* This file is part of the "news" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/
use DateTime;
use GeorgRinger\News\Domain\Model\News;
use GeorgRinger\News\ViewHelpers\SimplePrevNextViewHelper;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
/**
* Class SimplePrevNextViewHelperTest
*
*/
class SimplePrevNextViewHelperTest extends FunctionalTestCase
{
/** @var \GeorgRinger\News\ViewHelpers\SimplePrevNextViewHelper|\PHPUnit\Framework\MockObject\MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface */
protected $mockedViewHelper;
/** @var News */
protected $news;
protected $testExtensionsToLoad = ['typo3conf/ext/news'];
protected $coreExtensionsToLoad = ['extbase', 'fluid'];
public function setUp(): void
{
parent::setUp();
$this->mockedViewHelper = $this->getAccessibleMock(SimplePrevNextViewHelper::class, ['dummy'], [], '', true, true, false);
$this->news = new News();
$this->news->_setProperty('uid', 123);
$this->news->setPid(9);
$this->importDataSet(__DIR__ . '/../Fixtures/tx_news_domain_model_news.xml');
}
/**
* @test
*
* @return void
*/
public function allNeighboursCanBeFound(): void
{
$this->setDate(1396035186);
$actual = $this->mockedViewHelper->_call('getNeighbours', $this->news, '', 'datetime');
$exp = [
'prev' => $this->getRow(102),
'next' => $this->getRow(104)
];
$this->assertEquals($exp, $actual);
}
/**
* @test
*
* @return void
*/
public function nextNeighbourCanBeFound(): void
{
$this->setDate(1395516730);
$actual = $this->mockedViewHelper->_call('getNeighbours', $this->news, '', 'datetime');
$exp = [
'next' => $this->getRow(102)
];
$this->assertEquals($exp, $actual);
}
/**
* @test
*
* @return void
*/
public function previousNeighbourCanBeFound(): void
{
$this->setDate(1396640035);
$actual = $this->mockedViewHelper->_call('getNeighbours', $this->news, '', 'datetime');
$exp = [
'prev' => $this->getRow(105)
];
$this->assertEquals($exp, $actual);
}
/**
* @param int $timestamp
*
* @return void
*/
protected function setDate($timestamp): void
{
$date = new DateTime();
$date->setTimestamp($timestamp);
$this->news->_setProperty('datetime', $date);
}
/**
* @param int $id
*/
protected function getRow(int $id)
{
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('tx_news_domain_model_news');
return $queryBuilder
->select('*')
->from('tx_news_domain_model_news')
->where(
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($id, \PDO::PARAM_INT))
)
->setMaxResults(1)
->execute()->fetch();
}
}

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