mirror of
https://github.com/werkraum-media/events.git
synced 2024-11-10 03:36:09 +01:00
Ensure no "Undefined array key" within factories
This commit is contained in:
parent
fc274d238c
commit
9b783e5e89
4 changed files with 187 additions and 16 deletions
|
@ -60,15 +60,33 @@ class DateDemandFactory
|
|||
}
|
||||
}
|
||||
|
||||
$demand->setRegions(GeneralUtility::intExplode(',', (string)$settings['region'], true));
|
||||
$demand->setLocations(GeneralUtility::intExplode(',', (string)$settings['locations'], true));
|
||||
$demand->setCategories((string)$settings['categories']);
|
||||
$categoryCombination = (int)$settings['categoryCombination'] === 1 ? 'or' : 'and';
|
||||
if (!empty($settings['region'])) {
|
||||
$demand->setRegions(GeneralUtility::intExplode(',', (string)$settings['region'], true));
|
||||
}
|
||||
if (!empty($settings['locations'])) {
|
||||
$demand->setLocations(GeneralUtility::intExplode(',', (string)$settings['locations'], true));
|
||||
}
|
||||
if (!empty($settings['categories'])) {
|
||||
$demand->setCategories((string)$settings['categories']);
|
||||
}
|
||||
$categoryCombination = 'and';
|
||||
if (isset($settings['categoryCombination']) && (int)$settings['categoryCombination'] === 1) {
|
||||
$categoryCombination = 'or';
|
||||
}
|
||||
$demand->setCategoryCombination($categoryCombination);
|
||||
$demand->setIncludeSubCategories((bool)$settings['includeSubcategories']);
|
||||
$demand->setSortBy((string)$settings['sortByDate']);
|
||||
$demand->setSortOrder((string)$settings['sortOrder']);
|
||||
$demand->setHighlight((bool)$settings['highlight']);
|
||||
|
||||
if (isset($settings['includeSubcategories'])) {
|
||||
$demand->setIncludeSubCategories((bool)$settings['includeSubcategories']);
|
||||
}
|
||||
if (isset($settings['sortByDate'])) {
|
||||
$demand->setSortBy((string)$settings['sortByDate']);
|
||||
}
|
||||
if (!empty($settings['sortOrder'])) {
|
||||
$demand->setSortOrder((string)$settings['sortOrder']);
|
||||
}
|
||||
if (isset($settings['highlight'])) {
|
||||
$demand->setHighlight((bool)$settings['highlight']);
|
||||
}
|
||||
if (!empty($settings['start'])) {
|
||||
$demand->setStart((int)$settings['start']);
|
||||
}
|
||||
|
|
|
@ -30,24 +30,41 @@ class EventDemandFactory
|
|||
/** @var EventDemand $demand */
|
||||
$demand = GeneralUtility::makeInstance(EventDemand::class);
|
||||
|
||||
$demand->setRegion((string)$settings['region']);
|
||||
if (!empty($settings['region'])) {
|
||||
$demand->setRegion((string)$settings['region']);
|
||||
}
|
||||
|
||||
$demand->setCategories((string)$settings['categories']);
|
||||
if (!empty($settings['categories'])) {
|
||||
$demand->setCategories((string)$settings['categories']);
|
||||
}
|
||||
|
||||
$categoryCombination = 'and';
|
||||
if ((int)$settings['categoryCombination'] === 1) {
|
||||
if (
|
||||
isset($settings['categoryCombination'])
|
||||
&& (int)$settings['categoryCombination'] === 1
|
||||
) {
|
||||
$categoryCombination = 'or';
|
||||
}
|
||||
$demand->setCategoryCombination($categoryCombination);
|
||||
|
||||
$demand->setIncludeSubCategories((bool)$settings['includeSubcategories']);
|
||||
if (isset($settings['includeSubcategories'])) {
|
||||
$demand->setIncludeSubCategories((bool)$settings['includeSubcategories']);
|
||||
}
|
||||
|
||||
$demand->setSortBy((string)$settings['sortByEvent']);
|
||||
$demand->setSortOrder((string)$settings['sortOrder']);
|
||||
if (!empty($settings['sortByEvent'])) {
|
||||
$demand->setSortBy((string)$settings['sortByEvent']);
|
||||
}
|
||||
if (!empty($settings['sortOrder'])) {
|
||||
$demand->setSortOrder((string)$settings['sortOrder']);
|
||||
}
|
||||
|
||||
$demand->setHighlight((bool)$settings['highlight']);
|
||||
if (isset($settings['highlight'])) {
|
||||
$demand->setHighlight((bool)$settings['highlight']);
|
||||
}
|
||||
|
||||
$demand->setRecordUids(GeneralUtility::intExplode(',', $settings['selectedRecords'], true));
|
||||
if (!empty($settings['selectedRecords'])) {
|
||||
$demand->setRecordUids(GeneralUtility::intExplode(',', $settings['selectedRecords'], true));
|
||||
}
|
||||
|
||||
if (!empty($settings['limit'])) {
|
||||
$demand->setLimit($settings['limit']);
|
||||
|
|
74
Tests/Unit/Domain/Model/Dto/DateDemandFactoryTest.php
Normal file
74
Tests/Unit/Domain/Model/Dto/DateDemandFactoryTest.php
Normal file
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Copyright (C) 2022 Daniel Siepmann <coding@daniel-siepmann.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
namespace Wrm\Events\Tests\Unit\Domain\Model\Dto;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use TYPO3\CMS\Core\TypoScript\TypoScriptService;
|
||||
use Wrm\Events\Domain\Model\Dto\DateDemand;
|
||||
use Wrm\Events\Domain\Model\Dto\DateDemandFactory;
|
||||
use Wrm\Events\Tests\ProphecyTrait;
|
||||
|
||||
/**
|
||||
* @covers \Wrm\Events\Domain\Model\Dto\DateDemandFactory
|
||||
*/
|
||||
class DateDemandFactoryTest extends TestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function canBeCreated(): void
|
||||
{
|
||||
$typoScriptService = $this->prophesize(TypoScriptService::class);
|
||||
|
||||
$subject = new DateDemandFactory(
|
||||
$typoScriptService->reveal()
|
||||
);
|
||||
|
||||
self::assertInstanceOf(
|
||||
DateDemandFactory::class,
|
||||
$subject
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function fromSettingsDoesNotThrowUndefinedArrayKeyWarnings(): void
|
||||
{
|
||||
$typoScriptService = $this->prophesize(TypoScriptService::class);
|
||||
|
||||
$subject = new DateDemandFactory(
|
||||
$typoScriptService->reveal()
|
||||
);
|
||||
|
||||
$result = $subject->fromSettings([]);
|
||||
|
||||
self::assertInstanceOf(
|
||||
DateDemand::class,
|
||||
$result
|
||||
);
|
||||
}
|
||||
}
|
62
Tests/Unit/Domain/Model/Dto/EventDemandFactoryTest.php
Normal file
62
Tests/Unit/Domain/Model/Dto/EventDemandFactoryTest.php
Normal file
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Copyright (C) 2022 Daniel Siepmann <coding@daniel-siepmann.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
namespace Wrm\Events\Tests\Unit\Domain\Model\Dto;
|
||||
|
||||
use Wrm\Events\Domain\Model\Dto\EventDemand;
|
||||
use Wrm\Events\Domain\Model\Dto\EventDemandFactory;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \Wrm\Events\Domain\Model\Dto\EventDemandFactory
|
||||
*/
|
||||
class EventDemandFactoryTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function canBeCreated(): void
|
||||
{
|
||||
$subject = new EventDemandFactory();
|
||||
|
||||
self::assertInstanceOf(
|
||||
EventDemandFactory::class,
|
||||
$subject
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function fromSettingsDoesNotThrowUndefinedArrayKeyWarnings(): void
|
||||
{
|
||||
$subject = new EventDemandFactory();
|
||||
|
||||
$result = $subject->fromSettings([]);
|
||||
|
||||
self::assertInstanceOf(
|
||||
EventDemand::class,
|
||||
$result
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue