Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Classes/DataProcessing/ContainerProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function process(
}
$contentId = null;
if ($processorConfiguration['contentId.'] ?? false) {
$contentId = (int)$cObj->stdWrap($processorConfiguration['contentId'], $processorConfiguration['contentId.']);
$contentId = (int)$cObj->stdWrap($processorConfiguration['contentId'] ?? '', $processorConfiguration['contentId.']);
} elseif ($processorConfiguration['contentId'] ?? false) {
$contentId = (int)$processorConfiguration['contentId'];
}
Expand Down
99 changes: 99 additions & 0 deletions Tests/Unit/DataProcessing/ContainerProcessorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

declare(strict_types=1);

namespace B13\Container\Tests\Unit\DataProcessing;

/*
* This file is part of TYPO3 CMS-based extension "container" by b13.
*
* 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.
*/

use B13\Container\DataProcessing\ContainerProcessor;
use B13\Container\Domain\Factory\FrontendContainerFactory;
use B13\Container\Domain\Model\Container;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Frontend\ContentObject\ContentDataProcessor;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;

class ContainerProcessorTest extends UnitTestCase
{
protected bool $resetSingletonInstances = true;

/**
* @test
*/
public function configuredContentIdIsUsed(): void
{
$processorConfiguration = ['contentId' => 1];
$contentObjectRenderer = $this->getMockBuilder(ContentObjectRenderer::class)->disableOriginalConstructor()->getMock();
$contentObjectRenderer->expects($this->never())->method('stdWrap');
$context = $this->getMockBuilder(Context::class)->getMock();
$contentDataProcessor = $this->getMockBuilder(ContentDataProcessor::class)->disableOriginalConstructor()->getMock();
$frontendContainerFactory = $this->getMockBuilder(FrontendContainerFactory::class)->disableOriginalConstructor()->getMock();
$frontendContainerFactory->expects($this->once())->method('buildContainer')->with(
$contentObjectRenderer, $context, 1
)->willReturn(new Container([], []));
$containerProcessor = new ContainerProcessor($contentDataProcessor, $context, $frontendContainerFactory);
$containerProcessor->process($contentObjectRenderer, [], $processorConfiguration, []);
}

/**
* @test
*/
public function configuredContentIdStdWrapIsUsed(): void
{
$processorConfiguration = ['contentId' => 1, 'contentId.' => 'foo'];
$contentObjectRenderer = $this->getMockBuilder(ContentObjectRenderer::class)->disableOriginalConstructor()->getMock();
$contentObjectRenderer->expects($this->once())->method('stdWrap')->with(1, 'foo')->willReturn(2);
$context = $this->getMockBuilder(Context::class)->getMock();
$contentDataProcessor = $this->getMockBuilder(ContentDataProcessor::class)->disableOriginalConstructor()->getMock();
$frontendContainerFactory = $this->getMockBuilder(FrontendContainerFactory::class)->disableOriginalConstructor()->getMock();
$frontendContainerFactory->expects($this->once())->method('buildContainer')->with(
$contentObjectRenderer, $context, 2
)->willReturn(new Container([], []));
$containerProcessor = new ContainerProcessor($contentDataProcessor, $context, $frontendContainerFactory);
$containerProcessor->process($contentObjectRenderer, [], $processorConfiguration, []);
}

/**
* @test
*/
public function canBeCalledWithoutContentId(): void
{
$processorConfiguration = ['contentId.' => 'foo'];
$contentObjectRenderer = $this->getMockBuilder(ContentObjectRenderer::class)->disableOriginalConstructor()->getMock();
$contentObjectRenderer->expects($this->once())->method('stdWrap')->with('', 'foo')->willReturn(2);
$context = $this->getMockBuilder(Context::class)->getMock();
$contentDataProcessor = $this->getMockBuilder(ContentDataProcessor::class)->disableOriginalConstructor()->getMock();
$frontendContainerFactory = $this->getMockBuilder(FrontendContainerFactory::class)->disableOriginalConstructor()->getMock();
$frontendContainerFactory->expects($this->once())->method('buildContainer')->with(
$contentObjectRenderer, $context, 2
)->willReturn(new Container([], []));
$containerProcessor = new ContainerProcessor($contentDataProcessor, $context, $frontendContainerFactory);
$containerProcessor->process($contentObjectRenderer, [], $processorConfiguration, []);
}

/**
* @test
*/
public function nullIsUsedForFactoryIfNoContentIdIsGiven(): void
{
$processorConfiguration = [];
$contentObjectRenderer = $this->getMockBuilder(ContentObjectRenderer::class)->disableOriginalConstructor()->getMock();
$contentObjectRenderer->expects($this->never())->method('stdWrap');
$context = $this->getMockBuilder(Context::class)->getMock();
$contentDataProcessor = $this->getMockBuilder(ContentDataProcessor::class)->disableOriginalConstructor()->getMock();
$frontendContainerFactory = $this->getMockBuilder(FrontendContainerFactory::class)->disableOriginalConstructor()->getMock();
$frontendContainerFactory->expects($this->once())->method('buildContainer')->with(
$contentObjectRenderer, $context, null
)->willReturn(new Container([], []));
$containerProcessor = new ContainerProcessor($contentDataProcessor, $context, $frontendContainerFactory);
$containerProcessor->process($contentObjectRenderer, [], $processorConfiguration, []);
}

}