mirror of
https://github.com/SkillDisplay/TYPO3ContentElements.git
synced 2024-11-21 19:16:08 +01:00
Merge pull request #6 from SkillDisplay/bugfix/5-allow-creation-of-content-elements
Allow creation of content elements
This commit is contained in:
commit
19b7a950bc
10 changed files with 368 additions and 10 deletions
57
Classes/CampaignsFactory.php
Normal file
57
Classes/CampaignsFactory.php
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace SkillDisplay\Typo3Extension;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2021 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 GuzzleHttp\Client;
|
||||||
|
use SkillDisplay\PHPToolKit\Api\Campaigns;
|
||||||
|
use SkillDisplay\Typo3Extension\SettingsFactory;
|
||||||
|
|
||||||
|
class CampaignsFactory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var SettingsFactory
|
||||||
|
*/
|
||||||
|
private $settingsFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Client
|
||||||
|
*/
|
||||||
|
private $client;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
SettingsFactory $settingsFactory,
|
||||||
|
Client $client
|
||||||
|
) {
|
||||||
|
$this->settingsFactory = $settingsFactory;
|
||||||
|
$this->client = $client;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createFromPageUid(int $pageUid): Campaigns
|
||||||
|
{
|
||||||
|
return new Campaigns(
|
||||||
|
$this->settingsFactory->createFromPageUid($pageUid),
|
||||||
|
$this->client
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -25,9 +25,22 @@ namespace SkillDisplay\Typo3Extension;
|
||||||
|
|
||||||
use SkillDisplay\PHPToolKit\Configuration\Settings;
|
use SkillDisplay\PHPToolKit\Configuration\Settings;
|
||||||
use TYPO3\CMS\Core\Http\ServerRequest;
|
use TYPO3\CMS\Core\Http\ServerRequest;
|
||||||
|
use TYPO3\CMS\Core\Site\Entity\Site;
|
||||||
|
use TYPO3\CMS\Core\Site\SiteFinder;
|
||||||
|
|
||||||
class SettingsFactory
|
class SettingsFactory
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var SiteFinder
|
||||||
|
*/
|
||||||
|
private $siteFinder;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
SiteFinder $siteFinder
|
||||||
|
) {
|
||||||
|
$this->siteFinder = $siteFinder;
|
||||||
|
}
|
||||||
|
|
||||||
public function createFromCurrentSiteConfiguration(): Settings
|
public function createFromCurrentSiteConfiguration(): Settings
|
||||||
{
|
{
|
||||||
$site = $this->getRequest()->getAttribute('site');
|
$site = $this->getRequest()->getAttribute('site');
|
||||||
|
@ -35,6 +48,18 @@ class SettingsFactory
|
||||||
throw new \Exception('Could not determine current site.', 1599721652);
|
throw new \Exception('Could not determine current site.', 1599721652);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $this->createFromSite($site);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createFromPageUid(int $pageUid): Settings
|
||||||
|
{
|
||||||
|
$site = $this->siteFinder->getSiteByPageId($pageUid);
|
||||||
|
|
||||||
|
return $this->createFromSite($site);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createFromSite(Site $site): Settings
|
||||||
|
{
|
||||||
$config = $site->getConfiguration();
|
$config = $site->getConfiguration();
|
||||||
|
|
||||||
return new Settings(
|
return new Settings(
|
||||||
|
|
|
@ -4,19 +4,30 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace SkillDisplay\Typo3Extension;
|
namespace SkillDisplay\Typo3Extension;
|
||||||
|
|
||||||
use SkillDisplay\PHPToolKit\Api\Campaigns;
|
|
||||||
use SkillDisplay\PHPToolKit\Entity\Campaign;
|
use SkillDisplay\PHPToolKit\Entity\Campaign;
|
||||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
|
||||||
|
|
||||||
class TcaEnhancer
|
class TcaEnhancer
|
||||||
{
|
{
|
||||||
public function getCampaignsForTCA(array $params): void
|
/**
|
||||||
|
* @var CampaignsFactory
|
||||||
|
*/
|
||||||
|
private $campaignsFactory;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
CampaignsFactory $campaignsFactory
|
||||||
|
) {
|
||||||
|
$this->campaignsFactory = $campaignsFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCampaignsForTCA(array &$params): void
|
||||||
{
|
{
|
||||||
$params['items'] = [
|
$params['items'] = [
|
||||||
['', 0],
|
['', 0],
|
||||||
];
|
];
|
||||||
|
|
||||||
$campaigns = GeneralUtility::makeInstance(Campaigns::class)->getForUser();
|
$campaigns = $this->campaignsFactory
|
||||||
|
->createFromPageUid($params['row']['pid'])
|
||||||
|
->getForUser();
|
||||||
/** @var Campaign $campaign */
|
/** @var Campaign $campaign */
|
||||||
foreach ($campaigns as $campaign) {
|
foreach ($campaigns as $campaign) {
|
||||||
$params['items'][] = [
|
$params['items'][] = [
|
||||||
|
|
|
@ -39,3 +39,6 @@ services:
|
||||||
|
|
||||||
SkillDisplay\Typo3Extension\Backend\Preview:
|
SkillDisplay\Typo3Extension\Backend\Preview:
|
||||||
public: true
|
public: true
|
||||||
|
|
||||||
|
SkillDisplay\Typo3Extension\TcaEnhancer:
|
||||||
|
public: true
|
||||||
|
|
|
@ -33,7 +33,9 @@
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'skilldisplay_campaign' => [
|
'skilldisplay_campaign' => [
|
||||||
|
'exclude' => 1,
|
||||||
'label' => $languagePath . 'skilldisplay_campaign',
|
'label' => $languagePath . 'skilldisplay_campaign',
|
||||||
|
'description' => $languagePath . 'skilldisplay_campaign.description',
|
||||||
'config' => [
|
'config' => [
|
||||||
'type' => 'select',
|
'type' => 'select',
|
||||||
'renderType' => 'selectSingle',
|
'renderType' => 'selectSingle',
|
||||||
|
|
|
@ -17,6 +17,12 @@
|
||||||
<trans-unit id="tt_content.skilldisplay_skillset.description" resname="tt_content.skilldisplay_skillset.description">
|
<trans-unit id="tt_content.skilldisplay_skillset.description" resname="tt_content.skilldisplay_skillset.description">
|
||||||
<source>UID of SkillSet</source>
|
<source>UID of SkillSet</source>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
|
<trans-unit id="tt_content.skilldisplay_campaign" resname="tt_content.skilldisplay_campaign">
|
||||||
|
<source>Campaign</source>
|
||||||
|
</trans-unit>
|
||||||
|
<trans-unit id="tt_content.skilldisplay_campaign.description" resname="tt_content.skilldisplay_campaign.description">
|
||||||
|
<source>Fetched from API.</source>
|
||||||
|
</trans-unit>
|
||||||
</body>
|
</body>
|
||||||
</file>
|
</file>
|
||||||
</xliff>
|
</xliff>
|
||||||
|
|
77
Tests/Unit/CampaignsFactoryTest.php
Normal file
77
Tests/Unit/CampaignsFactoryTest.php
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace SkillDisplay\Typo3Extension\Tests\Unit;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2021 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 GuzzleHttp\Client;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Prophecy\PhpUnit\ProphecyTrait;
|
||||||
|
use SkillDisplay\PHPToolKit\Api\Campaigns;
|
||||||
|
use SkillDisplay\PHPToolKit\Configuration\Settings;
|
||||||
|
use SkillDisplay\Typo3Extension\CampaignsFactory;
|
||||||
|
use SkillDisplay\Typo3Extension\SettingsFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers SkillDisplay\Typo3Extension\CampaignsFactory
|
||||||
|
*/
|
||||||
|
class CampaignsFactoryTest extends TestCase
|
||||||
|
{
|
||||||
|
use ProphecyTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function instanceCanBeCreated(): void
|
||||||
|
{
|
||||||
|
$settingsFactory = $this->prophesize(SettingsFactory::class);
|
||||||
|
$client = $this->prophesize(Client::class);
|
||||||
|
|
||||||
|
$subject = new CampaignsFactory(
|
||||||
|
$settingsFactory->reveal(),
|
||||||
|
$client->reveal()
|
||||||
|
);
|
||||||
|
|
||||||
|
self::assertInstanceOf(CampaignsFactory::class, $subject);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function returnsCampaignsFromPageUid(): void
|
||||||
|
{
|
||||||
|
$settingsFactory = $this->prophesize(SettingsFactory::class);
|
||||||
|
$settings = $this->prophesize(Settings::class);
|
||||||
|
$client = $this->prophesize(Client::class);
|
||||||
|
|
||||||
|
$settingsFactory->createFromPageUid(10)->willReturn($settings->reveal());
|
||||||
|
|
||||||
|
$subject = new CampaignsFactory(
|
||||||
|
$settingsFactory->reveal(),
|
||||||
|
$client->reveal()
|
||||||
|
);
|
||||||
|
|
||||||
|
$result = $subject->createFromPageUid(10);
|
||||||
|
|
||||||
|
self::assertInstanceOf(Campaigns::class, $result);
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,6 +28,7 @@ use SkillDisplay\PHPToolKit\Configuration\Settings;
|
||||||
use SkillDisplay\Typo3Extension\SettingsFactory;
|
use SkillDisplay\Typo3Extension\SettingsFactory;
|
||||||
use TYPO3\CMS\Core\Http\ServerRequest;
|
use TYPO3\CMS\Core\Http\ServerRequest;
|
||||||
use TYPO3\CMS\Core\Site\Entity\Site;
|
use TYPO3\CMS\Core\Site\Entity\Site;
|
||||||
|
use TYPO3\CMS\Core\Site\SiteFinder;
|
||||||
use TYPO3\TestingFramework\Core\Unit\UnitTestCase as TestCase;
|
use TYPO3\TestingFramework\Core\Unit\UnitTestCase as TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,15 +43,18 @@ class SettingsFactoryTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function instanceCanBeCreated(): void
|
public function instanceCanBeCreated(): void
|
||||||
{
|
{
|
||||||
$subject = new SettingsFactory();
|
$siteFinder = $this->prophesize(SiteFinder::class);
|
||||||
|
$subject = new SettingsFactory($siteFinder->reveal());
|
||||||
static::assertInstanceOf(SettingsFactory::class, $subject);
|
static::assertInstanceOf(SettingsFactory::class, $subject);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function returnsDefaultSettingsIfNothingIsConfigured(): void
|
public function returnsDefaultSettingsIfNothingIsConfiguredInCurrentSite(): void
|
||||||
{
|
{
|
||||||
|
$siteFinder = $this->prophesize(SiteFinder::class);
|
||||||
|
|
||||||
$site = $this->prophesize(Site::class);
|
$site = $this->prophesize(Site::class);
|
||||||
$site->getConfiguration()->willReturn([]);
|
$site->getConfiguration()->willReturn([]);
|
||||||
|
|
||||||
|
@ -58,7 +62,7 @@ class SettingsFactoryTest extends TestCase
|
||||||
$request->getAttribute('site')->willReturn($site->reveal());
|
$request->getAttribute('site')->willReturn($site->reveal());
|
||||||
|
|
||||||
$GLOBALS['TYPO3_REQUEST'] = $request->reveal();
|
$GLOBALS['TYPO3_REQUEST'] = $request->reveal();
|
||||||
$subject = new SettingsFactory();
|
$subject = new SettingsFactory($siteFinder->reveal());
|
||||||
|
|
||||||
$settings = $subject->createFromCurrentSiteConfiguration();
|
$settings = $subject->createFromCurrentSiteConfiguration();
|
||||||
static::assertInstanceOf(Settings::class, $settings);
|
static::assertInstanceOf(Settings::class, $settings);
|
||||||
|
@ -74,6 +78,8 @@ class SettingsFactoryTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function returnsSettingsFromCurrentSite(): void
|
public function returnsSettingsFromCurrentSite(): void
|
||||||
{
|
{
|
||||||
|
$siteFinder = $this->prophesize(SiteFinder::class);
|
||||||
|
|
||||||
$site = $this->prophesize(Site::class);
|
$site = $this->prophesize(Site::class);
|
||||||
$site->getConfiguration()->willReturn([
|
$site->getConfiguration()->willReturn([
|
||||||
'skilldisplay_api_key' => '---YOUR-API-KEY---',
|
'skilldisplay_api_key' => '---YOUR-API-KEY---',
|
||||||
|
@ -85,7 +91,7 @@ class SettingsFactoryTest extends TestCase
|
||||||
$request->getAttribute('site')->willReturn($site->reveal());
|
$request->getAttribute('site')->willReturn($site->reveal());
|
||||||
|
|
||||||
$GLOBALS['TYPO3_REQUEST'] = $request->reveal();
|
$GLOBALS['TYPO3_REQUEST'] = $request->reveal();
|
||||||
$subject = new SettingsFactory();
|
$subject = new SettingsFactory($siteFinder->reveal());
|
||||||
|
|
||||||
$settings = $subject->createFromCurrentSiteConfiguration();
|
$settings = $subject->createFromCurrentSiteConfiguration();
|
||||||
static::assertInstanceOf(Settings::class, $settings);
|
static::assertInstanceOf(Settings::class, $settings);
|
||||||
|
@ -101,14 +107,64 @@ class SettingsFactoryTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function throwsExceptionIfCurrentSiteCanNotBeFetched(): void
|
public function throwsExceptionIfCurrentSiteCanNotBeFetched(): void
|
||||||
{
|
{
|
||||||
|
$siteFinder = $this->prophesize(SiteFinder::class);
|
||||||
|
|
||||||
$request = $this->prophesize(ServerRequest::class);
|
$request = $this->prophesize(ServerRequest::class);
|
||||||
$request->getAttribute('site')->willReturn(null);
|
$request->getAttribute('site')->willReturn(null);
|
||||||
|
|
||||||
$GLOBALS['TYPO3_REQUEST'] = $request->reveal();
|
$GLOBALS['TYPO3_REQUEST'] = $request->reveal();
|
||||||
$subject = new SettingsFactory();
|
$subject = new SettingsFactory($siteFinder->reveal());
|
||||||
|
|
||||||
$this->expectExceptionMessage('Could not determine current site.');
|
$this->expectExceptionMessage('Could not determine current site.');
|
||||||
$this->expectExceptionCode(1599721652);
|
$this->expectExceptionCode(1599721652);
|
||||||
$subject->createFromCurrentSiteConfiguration();
|
$subject->createFromCurrentSiteConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function returnsDefaultSettingsIfNothingIsConfiguredForPageUidBasesSite(): void
|
||||||
|
{
|
||||||
|
$site = $this->prophesize(Site::class);
|
||||||
|
$site->getConfiguration()->willReturn([]);
|
||||||
|
|
||||||
|
$siteFinder = $this->prophesize(SiteFinder::class);
|
||||||
|
$siteFinder->getSiteByPageId(10)->willReturn($site->reveal());
|
||||||
|
|
||||||
|
$subject = new SettingsFactory($siteFinder->reveal());
|
||||||
|
|
||||||
|
$settings = $subject->createFromPageUid(10);
|
||||||
|
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 returnsSettingsFromPageUidBasedSite(): void
|
||||||
|
{
|
||||||
|
$site = $this->prophesize(Site::class);
|
||||||
|
$site->getConfiguration()->willReturn([
|
||||||
|
'skilldisplay_api_key' => '---YOUR-API-KEY---',
|
||||||
|
'skilldisplay_verifier_id' => 10,
|
||||||
|
'skilldisplay_user_secret' => '---USER-SECRET---',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$siteFinder = $this->prophesize(SiteFinder::class);
|
||||||
|
$siteFinder->getSiteByPageId(10)->willReturn($site->reveal());
|
||||||
|
|
||||||
|
$subject = new SettingsFactory($siteFinder->reveal());
|
||||||
|
|
||||||
|
$settings = $subject->createFromPageUid(10);
|
||||||
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
120
Tests/Unit/TcaEnhancerTest.php
Normal file
120
Tests/Unit/TcaEnhancerTest.php
Normal file
|
@ -0,0 +1,120 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace SkillDisplay\Typo3Extension\Tests\Unit;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2021 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 PHPUnit\Framework\TestCase;
|
||||||
|
use Prophecy\PhpUnit\ProphecyTrait;
|
||||||
|
use SkillDisplay\PHPToolKit\Api\Campaigns;
|
||||||
|
use SkillDisplay\PHPToolKit\Entity\Campaign;
|
||||||
|
use SkillDisplay\Typo3Extension\CampaignsFactory;
|
||||||
|
use SkillDisplay\Typo3Extension\TcaEnhancer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers SkillDisplay\Typo3Extension\TcaEnhancer
|
||||||
|
*/
|
||||||
|
class TcaEnhancerTest extends TestCase
|
||||||
|
{
|
||||||
|
use ProphecyTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function instanceCanBeCreated(): void
|
||||||
|
{
|
||||||
|
$campaignsFactory = $this->prophesize(CampaignsFactory::class);
|
||||||
|
$subject = new TcaEnhancer(
|
||||||
|
$campaignsFactory->reveal()
|
||||||
|
);
|
||||||
|
|
||||||
|
self::assertInstanceOf(TcaEnhancer::class, $subject);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function addsDefaultItemOnlyWhenNoCampaignsAreAvailable(): void
|
||||||
|
{
|
||||||
|
$parameters = [
|
||||||
|
'row' => [
|
||||||
|
'pid' => 10,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$campaigns = $this->prophesize(Campaigns::class);
|
||||||
|
$campaigns->getForUser()->willReturn([]);
|
||||||
|
|
||||||
|
$campaignsFactory = $this->prophesize(CampaignsFactory::class);
|
||||||
|
$campaignsFactory->createFromPageUid(10)->willReturn($campaigns->reveal());
|
||||||
|
|
||||||
|
$subject = new TcaEnhancer(
|
||||||
|
$campaignsFactory->reveal()
|
||||||
|
);
|
||||||
|
$subject->getCampaignsForTCA($parameters);
|
||||||
|
|
||||||
|
self::assertArrayHasKey('items', $parameters);
|
||||||
|
self::assertSame([
|
||||||
|
['', 0],
|
||||||
|
], $parameters['items']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function addsFetchedCampaignsBesideDefault(): void
|
||||||
|
{
|
||||||
|
$parameters = [
|
||||||
|
'row' => [
|
||||||
|
'pid' => 10,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$campaign1 = $this->prophesize(Campaign::class);
|
||||||
|
$campaign1->getTitle()->willReturn('Campaign Title 1');
|
||||||
|
$campaign1->getId()->willReturn(10);
|
||||||
|
$campaign2 = $this->prophesize(Campaign::class);
|
||||||
|
$campaign2->getTitle()->willReturn('Campaign Title 2');
|
||||||
|
$campaign2->getId()->willReturn(20);
|
||||||
|
|
||||||
|
$campaigns = $this->prophesize(Campaigns::class);
|
||||||
|
$campaigns->getForUser()->willReturn([
|
||||||
|
$campaign1->reveal(),
|
||||||
|
$campaign2->reveal(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$campaignsFactory = $this->prophesize(CampaignsFactory::class);
|
||||||
|
$campaignsFactory->createFromPageUid(10)->willReturn($campaigns->reveal());
|
||||||
|
|
||||||
|
$subject = new TcaEnhancer(
|
||||||
|
$campaignsFactory->reveal()
|
||||||
|
);
|
||||||
|
$subject->getCampaignsForTCA($parameters);
|
||||||
|
|
||||||
|
self::assertArrayHasKey('items', $parameters);
|
||||||
|
self::assertSame([
|
||||||
|
['', 0],
|
||||||
|
['Campaign Title 1', 10],
|
||||||
|
['Campaign Title 2', 20],
|
||||||
|
], $parameters['items']);
|
||||||
|
}
|
||||||
|
}
|
|
@ -31,7 +31,8 @@
|
||||||
"skilldisplay/phptoolkit": "^1.2",
|
"skilldisplay/phptoolkit": "^1.2",
|
||||||
"typo3/cms-backend": "^10.4",
|
"typo3/cms-backend": "^10.4",
|
||||||
"typo3/cms-frontend": "^10.4",
|
"typo3/cms-frontend": "^10.4",
|
||||||
"typo3fluid/fluid": "^2.6"
|
"typo3fluid/fluid": "^2.6",
|
||||||
|
"guzzlehttp/guzzle": "^6.5"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"squizlabs/php_codesniffer": "^3.5",
|
"squizlabs/php_codesniffer": "^3.5",
|
||||||
|
|
Loading…
Reference in a new issue