diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5f99865..c67e1e0 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -109,6 +109,42 @@ jobs: - name: TYPO3 language files run: xmllint --schema .Build/xliff-core-1.2-strict.xsd --noout $(find Resources -name '*.xlf') + tests: + runs-on: ubuntu-latest + needs: + - check-dependencies + - xml-linting + strategy: + matrix: + php-version: + - 7.3 + - 7.4 + steps: + - uses: actions/checkout@v2 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: "${{ matrix.php-version }}" + + - name: Get Composer Cache Directory + id: composer-cache + run: | + echo "::set-output name=dir::$(composer config cache-files-dir)" + + - uses: actions/cache@v1 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer- + + - name: Install dependencies + run: composer install --prefer-dist --no-progress --no-suggest + + - name: PHPUnit Tests + run: ./vendor/bin/phpunit --testdox + code-quality: runs-on: ubuntu-latest needs: [check-dependencies] diff --git a/Classes/SettingsFactory.php b/Classes/SettingsFactory.php index ab87e4b..a8821d4 100644 --- a/Classes/SettingsFactory.php +++ b/Classes/SettingsFactory.php @@ -22,31 +22,10 @@ namespace SkillDisplay\Typo3Extension; */ use SkillDisplay\PHPToolKit\Configuration\Settings; -use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Core\Http\ServerRequest; -use TYPO3\CMS\Core\Site\SiteFinder; class SettingsFactory { - /** - * @var SiteFinder - */ - private $siteFinder; - - /** - * @var Context - */ - private $context; - - - public function __construct( - SiteFinder $siteFinder, - Context $context - ) { - $this->siteFinder = $siteFinder; - $this->context = $context; - } - public function createFromCurrentSiteConfiguration(): Settings { $site = $this->getRequest()->getAttribute('site'); @@ -58,7 +37,7 @@ class SettingsFactory return new Settings( $config['skilldisplay_api_key'] ?? '', - ((int)$config['skilldisplay_verifier_id']) ?? 0, + (int)($config['skilldisplay_verifier_id'] ?? 0), $config['skilldisplay_user_secret'] ?? '' ); } diff --git a/Tests/Unit/Backend/PreviewTest.php b/Tests/Unit/Backend/PreviewTest.php new file mode 100644 index 0000000..f2534f6 --- /dev/null +++ b/Tests/Unit/Backend/PreviewTest.php @@ -0,0 +1,194 @@ + + * + * 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 PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; +use SkillDisplay\PHPToolKit\Api\Skill; +use SkillDisplay\PHPToolKit\Api\SkillSet; +use SkillDisplay\PHPToolKit\Entity\Skill as SkillEntity; +use SkillDisplay\PHPToolKit\Entity\SkillSet as SkillSetEntity; +use SkillDisplay\Typo3Extension\Backend\Preview; +use TYPO3\CMS\Backend\View\PageLayoutView; + +/** + * @covers SkillDisplay\Typo3Extension\Backend\Preview + */ +class PreviewTest extends TestCase +{ + use ProphecyTrait; + + /** + * @test + */ + public function instanceCanBeCreated(): void + { + $skillApi = $this->prophesize(Skill::class); + $skillSetApi = $this->prophesize(SkillSet::class); + + $subject = new Preview( + $skillApi->reveal(), + $skillSetApi->reveal() + ); + + static::assertInstanceOf(Preview::class, $subject); + } + + /** + * @test + */ + public function doesReturnEmptyResultsIfNoIds(): void + { + $skillApi = $this->prophesize(Skill::class); + $skillSetApi = $this->prophesize(SkillSet::class); + $pageLayoutView = $this->prophesize(PageLayoutView::class); + + $subject = new Preview( + $skillApi->reveal(), + $skillSetApi->reveal() + ); + + $revealedPageLayoutView = $pageLayoutView->reveal(); + $drawItem = false; + $headerContent = ''; + $itemContent = ''; + $row = [ + 'skilldisplay_skills' => '', + 'skilldisplay_skillset' => '0', + ]; + + $subject->preProcess( + $revealedPageLayoutView, + $drawItem, + $headerContent, + $itemContent, + $row + ); + + static::assertFalse($drawItem); + static::assertEmpty($headerContent); + static::assertEmpty($itemContent); + static::assertSame([ + 'skilldisplay_skills' => '', + 'skilldisplay_skillset' => '0', + 'skills' => [], + 'skillSets' => [], + ], $row); + } + + /** + * @test + */ + public function addsSkillsBasedOnIds(): void + { + $skillApi = $this->prophesize(Skill::class); + $skillSetApi = $this->prophesize(SkillSet::class); + $pageLayoutView = $this->prophesize(PageLayoutView::class); + + $skill10 = $this->prophesize(SkillEntity::class); + $skillApi->getById(10)->willReturn($skill10->reveal()); + $skill20 = $this->prophesize(SkillEntity::class); + $skillApi->getById(20)->willReturn($skill20->reveal()); + + $subject = new Preview( + $skillApi->reveal(), + $skillSetApi->reveal() + ); + + $revealedPageLayoutView = $pageLayoutView->reveal(); + $drawItem = false; + $headerContent = ''; + $itemContent = ''; + $row = [ + 'skilldisplay_skills' => '10, 20,,', + 'skilldisplay_skillset' => '0', + ]; + + $subject->preProcess( + $revealedPageLayoutView, + $drawItem, + $headerContent, + $itemContent, + $row + ); + + static::assertFalse($drawItem); + static::assertEmpty($headerContent); + static::assertEmpty($itemContent); + static::assertSame([ + 'skilldisplay_skills' => '10, 20,,', + 'skilldisplay_skillset' => '0', + 'skills' => [ + $skill10->reveal(), + $skill20->reveal(), + ], + 'skillSets' => [], + ], $row); + } + + /** + * @test + */ + public function addsSkillSetsBasedOnIds(): void + { + $skillApi = $this->prophesize(Skill::class); + $skillSetApi = $this->prophesize(SkillSet::class); + $pageLayoutView = $this->prophesize(PageLayoutView::class); + + $skillSet10 = $this->prophesize(SkillSetEntity::class); + $skillSetApi->getById(10)->willReturn($skillSet10->reveal()); + + $subject = new Preview( + $skillApi->reveal(), + $skillSetApi->reveal() + ); + + $revealedPageLayoutView = $pageLayoutView->reveal(); + $drawItem = false; + $headerContent = ''; + $itemContent = ''; + $row = [ + 'skilldisplay_skills' => '', + 'skilldisplay_skillset' => '10', + ]; + + $subject->preProcess( + $revealedPageLayoutView, + $drawItem, + $headerContent, + $itemContent, + $row + ); + + static::assertFalse($drawItem); + static::assertEmpty($headerContent); + static::assertEmpty($itemContent); + static::assertSame([ + 'skilldisplay_skills' => '', + 'skilldisplay_skillset' => '10', + 'skills' => [], + 'skillSets' => [ + $skillSet10->reveal(), + ], + ], $row); + } +} diff --git a/Tests/Unit/Frontend/DataProcessing/SkillSetsTest.php b/Tests/Unit/Frontend/DataProcessing/SkillSetsTest.php new file mode 100644 index 0000000..3273e20 --- /dev/null +++ b/Tests/Unit/Frontend/DataProcessing/SkillSetsTest.php @@ -0,0 +1,112 @@ + + * + * 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 PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; +use SkillDisplay\PHPToolKit\Api\SkillSet; +use SkillDisplay\PHPToolKit\Entity\SkillSet as SkillSetEntity; +use SkillDisplay\Typo3Extension\Frontend\DataProcessing\SkillSets; +use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; + +/** + * @covers SkillDisplay\Typo3Extension\Frontend\DataProcessing\SkillSets + */ +class SkillSetsTest extends TestCase +{ + use ProphecyTrait; + + /** + * @test + */ + public function instanceCanBeCreated(): void + { + $skillApi = $this->prophesize(SkillSet::class); + $subject = new SkillSets( + $skillApi->reveal() + ); + + static::assertInstanceOf(SkillSets::class, $subject); + } + + /** + * @test + */ + public function addsEmptyArrayIfNoSkillSetsAreProvided(): void + { + $skillApi = $this->prophesize(SkillSet::class); + $cObj = $this->prophesize(ContentObjectRenderer::class); + $cObj->stdWrapValue('as', [], 'skillSets')->willReturn('skillSets'); + $cObj->stdWrapValue('skillSets', [], '')->willReturn(''); + + $subject = new SkillSets( + $skillApi->reveal() + ); + + $processedData = $subject->process( + $cObj->reveal(), + [], + [], + [] + ); + + static::assertEquals([ + 'skillSets' => [], + ], $processedData); + } + + /** + * @test + */ + public function addsSkillSetsAccordinglyToProvidedIds(): void + { + $skillApi = $this->prophesize(SkillSet::class); + $skillSet10 = $this->prophesize(SkillSetEntity::class); + $skillApi->getById(10)->willReturn($skillSet10->reveal()); + $skillSet20 = $this->prophesize(SkillSetEntity::class); + $skillApi->getById(20)->willReturn($skillSet20->reveal()); + + $cObj = $this->prophesize(ContentObjectRenderer::class); + $cObj->stdWrapValue('as', [], 'skillSets')->willReturn('skillSets'); + $cObj->stdWrapValue('skillSets', [], '')->willReturn('10, 20,,'); + + $subject = new SkillSets( + $skillApi->reveal() + ); + + $processedData = $subject->process( + $cObj->reveal(), + [], + [], + [ + 'skillSets' => '10, 20,,', + ] + ); + + static::assertEquals([ + 'skillSets' => [ + $skillSet10->reveal(), + $skillSet20->reveal(), + ], + ], $processedData); + } +} diff --git a/Tests/Unit/Frontend/DataProcessing/SkillsTest.php b/Tests/Unit/Frontend/DataProcessing/SkillsTest.php new file mode 100644 index 0000000..4a78d67 --- /dev/null +++ b/Tests/Unit/Frontend/DataProcessing/SkillsTest.php @@ -0,0 +1,112 @@ + + * + * 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 PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; +use SkillDisplay\PHPToolKit\Api\Skill; +use SkillDisplay\PHPToolKit\Entity\Skill as SkillEntity; +use SkillDisplay\Typo3Extension\Frontend\DataProcessing\Skills; +use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; + +/** + * @covers SkillDisplay\Typo3Extension\Frontend\DataProcessing\Skills + */ +class SkillsTest extends TestCase +{ + use ProphecyTrait; + + /** + * @test + */ + public function instanceCanBeCreated(): void + { + $skillApi = $this->prophesize(Skill::class); + $subject = new Skills( + $skillApi->reveal() + ); + + static::assertInstanceOf(Skills::class, $subject); + } + + /** + * @test + */ + public function addsEmptyArrayIfNoSkillsAreProvided(): void + { + $skillApi = $this->prophesize(Skill::class); + $cObj = $this->prophesize(ContentObjectRenderer::class); + $cObj->stdWrapValue('as', [], 'skills')->willReturn('skills'); + $cObj->stdWrapValue('skills', [], '')->willReturn(''); + + $subject = new Skills( + $skillApi->reveal() + ); + + $processedData = $subject->process( + $cObj->reveal(), + [], + [], + [] + ); + + static::assertEquals([ + 'skills' => [], + ], $processedData); + } + + /** + * @test + */ + public function addsSkillsAccordinglyToProvidedIds(): void + { + $skillApi = $this->prophesize(Skill::class); + $skill10 = $this->prophesize(SkillEntity::class); + $skillApi->getById(10)->willReturn($skill10->reveal()); + $skill20 = $this->prophesize(SkillEntity::class); + $skillApi->getById(20)->willReturn($skill20->reveal()); + + $cObj = $this->prophesize(ContentObjectRenderer::class); + $cObj->stdWrapValue('as', [], 'skills')->willReturn('skills'); + $cObj->stdWrapValue('skills', [], '')->willReturn('10, 20,,'); + + $subject = new Skills( + $skillApi->reveal() + ); + + $processedData = $subject->process( + $cObj->reveal(), + [], + [], + [ + 'skills' => '10, 20,,', + ] + ); + + static::assertEquals([ + 'skills' => [ + $skill10->reveal(), + $skill20->reveal(), + ], + ], $processedData); + } +} diff --git a/Tests/Unit/SettingsFactoryTest.php b/Tests/Unit/SettingsFactoryTest.php new file mode 100644 index 0000000..045994e --- /dev/null +++ b/Tests/Unit/SettingsFactoryTest.php @@ -0,0 +1,112 @@ + + * + * 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 PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; +use SkillDisplay\PHPToolKit\Configuration\Settings; +use SkillDisplay\Typo3Extension\SettingsFactory; +use TYPO3\CMS\Core\Http\ServerRequest; +use TYPO3\CMS\Core\Site\Entity\Site; + +/** + * @covers SkillDisplay\Typo3Extension\SettingsFactory + */ +class SettingsFactoryTest extends TestCase +{ + use ProphecyTrait; + + /** + * @test + */ + public function instanceCanBeCreated(): void + { + $subject = new SettingsFactory(); + static::assertInstanceOf(SettingsFactory::class, $subject); + } + + /** + * @test + */ + public function returnsDefaultSettingsIfNothingIsConfigured(): void + { + $site = $this->prophesize(Site::class); + $site->getConfiguration()->willReturn([]); + + $request = $this->prophesize(ServerRequest::class); + $request->getAttribute('site')->willReturn($site->reveal()); + + $GLOBALS['TYPO3_REQUEST'] = $request->reveal(); + $subject = new SettingsFactory(); + + $settings = $subject->createFromCurrentSiteConfiguration(); + static::assertInstanceOf(Settings::class, $settings); + static::assertSame(0, $settings->getVerifierID()); + static::assertSame('', $settings->getUserSecret()); + static::assertSame('', $settings->getApiKey()); + static::assertSame('https://www.skilldisplay.eu', $settings->getAPIUrl()); + static::assertSame('https://my.skilldisplay.eu', $settings->getMySkillDisplayUrl()); + } + + /** + * @test + */ + public function returnsSettingsFromCurrentSite(): void + { + $site = $this->prophesize(Site::class); + $site->getConfiguration()->willReturn([ + 'skilldisplay_api_key' => '---YOUR-API-KEY---', + 'skilldisplay_verifier_id' => 10, + 'skilldisplay_user_secret' => '---USER-SECRET---', + ]); + + $request = $this->prophesize(ServerRequest::class); + $request->getAttribute('site')->willReturn($site->reveal()); + + $GLOBALS['TYPO3_REQUEST'] = $request->reveal(); + $subject = new SettingsFactory(); + + $settings = $subject->createFromCurrentSiteConfiguration(); + static::assertInstanceOf(Settings::class, $settings); + static::assertSame(10, $settings->getVerifierID()); + static::assertSame('---USER-SECRET---', $settings->getUserSecret()); + static::assertSame('---YOUR-API-KEY---', $settings->getApiKey()); + static::assertSame('https://www.skilldisplay.eu', $settings->getAPIUrl()); + static::assertSame('https://my.skilldisplay.eu', $settings->getMySkillDisplayUrl()); + } + + /** + * @test + */ + public function throwsExceptionIfCurrentSiteCanNotBeFetched(): void + { + $request = $this->prophesize(ServerRequest::class); + $request->getAttribute('site')->willReturn(null); + + $GLOBALS['TYPO3_REQUEST'] = $request->reveal(); + $subject = new SettingsFactory(); + + $this->expectExceptionMessage('Could not determine current site.'); + $this->expectExceptionCode(1599721652); + $subject->createFromCurrentSiteConfiguration(); + } +} diff --git a/Tests/Unit/ViewHelpers/Verification/ButtonViewHelperTest.php b/Tests/Unit/ViewHelpers/Verification/ButtonViewHelperTest.php new file mode 100644 index 0000000..59514dd --- /dev/null +++ b/Tests/Unit/ViewHelpers/Verification/ButtonViewHelperTest.php @@ -0,0 +1,122 @@ + + * + * 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('

expected HTML

'); + GeneralUtility::addInstance(Link::class, $link->reveal()); + + $result = ButtonViewHelper::renderStatic( + [ + 'skill' => 10, + 'type' => 'self', + ], + function () { + }, + $renderingContext->reveal() + ); + static::assertSame('

expected HTML

', $result); + } + + /** + * @test + */ + public function returnsRenderedButtonForSkillSet(): void + { + $renderingContext = $this->prophesize(RenderingContextInterface::class); + $link = $this->prophesize(Link::class); + $link->getVerificationButton('self', 10, Link::SKILL_SET)->willReturn('

expected HTML

'); + GeneralUtility::addInstance(Link::class, $link->reveal()); + + $result = ButtonViewHelper::renderStatic( + [ + 'skillSet' => 10, + 'type' => 'self', + ], + function () { + }, + $renderingContext->reveal() + ); + static::assertSame('

expected HTML

', $result); + } +} diff --git a/Tests/Unit/ViewHelpers/Verification/UrlViewHelperTest.php b/Tests/Unit/ViewHelpers/Verification/UrlViewHelperTest.php new file mode 100644 index 0000000..07062d1 --- /dev/null +++ b/Tests/Unit/ViewHelpers/Verification/UrlViewHelperTest.php @@ -0,0 +1,122 @@ + + * + * 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\UrlViewHelper; +use PHPUnit\Framework\TestCase; +use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; +use TYPO3\CMS\Core\Utility\GeneralUtility; + +/** + * @covers SkillDisplay\Typo3Extension\ViewHelpers\Verification\UrlViewHelper + * @covers SkillDisplay\Typo3Extension\ViewHelpers\VerificationViewHelper + */ +class UrlViewHelperTest 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); + + UrlViewHelper::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); + + UrlViewHelper::renderStatic( + [ + ], + function () { + }, + $renderingContext->reveal() + ); + } + + /** + * @test + */ + public function returnsRenderedUrlForSkill(): void + { + $renderingContext = $this->prophesize(RenderingContextInterface::class); + $link = $this->prophesize(Link::class); + $link->getVerificationLink('self', 10, Link::SKILL)->willReturn('https://example.com/path/to/verification'); + GeneralUtility::addInstance(Link::class, $link->reveal()); + + $result = UrlViewHelper::renderStatic( + [ + 'skill' => 10, + 'type' => 'self', + ], + function () { + }, + $renderingContext->reveal() + ); + static::assertSame('https://example.com/path/to/verification', $result); + } + + /** + * @test + */ + public function returnsRenderedUrlForSkillSet(): void + { + $renderingContext = $this->prophesize(RenderingContextInterface::class); + $link = $this->prophesize(Link::class); + $link->getVerificationLink('self', 10, Link::SKILL_SET)->willReturn('https://example.com/path/to/verification'); + GeneralUtility::addInstance(Link::class, $link->reveal()); + + $result = UrlViewHelper::renderStatic( + [ + 'skillSet' => 10, + 'type' => 'self', + ], + function () { + }, + $renderingContext->reveal() + ); + static::assertSame('https://example.com/path/to/verification', $result); + } +} diff --git a/composer.json b/composer.json index ac79e2f..69ade24 100644 --- a/composer.json +++ b/composer.json @@ -44,9 +44,11 @@ "phpstan/phpstan": "^0.12.18", "phpstan/extension-installer": "^1.0", "maglnet/composer-require-checker": "^2.1", - "phpspec/prophecy-phpunit": "^2.0", + "phpspec/prophecy-phpunit": "^2.0.0", "saschaegerer/phpstan-typo3": "^0.13.1", - "sensiolabs/security-checker": "^6.0" + "sensiolabs/security-checker": "^6.0", + "typo3/testing-framework": "^6.4", + "jangregor/phpstan-prophecy": "^0.8.0" }, "minimum-stability": "dev", "prefer-stable": true, diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 1a01c0b..131338c 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -3,6 +3,7 @@ This project coding standard Classes/ + Tests/ Configuration/ ext_emconf.php ext_localconf.php diff --git a/phpstan.neon b/phpstan.neon index 9cd632b..3d1b1cd 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -2,6 +2,7 @@ parameters: level: max paths: - Classes + - Tests - Configuration - ext_localconf.php checkMissingIterableValueType: false diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..8803eec --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,31 @@ + + + + + + Tests/Unit/ + + + + + + Classes + + +