mirror of
https://github.com/SkillDisplay/TYPO3ContentElements.git
synced 2024-11-22 11:26:08 +01:00
123 lines
3.8 KiB
PHP
123 lines
3.8 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace SkillDisplay\Typo3Extension\Tests\Unit\ViewHelpers\Verification;
|
||
|
|
||
|
/*
|
||
|
* Copyright (C) 2020 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.
|
||
|
*/
|
||
|
|
||
|
use Prophecy\PhpUnit\ProphecyTrait;
|
||
|
use SkillDisplay\PHPToolKit\Verification\Link;
|
||
|
use SkillDisplay\Typo3Extension\ViewHelpers\Verification\ButtonViewHelper;
|
||
|
use PHPUnit\Framework\TestCase;
|
||
|
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
|
||
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||
|
|
||
|
/**
|
||
|
* @covers SkillDisplay\Typo3Extension\ViewHelpers\Verification\ButtonViewHelper
|
||
|
* @covers SkillDisplay\Typo3Extension\ViewHelpers\VerificationViewHelper
|
||
|
*/
|
||
|
class ButtonViewHelperTest extends TestCase
|
||
|
{
|
||
|
use ProphecyTrait;
|
||
|
|
||
|
/**
|
||
|
* @test
|
||
|
*/
|
||
|
public function throwsExceptionIfSkillAndSkillSetIsProvided(): void
|
||
|
{
|
||
|
$renderingContext = $this->prophesize(RenderingContextInterface::class);
|
||
|
|
||
|
$this->expectExceptionMessage('Can only handle skill or skillSet not both.');
|
||
|
$this->expectExceptionCode(1600775604);
|
||
|
|
||
|
ButtonViewHelper::renderStatic(
|
||
|
[
|
||
|
'skill' => 10,
|
||
|
'skillSet' => 10,
|
||
|
],
|
||
|
function () {
|
||
|
},
|
||
|
$renderingContext->reveal()
|
||
|
);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @test
|
||
|
*/
|
||
|
public function throwsExceptionIfNeitherSkillNorSkillSetIsProvided(): void
|
||
|
{
|
||
|
$renderingContext = $this->prophesize(RenderingContextInterface::class);
|
||
|
|
||
|
$this->expectExceptionMessage('Either needs skill or skillSet, none given.');
|
||
|
$this->expectExceptionCode(1600775604);
|
||
|
|
||
|
ButtonViewHelper::renderStatic(
|
||
|
[
|
||
|
],
|
||
|
function () {
|
||
|
},
|
||
|
$renderingContext->reveal()
|
||
|
);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @test
|
||
|
*/
|
||
|
public function returnsRenderedButtonForSkill(): void
|
||
|
{
|
||
|
$renderingContext = $this->prophesize(RenderingContextInterface::class);
|
||
|
$link = $this->prophesize(Link::class);
|
||
|
$link->getVerificationButton('self', 10, Link::SKILL)->willReturn('<p>expected HTML</p>');
|
||
|
GeneralUtility::addInstance(Link::class, $link->reveal());
|
||
|
|
||
|
$result = ButtonViewHelper::renderStatic(
|
||
|
[
|
||
|
'skill' => 10,
|
||
|
'type' => 'self',
|
||
|
],
|
||
|
function () {
|
||
|
},
|
||
|
$renderingContext->reveal()
|
||
|
);
|
||
|
static::assertSame('<p>expected HTML</p>', $result);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @test
|
||
|
*/
|
||
|
public function returnsRenderedButtonForSkillSet(): void
|
||
|
{
|
||
|
$renderingContext = $this->prophesize(RenderingContextInterface::class);
|
||
|
$link = $this->prophesize(Link::class);
|
||
|
$link->getVerificationButton('self', 10, Link::SKILL_SET)->willReturn('<p>expected HTML</p>');
|
||
|
GeneralUtility::addInstance(Link::class, $link->reveal());
|
||
|
|
||
|
$result = ButtonViewHelper::renderStatic(
|
||
|
[
|
||
|
'skillSet' => 10,
|
||
|
'type' => 'self',
|
||
|
],
|
||
|
function () {
|
||
|
},
|
||
|
$renderingContext->reveal()
|
||
|
);
|
||
|
static::assertSame('<p>expected HTML</p>', $result);
|
||
|
}
|
||
|
}
|