Skip to content

Commit 270dd3a

Browse files
committed
[BUGFIX] check array access
Fixes: #590
1 parent 3a75d0f commit 270dd3a

File tree

2 files changed

+100
-1
lines changed

2 files changed

+100
-1
lines changed

Classes/DataProcessing/ContainerProcessor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function process(
5151
}
5252
$contentId = null;
5353
if ($processorConfiguration['contentId.'] ?? false) {
54-
$contentId = (int)$cObj->stdWrap($processorConfiguration['contentId'], $processorConfiguration['contentId.']);
54+
$contentId = (int)$cObj->stdWrap($processorConfiguration['contentId'] ?? '', $processorConfiguration['contentId.']);
5555
} elseif ($processorConfiguration['contentId'] ?? false) {
5656
$contentId = (int)$processorConfiguration['contentId'];
5757
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace B13\Container\Tests\Unit\DataProcessing;
6+
7+
/*
8+
* This file is part of TYPO3 CMS-based extension "container" by b13.
9+
*
10+
* It is free software; you can redistribute it and/or modify it under
11+
* the terms of the GNU General Public License, either version 2
12+
* of the License, or any later version.
13+
*/
14+
15+
use B13\Container\DataProcessing\ContainerProcessor;
16+
use B13\Container\Domain\Factory\FrontendContainerFactory;
17+
use B13\Container\Domain\Model\Container;
18+
use TYPO3\CMS\Core\Context\Context;
19+
use TYPO3\CMS\Frontend\ContentObject\ContentDataProcessor;
20+
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
21+
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22+
23+
class ContainerProcessorTest extends UnitTestCase
24+
{
25+
protected bool $resetSingletonInstances = true;
26+
27+
/**
28+
* @test
29+
*/
30+
public function configuredContentIdIsUsed(): void
31+
{
32+
$processorConfiguration = ['contentId' => 1];
33+
$contentObjectRenderer = $this->getMockBuilder(ContentObjectRenderer::class)->disableOriginalConstructor()->getMock();
34+
$contentObjectRenderer->expects($this->never())->method('stdWrap');
35+
$context = $this->getMockBuilder(Context::class)->getMock();
36+
$contentDataProcessor = $this->getMockBuilder(ContentDataProcessor::class)->disableOriginalConstructor()->getMock();
37+
$frontendContainerFactory = $this->getMockBuilder(FrontendContainerFactory::class)->disableOriginalConstructor()->getMock();
38+
$frontendContainerFactory->expects($this->once())->method('buildContainer')->with(
39+
$contentObjectRenderer, $context, 1
40+
)->willReturn(new Container([], []));
41+
$containerProcessor = new ContainerProcessor($contentDataProcessor, $context, $frontendContainerFactory);
42+
$containerProcessor->process($contentObjectRenderer, [], $processorConfiguration, []);
43+
}
44+
45+
/**
46+
* @test
47+
*/
48+
public function configuredContentIdStdWrapIsUsed(): void
49+
{
50+
$processorConfiguration = ['contentId' => 1, 'contentId.' => 'foo'];
51+
$contentObjectRenderer = $this->getMockBuilder(ContentObjectRenderer::class)->disableOriginalConstructor()->getMock();
52+
$contentObjectRenderer->expects($this->once())->method('stdWrap')->with(1, 'foo')->willReturn(2);
53+
$context = $this->getMockBuilder(Context::class)->getMock();
54+
$contentDataProcessor = $this->getMockBuilder(ContentDataProcessor::class)->disableOriginalConstructor()->getMock();
55+
$frontendContainerFactory = $this->getMockBuilder(FrontendContainerFactory::class)->disableOriginalConstructor()->getMock();
56+
$frontendContainerFactory->expects($this->once())->method('buildContainer')->with(
57+
$contentObjectRenderer, $context, 2
58+
)->willReturn(new Container([], []));
59+
$containerProcessor = new ContainerProcessor($contentDataProcessor, $context, $frontendContainerFactory);
60+
$containerProcessor->process($contentObjectRenderer, [], $processorConfiguration, []);
61+
}
62+
63+
/**
64+
* @test
65+
*/
66+
public function canBeCalledWithoutContentId(): void
67+
{
68+
$processorConfiguration = ['contentId.' => 'foo'];
69+
$contentObjectRenderer = $this->getMockBuilder(ContentObjectRenderer::class)->disableOriginalConstructor()->getMock();
70+
$contentObjectRenderer->expects($this->once())->method('stdWrap')->with('', 'foo')->willReturn(2);
71+
$context = $this->getMockBuilder(Context::class)->getMock();
72+
$contentDataProcessor = $this->getMockBuilder(ContentDataProcessor::class)->disableOriginalConstructor()->getMock();
73+
$frontendContainerFactory = $this->getMockBuilder(FrontendContainerFactory::class)->disableOriginalConstructor()->getMock();
74+
$frontendContainerFactory->expects($this->once())->method('buildContainer')->with(
75+
$contentObjectRenderer, $context, 2
76+
)->willReturn(new Container([], []));
77+
$containerProcessor = new ContainerProcessor($contentDataProcessor, $context, $frontendContainerFactory);
78+
$containerProcessor->process($contentObjectRenderer, [], $processorConfiguration, []);
79+
}
80+
81+
/**
82+
* @test
83+
*/
84+
public function nullIsUsedForFactoryIfNoContentIdIsGiven(): void
85+
{
86+
$processorConfiguration = [];
87+
$contentObjectRenderer = $this->getMockBuilder(ContentObjectRenderer::class)->disableOriginalConstructor()->getMock();
88+
$contentObjectRenderer->expects($this->never())->method('stdWrap');
89+
$context = $this->getMockBuilder(Context::class)->getMock();
90+
$contentDataProcessor = $this->getMockBuilder(ContentDataProcessor::class)->disableOriginalConstructor()->getMock();
91+
$frontendContainerFactory = $this->getMockBuilder(FrontendContainerFactory::class)->disableOriginalConstructor()->getMock();
92+
$frontendContainerFactory->expects($this->once())->method('buildContainer')->with(
93+
$contentObjectRenderer, $context, null
94+
)->willReturn(new Container([], []));
95+
$containerProcessor = new ContainerProcessor($contentDataProcessor, $context, $frontendContainerFactory);
96+
$containerProcessor->process($contentObjectRenderer, [], $processorConfiguration, []);
97+
}
98+
99+
}

0 commit comments

Comments
 (0)