Initial commit - Typo3 11.5.41
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FriendsOfTypo3\TtAddress\Tests\Unit\Command;
|
||||
|
||||
/**
|
||||
* This file is part of the "tt_address" Extension for TYPO3 CMS.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*/
|
||||
use FriendsOfTYPO3\TtAddress\Command\GeocodeCommand;
|
||||
use FriendsOfTYPO3\TtAddress\Service\GeocodeService;
|
||||
use Symfony\Component\Console\Input\StringInput;
|
||||
use Symfony\Component\Console\Output\ConsoleOutput;
|
||||
use TYPO3\TestingFramework\Core\BaseTestCase;
|
||||
|
||||
class GeocodeCommandTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function configurationIsProperlyConfigured()
|
||||
{
|
||||
$subject = $this->getAccessibleMock(GeocodeCommand::class, ['addArgument'], [], '', false);
|
||||
$subject->_call('configure');
|
||||
$this->assertEquals('Geocode tt_address records', $subject->getDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function geocodeServiceIsReturned()
|
||||
{
|
||||
$subject = $this->getAccessibleMock(GeocodeCommand::class, null, [], '', false);
|
||||
$service = $subject->_call('getGeocodeService', '123');
|
||||
$this->assertEquals(GeocodeService::class, get_class($service));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function geocodingIsCalled()
|
||||
{
|
||||
$geocodeService = $this->getAccessibleMock(GeocodeService::class, ['calculateCoordinatesForAllRecordsInTable'], [], '', false);
|
||||
$geocodeService->expects($this->once())->method('calculateCoordinatesForAllRecordsInTable');
|
||||
|
||||
$subject = $this->getAccessibleMock(GeocodeCommand::class, ['getGeocodeService'], [], '', false);
|
||||
$subject->expects($this->once())->method('getGeocodeService')->willReturn($geocodeService);
|
||||
|
||||
$input = $this->getAccessibleMock(StringInput::class, ['getArgument'], [], '', false);
|
||||
$input->expects($this->once())->method('getArgument')->willReturn('123');
|
||||
|
||||
$output = $this->getAccessibleMock(ConsoleOutput::class, null, []);
|
||||
$subject->_call('execute', $input, $output);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
namespace FriendsOfTypo3\TtAddress\Tests\Unit\Controller;
|
||||
|
||||
/**
|
||||
* This file is part of the "tt_address" Extension for TYPO3 CMS.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use FriendsOfTYPO3\TtAddress\Controller\AddressController;
|
||||
use FriendsOfTYPO3\TtAddress\Domain\Model\Dto\Demand;
|
||||
use FriendsOfTYPO3\TtAddress\Domain\Model\Dto\Settings;
|
||||
use FriendsOfTYPO3\TtAddress\Domain\Repository\AddressRepository;
|
||||
use TYPO3\CMS\Core\Pagination\PaginatorInterface;
|
||||
use TYPO3\CMS\Core\Pagination\SimplePagination;
|
||||
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
|
||||
use TYPO3\CMS\Extbase\Mvc\Request;
|
||||
use TYPO3\CMS\Fluid\View\TemplateView;
|
||||
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
|
||||
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
|
||||
use TYPO3\TestingFramework\Core\BaseTestCase;
|
||||
|
||||
class AddressControllerPaginationTest extends BaseTestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
$GLOBALS['TSFE'] = $this->getAccessibleMock(TypoScriptFrontendController::class, ['addCacheTags'], [], '', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function listActionUsesNewPaginationWithArrayRecords()
|
||||
{
|
||||
if (!class_exists(SimplePagination::class)) {
|
||||
$this->markTestSkipped('Ignore test as new pagination is not available');
|
||||
}
|
||||
$settings = [
|
||||
'singlePid' => 0,
|
||||
'singleRecords' => 1,
|
||||
'paginate' => [
|
||||
'itemsPerPage' => 3
|
||||
]
|
||||
];
|
||||
$demand = new Demand();
|
||||
$demand->setSingleRecords('134');
|
||||
|
||||
$mockedRepository = $this->getAccessibleMock(AddressRepository::class, ['getAddressesByCustomSorting'], [], '', false);
|
||||
|
||||
$rows = [];
|
||||
for ($i = 1; $i <= 10; $i++) {
|
||||
$rows[] = [
|
||||
'uid' => $i,
|
||||
'title' => 'record #' . $i
|
||||
];
|
||||
}
|
||||
$assignments = [
|
||||
'demand' => $demand,
|
||||
'addresses' => $rows,
|
||||
'contentObjectData' => [],
|
||||
];
|
||||
|
||||
$mockedRepository->expects($this->once())->method('getAddressesByCustomSorting')->willReturn($rows);
|
||||
|
||||
$mockedRequest = $this->getAccessibleMock(Request::class, ['hasArgument', 'getArgument'], [], '', false);
|
||||
$mockedRequest->expects($this->once())->method('hasArgument')->with('currentPage')->willReturn(true);
|
||||
$mockedRequest->expects($this->once())->method('getArgument')->with('currentPage')->willReturn(2);
|
||||
|
||||
$mockedView = $this->getAccessibleMock(TemplateView::class, ['assignMultiple', 'assign'], [], '', false);
|
||||
$mockedView->expects($this->once())->method('assignMultiple')->with($assignments);
|
||||
$mockedView->expects($this->any())->method('assign')
|
||||
->withConsecutive(
|
||||
['newPagination', true],
|
||||
['pagination'] // the result can't be mocked, therefore just testing if it exists
|
||||
);
|
||||
|
||||
$mockContentObject = $this->createMock(ContentObjectRenderer::class);
|
||||
$mockConfigurationManager = $this->createMock(ConfigurationManager::class);
|
||||
$mockConfigurationManager->method('getContentObject')
|
||||
->willReturn($mockContentObject);
|
||||
|
||||
$subject = $this->getAccessibleMock(AddressController::class, ['createDemandFromSettings', 'htmlResponse'], [], '', false);
|
||||
$subject->expects($this->once())->method('createDemandFromSettings')->willReturn($demand);
|
||||
$subject->expects($this->once())->method('htmlResponse');
|
||||
$subject->_set('settings', $settings);
|
||||
$subject->_set('view', $mockedView);
|
||||
$subject->_set('request', $mockedRequest);
|
||||
$subject->_set('addressRepository', $mockedRepository);
|
||||
$subject->_set('extensionConfiguration', $this->getMockedSettings());
|
||||
$subject->_set('configurationManager', $mockConfigurationManager);
|
||||
|
||||
$subject->listAction();
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function paginationIsCorrectlyTriggered()
|
||||
{
|
||||
if (!class_exists(SimplePagination::class)) {
|
||||
$this->markTestSkipped('Ignore test as new pagination is not available');
|
||||
}
|
||||
|
||||
$settings = [
|
||||
'singlePid' => 0,
|
||||
'singleRecords' => 1,
|
||||
'paginate' => [
|
||||
'itemsPerPage' => 3
|
||||
]
|
||||
];
|
||||
|
||||
$rows = [];
|
||||
for ($i = 1; $i <= 10; $i++) {
|
||||
$rows[] = [
|
||||
'uid' => $i,
|
||||
'title' => 'record #' . $i
|
||||
];
|
||||
}
|
||||
|
||||
$mockedRequest = $this->getAccessibleMock(Request::class, ['hasArgument', 'getArgument'], [], '', false);
|
||||
$mockedRequest->expects($this->once())->method('hasArgument')->with('currentPage')->willReturn(true);
|
||||
$mockedRequest->expects($this->once())->method('getArgument')->with('currentPage')->willReturn(2);
|
||||
|
||||
$subject = $this->getAccessibleMock(AddressController::class, null, [], '', false);
|
||||
$subject->_set('settings', $settings);
|
||||
$subject->_set('request', $mockedRequest);
|
||||
|
||||
/** @var PaginatorInterface $paginator */
|
||||
$paginator = $subject->_call('getPaginator', $rows);
|
||||
$this->assertEquals($paginator->getPaginatedItems(), array_splice($rows, 3, 3));
|
||||
}
|
||||
|
||||
protected function getMockedSettings()
|
||||
{
|
||||
$mockedSettings = $this->getAccessibleMock(Settings::class, ['getSettings'], [], '', false);
|
||||
$mockedSettings->expects($this->any())->method('getSettings')->willReturn([]);
|
||||
|
||||
return $mockedSettings;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,392 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FriendsOfTypo3\TtAddress\Tests\Unit\Controller;
|
||||
|
||||
/**
|
||||
* This file is part of the "tt_address" Extension for TYPO3 CMS.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use FriendsOfTYPO3\TtAddress\Controller\AddressController;
|
||||
use FriendsOfTYPO3\TtAddress\Database\QueryGenerator;
|
||||
use FriendsOfTYPO3\TtAddress\Domain\Model\Address;
|
||||
use FriendsOfTYPO3\TtAddress\Domain\Model\Dto\Demand;
|
||||
use FriendsOfTYPO3\TtAddress\Domain\Model\Dto\Settings;
|
||||
use FriendsOfTYPO3\TtAddress\Domain\Repository\AddressRepository;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use TYPO3\CMS\Core\Package\PackageManager;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
|
||||
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
|
||||
use TYPO3\CMS\Extbase\Mvc\Request;
|
||||
use TYPO3\CMS\Fluid\View\TemplateView;
|
||||
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
|
||||
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
|
||||
use TYPO3\TestingFramework\Core\BaseTestCase;
|
||||
|
||||
class AddressControllerTest extends BaseTestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$GLOBALS['TSFE'] = $this->getAccessibleMock(TypoScriptFrontendController::class, ['addCacheTags'], [], '', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $given
|
||||
* @param $expected
|
||||
* @test
|
||||
* @dataProvider dotIsRemovedFromEndDataProvider
|
||||
*/
|
||||
public function dotIsRemovedFromEnd($given, $expected)
|
||||
{
|
||||
$subject = $this->getAccessibleMock(AddressController::class, null, [], '', false);
|
||||
$this->assertEquals($expected, $subject->_call('removeDotAtTheEnd', $given));
|
||||
}
|
||||
|
||||
public function dotIsRemovedFromEndDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'empty string' => ['', ''],
|
||||
'dot at end' => ['foBar.', 'foBar'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function dotsAreRemovedFromArray()
|
||||
{
|
||||
$subject = $this->getAccessibleMock(AddressController::class, null, [], '', false);
|
||||
$given = [
|
||||
'example' => 'some string',
|
||||
'example2' => '123',
|
||||
'example with dot.' => 'bla',
|
||||
'array' => [
|
||||
'sub' => 'string',
|
||||
'sub-with-dot.' => 'stringvalue',
|
||||
],
|
||||
];
|
||||
$expected = [
|
||||
'example' => 'some string',
|
||||
'example2' => '123',
|
||||
'example with dot' => 'bla',
|
||||
'array' => [
|
||||
'sub' => 'string',
|
||||
'sub-with-dot' => 'stringvalue',
|
||||
],
|
||||
];
|
||||
$this->assertEquals($expected, $subject->_call('removeDots', $given));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function initializeActionWorks()
|
||||
{
|
||||
$packageManagerProphecy = $this->prophesize(PackageManager::class);
|
||||
GeneralUtility::setSingletonInstance(PackageManager::class, $packageManagerProphecy->reveal());
|
||||
|
||||
$subject = $this->getAccessibleMock(AddressController::class, null, [], '', false);
|
||||
$subject->_set('extensionConfiguration', $this->getMockedSettings());
|
||||
$subject->initializeAction();
|
||||
|
||||
$expected = new QueryGenerator();
|
||||
|
||||
$this->assertEquals($expected, $subject->_get('queryGenerator'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function injectAddressRepositoryWorks()
|
||||
{
|
||||
$mockedRepository = $this->getAccessibleMock(AddressRepository::class, null, [], '', false);
|
||||
|
||||
$subject = $this->getAccessibleMock(AddressController::class, null, [], '', false);
|
||||
$subject->injectAddressRepository($mockedRepository);
|
||||
|
||||
$this->assertEquals($mockedRepository, $subject->_get('addressRepository'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function pidListIsReturned()
|
||||
{
|
||||
$mockedQueryGenerator = $this->getAccessibleMock(QueryGenerator::class, ['getTreeList'], [], '', false);
|
||||
$mockedQueryGenerator->expects($this->any())->method('getTreeList')
|
||||
->withConsecutive([123, 3], [456, 3])
|
||||
->willReturnOnConsecutiveCalls('7,8,9', '');
|
||||
|
||||
$subject = $this->getAccessibleMock(AddressController::class, null, [], '', false);
|
||||
$subject->_set('queryGenerator', $mockedQueryGenerator);
|
||||
$subject->_set('settings', [
|
||||
'pages' => '123,456',
|
||||
'recursive' => 3,
|
||||
]);
|
||||
|
||||
$this->assertEquals(['123', '456', '7', '8', '9'], $subject->_call('getPidList'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function settingsAreProperlyInjected()
|
||||
{
|
||||
$this->markTestSkipped('Skipped until fixed');
|
||||
$mockedConfigurationManager = $this->getAccessibleMock(ConfigurationManager::class, ['getConfiguration'], [], '', false);
|
||||
$mockedConfigurationManager->expects($this->any())->method('getConfiguration')
|
||||
->withConsecutive([ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT], [ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS])
|
||||
->willReturnOnConsecutiveCalls(
|
||||
[
|
||||
'plugin.' => [
|
||||
'tx_ttaddress.' => [
|
||||
'settings' => [
|
||||
'orderByAllowed' => 'sorting',
|
||||
'overrideFlexformSettingsIfEmpty' => 'key4,key5,key6',
|
||||
'key2' => 'abc',
|
||||
'key4' => 'fo',
|
||||
'key5' => '',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'key1' => 'value1',
|
||||
'orderByAllowed' => 'custom',
|
||||
'key2' => '',
|
||||
'key3' => '',
|
||||
'key4' => '',
|
||||
'key5' => '',
|
||||
]
|
||||
);
|
||||
|
||||
$subject = $this->getAccessibleMock(AddressController::class, null, [], '', false);
|
||||
$expectedSettings = [
|
||||
'key1' => 'value1',
|
||||
'orderByAllowed' => 'sorting',
|
||||
'key2' => '',
|
||||
'key3' => '',
|
||||
'key4' => 'fo',
|
||||
'key5' => '',
|
||||
];
|
||||
$subject->injectConfigurationManager($mockedConfigurationManager);
|
||||
$this->assertEquals($expectedSettings, $subject->_get('settings'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function demandIsCreated()
|
||||
{
|
||||
$demand = new Demand();
|
||||
|
||||
$subject = $this->getAccessibleMock(AddressController::class, ['getPidList'], [], '', false);
|
||||
$subject->expects($this->any())->method('getPidList')->willReturn(['123', '456']);
|
||||
$subject->_set('settings', [
|
||||
'pages' => '123,456',
|
||||
'singleRecords' => '7,4',
|
||||
'recursive' => 3,
|
||||
'groups' => '4,5,6',
|
||||
'groupsCombination' => 1,
|
||||
]);
|
||||
|
||||
$expected = new Demand();
|
||||
$expected->setPages(['123', '456']);
|
||||
$expected->setSingleRecords('7,4');
|
||||
$expected->setCategoryCombination('or');
|
||||
$expected->setCategories('4,5,6');
|
||||
|
||||
$this->assertEquals($expected, $subject->_call('createDemandFromSettings'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function showActionFillsView()
|
||||
{
|
||||
$address = new Address();
|
||||
$address->setLastName('Doe');
|
||||
$assigned = [
|
||||
'address' => $address,
|
||||
'contentObjectData' => [],
|
||||
];
|
||||
$mockedView = $this->getAccessibleMock(TemplateView::class, ['assignMultiple'], [], '', false);
|
||||
$mockedView->expects($this->once())->method('assignMultiple')->with($assigned);
|
||||
$mockContentObject = $this->createMock(ContentObjectRenderer::class);
|
||||
$mockConfigurationManager = $this->createMock(ConfigurationManager::class);
|
||||
$mockConfigurationManager->method('getContentObject')
|
||||
->willReturn($mockContentObject);
|
||||
|
||||
$subject = $this->getAccessibleMock(AddressController::class, ['redirectToUri', 'htmlResponse'], [], '', false);
|
||||
$subject->_set('view', $mockedView);
|
||||
$subject->_set('configurationManager', $mockConfigurationManager);
|
||||
$subject->expects($this->once())->method('htmlResponse');
|
||||
|
||||
$subject->showAction($address);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function listActionFillsViewForSingleRecords()
|
||||
{
|
||||
$settings = [
|
||||
'singlePid' => 0,
|
||||
'singleRecords' => 1,
|
||||
];
|
||||
$demand = new Demand();
|
||||
$demand->setSingleRecords('134');
|
||||
|
||||
$mockedRepository = $this->getAccessibleMock(AddressRepository::class, ['getAddressesByCustomSorting'], [], '', false);
|
||||
$mockedRepository->expects($this->once())->method('getAddressesByCustomSorting')->willReturn(['dummy return single']);
|
||||
|
||||
$assignments = [
|
||||
'demand' => $demand,
|
||||
'addresses' => ['dummy return single'],
|
||||
'contentObjectData' => []
|
||||
];
|
||||
|
||||
$mockedView = $this->getAccessibleMock(TemplateView::class, ['assignMultiple', 'assign'], [], '', false);
|
||||
$mockedView->expects($this->once())->method('assignMultiple')->with($assignments);
|
||||
$mockConfigurationManager = $this->createMock(ConfigurationManager::class);
|
||||
$mockContentObject = $this->createMock(ContentObjectRenderer::class);
|
||||
$mockConfigurationManager->method('getContentObject')
|
||||
->willReturn($mockContentObject);
|
||||
$mockedRequest = $this->getAccessibleMock(Request::class, ['hasArgument', 'getArgument'], [], '', false);
|
||||
|
||||
$subject = $this->getAccessibleMock(AddressController::class, ['createDemandFromSettings', 'htmlResponse'], [], '', false);
|
||||
$subject->expects($this->once())->method('createDemandFromSettings')->willReturn($demand);
|
||||
$subject->expects($this->once())->method('htmlResponse');
|
||||
$subject->_set('settings', $settings);
|
||||
$subject->_set('view', $mockedView);
|
||||
$subject->_set('request', $mockedRequest);
|
||||
$subject->_set('addressRepository', $mockedRepository);
|
||||
$subject->_set('extensionConfiguration', $this->getMockedSettings());
|
||||
$subject->_set('configurationManager', $mockConfigurationManager);
|
||||
|
||||
$subject->listAction();
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function listActionFillsViewForDemand()
|
||||
{
|
||||
$settings = [
|
||||
'singleRecords' => 1,
|
||||
];
|
||||
$demand = new Demand();
|
||||
$demand->setPages(['12']);
|
||||
|
||||
$mockedRepository = $this->getAccessibleMock(AddressRepository::class, ['findByDemand'], [], '', false);
|
||||
$mockedRepository->expects($this->once())->method('findByDemand')->willReturn(['dummy return']);
|
||||
$mockContentObject = $this->createMock(ContentObjectRenderer::class);
|
||||
$mockConfigurationManager = $this->createMock(ConfigurationManager::class);
|
||||
$mockConfigurationManager->method('getContentObject')
|
||||
->willReturn($mockContentObject);
|
||||
$assignments = [
|
||||
'demand' => $demand,
|
||||
'addresses' => ['dummy return'],
|
||||
'contentObjectData' => [],
|
||||
];
|
||||
|
||||
$mockedRequest = $this->getAccessibleMock(Request::class, ['hasArgument', 'getArgument'], [], '', false);
|
||||
|
||||
$mockedView = $this->getAccessibleMock(TemplateView::class, ['assignMultiple', 'assign'], [], '', false);
|
||||
$mockedView->expects($this->once())->method('assignMultiple')->with($assignments);
|
||||
|
||||
$subject = $this->getAccessibleMock(AddressController::class, ['createDemandFromSettings', 'htmlResponse'], [], '', false);
|
||||
$subject->expects($this->once())->method('createDemandFromSettings')->willReturn($demand);
|
||||
$subject->expects($this->any())->method('htmlResponse');
|
||||
$subject->_set('settings', $settings);
|
||||
$subject->_set('view', $mockedView);
|
||||
$subject->_set('request', $mockedRequest);
|
||||
$subject->_set('addressRepository', $mockedRepository);
|
||||
$subject->_set('extensionConfiguration', $this->getMockedSettings());
|
||||
$subject->_set('configurationManager', $mockConfigurationManager);
|
||||
|
||||
$subject->listAction();
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function overrideDemandMethodIsCalledIfEnabled()
|
||||
{
|
||||
$mockedRequest = $this->getAccessibleMock(Request::class, ['hasArgument', 'getArgument'], [], '', false);
|
||||
$mockedRepository = $this->getAccessibleMock(AddressRepository::class, ['getAddressesByCustomSorting', 'findByDemand'], [], '', false);
|
||||
$mockedRepository->expects($this->any())->method('findByDemand')->willReturn([]);
|
||||
$mockedView = $this->getAccessibleMock(TemplateView::class, ['assignMultiple', 'assign'], [], '', false);
|
||||
$mockedView->expects($this->once())->method('assignMultiple');
|
||||
$mockContentObject = $this->createMock(ContentObjectRenderer::class);
|
||||
$mockConfigurationManager = $this->createMock(ConfigurationManager::class);
|
||||
$mockConfigurationManager->method('getContentObject')
|
||||
->willReturn($mockContentObject);
|
||||
|
||||
$subject = $this->getAccessibleMock(AddressController::class, ['overrideDemand', 'createDemandFromSettings', 'htmlResponse'], [], '', false);
|
||||
$subject->_set('extensionConfiguration', $this->getMockedSettings());
|
||||
$subject->_set('configurationManager', $mockConfigurationManager);
|
||||
$subject->expects($this->any())->method('overrideDemand');
|
||||
$subject->expects($this->any())->method('htmlResponse');
|
||||
|
||||
$demand = new Demand();
|
||||
$subject->expects($this->any())->method('createDemandFromSettings')->willReturn($demand);
|
||||
|
||||
$settings = [
|
||||
'allowOverride' => true,
|
||||
];
|
||||
$subject->_set('settings', $settings);
|
||||
$subject->_set('addressRepository', $mockedRepository);
|
||||
$subject->_set('view', $mockedView);
|
||||
$subject->_set('request', $mockedRequest);
|
||||
|
||||
$subject->listAction(['not', 'empty']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider overrideDemandWorksDataProvider
|
||||
*/
|
||||
public function overrideDemandWorks(Demand $demandIn, Demand $demandOut, array $override)
|
||||
{
|
||||
$subject = $this->getAccessibleMock(AddressController::class, null, [], '', false);
|
||||
|
||||
$this->assertEquals($demandOut, $subject->_call('overrideDemand', $demandIn, $override));
|
||||
}
|
||||
|
||||
public function overrideDemandWorksDataProvider(): array
|
||||
{
|
||||
$data = [];
|
||||
|
||||
// simple override + skipped field including different case
|
||||
$demand1In = new Demand();
|
||||
$demand1In->setCategories('12,34');
|
||||
$demand1In->setSortBy('uid');
|
||||
$demand1Out = clone $demand1In;
|
||||
$demand1Out->setCategories('56');
|
||||
$demand1Out->setSortBy('title');
|
||||
$data['skipSimple'] = [$demand1In, $demand1Out, ['categories' => '56', 'sortby' => 'title']];
|
||||
|
||||
// not existing field
|
||||
$demand2In = new Demand();
|
||||
$demand2In->setCategories('7');
|
||||
$demand2Out = clone $demand2In;
|
||||
$data['ignoreNotExisting'] = [$demand2In, $demand2Out, ['categoriesX' => '56', 'ysortby' => 'title']];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function getMockedSettings()
|
||||
{
|
||||
$mockedSettings = $this->getAccessibleMock(Settings::class, ['getSettings'], [], '', false);
|
||||
$mockedSettings->expects($this->any())->method('getSettings')->willReturn([]);
|
||||
|
||||
return $mockedSettings;
|
||||
}
|
||||
}
|
||||
540
typo3conf/ext/tt_address/Tests/Unit/Domain/Model/AddressTest.php
Normal file
540
typo3conf/ext/tt_address/Tests/Unit/Domain/Model/AddressTest.php
Normal file
@@ -0,0 +1,540 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FriendsOfTypo3\TtAddress\Tests\Unit\Domain\Model;
|
||||
|
||||
/**
|
||||
* This file is part of the "tt_address" Extension for TYPO3 CMS.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use FriendsOfTYPO3\TtAddress\Domain\Model\Address;
|
||||
use TYPO3\CMS\Extbase\Domain\Model\Category;
|
||||
use TYPO3\CMS\Extbase\Domain\Model\FileReference;
|
||||
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
|
||||
use TYPO3\TestingFramework\Core\BaseTestCase;
|
||||
|
||||
class AddressTest extends BaseTestCase
|
||||
{
|
||||
/** @var Address */
|
||||
protected $subject;
|
||||
|
||||
public function setup(): void
|
||||
{
|
||||
$this->subject = new Address();
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function genderCanBeSet()
|
||||
{
|
||||
$value = 'm';
|
||||
$this->subject->setGender($value);
|
||||
$this->assertEquals($value, $this->subject->getGender());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function nameCanBeSet()
|
||||
{
|
||||
$value = 'Max Mustermann';
|
||||
$this->subject->setName($value);
|
||||
$this->assertEquals($value, $this->subject->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function firstNameCanBeSet()
|
||||
{
|
||||
$value = 'Max';
|
||||
$this->subject->setFirstName($value);
|
||||
$this->assertEquals($value, $this->subject->getFirstName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function middleNameCanBeSet()
|
||||
{
|
||||
$value = 'J.';
|
||||
$this->subject->setMiddleName($value);
|
||||
$this->assertEquals($value, $this->subject->getMiddleName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function lastNameCanBeSet()
|
||||
{
|
||||
$value = 'Mustermann';
|
||||
$this->subject->setLastName($value);
|
||||
$this->assertEquals($value, $this->subject->getLastName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function birthdayCanBeSet()
|
||||
{
|
||||
$value = new \DateTime();
|
||||
$this->subject->setBirthday($value);
|
||||
$this->assertEquals($value, $this->subject->getBirthday());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function titleCanBeSet()
|
||||
{
|
||||
$value = 'dr.';
|
||||
$this->subject->setTitle($value);
|
||||
$this->assertEquals($value, $this->subject->getTitle());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function addressCanBeSet()
|
||||
{
|
||||
$value = 'Dummystreet 134';
|
||||
$this->subject->setAddress($value);
|
||||
$this->assertEquals($value, $this->subject->getAddress());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function latitudeCanBeSet()
|
||||
{
|
||||
$value = 123.121221;
|
||||
$this->subject->setLatitude($value);
|
||||
$this->assertEquals($value, $this->subject->getLatitude());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function longitudeCanBeSet()
|
||||
{
|
||||
$value = 10.1291;
|
||||
$this->subject->setLongitude($value);
|
||||
$this->assertEquals($value, $this->subject->getLongitude());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function buildingCanBeSet()
|
||||
{
|
||||
$value = 'building 1';
|
||||
$this->subject->setBuilding($value);
|
||||
$this->assertEquals($value, $this->subject->getBuilding());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function roomCanBeSet()
|
||||
{
|
||||
$value = 'room 1';
|
||||
$this->subject->setRoom($value);
|
||||
$this->assertEquals($value, $this->subject->getRoom());
|
||||
}
|
||||
|
||||
public function telephoneFormatDataProvider()
|
||||
{
|
||||
return [
|
||||
'phone number' => ['0122333', '0122333'],
|
||||
'phone number with spaces' => [' 0 122 333 ', '0122333'],
|
||||
'phone number with dashes' => ['0122-333-4444', '01223334444'],
|
||||
'phone number with slash' => ['0122/333', '0122333'],
|
||||
'phone number with invalid chars' => ['!0"1§2$2%/&3/3(3)', '0122333'],
|
||||
'phone number with allowed special chars' => ['#06*', '#06*'],
|
||||
'phone number with brackets in front' => ['(0)22333', '022333'],
|
||||
'phone number with brackets in middle' => ['+49(0)22333', '+4922333'],
|
||||
'phone number with number in brackets' => ['+49 (122) 333', '+49122333'],
|
||||
'phone number with letters' => ['tel: +49 122 333', '+49122333'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function phoneCanBeSet()
|
||||
{
|
||||
$value = '+43129';
|
||||
$this->subject->setPhone($value);
|
||||
$this->assertEquals($value, $this->subject->getPhone());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider telephoneFormatDataProvider
|
||||
*/
|
||||
public function phoneWithCleanedChars($number, $expectedNumber)
|
||||
{
|
||||
$this->subject->setPhone($number);
|
||||
|
||||
self::assertSame(
|
||||
$expectedNumber,
|
||||
$this->subject->getCleanedPhone()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function faxCanBeSet()
|
||||
{
|
||||
$value = '+431294';
|
||||
$this->subject->setFax($value);
|
||||
$this->assertEquals($value, $this->subject->getFax());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider telephoneFormatDataProvider
|
||||
*/
|
||||
public function faxWithCleanedChars($number, $expectedNumber)
|
||||
{
|
||||
$this->subject->setFax($number);
|
||||
|
||||
self::assertSame(
|
||||
$expectedNumber,
|
||||
$this->subject->getCleanedFax()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function mobileCanBeSet()
|
||||
{
|
||||
$value = '+431294111';
|
||||
$this->subject->setMobile($value);
|
||||
$this->assertEquals($value, $this->subject->getMobile());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider telephoneFormatDataProvider
|
||||
*/
|
||||
public function mobileWithCleanedChars($number, $expectedNumber)
|
||||
{
|
||||
$this->subject->setMobile($number);
|
||||
|
||||
self::assertSame(
|
||||
$expectedNumber,
|
||||
$this->subject->getCleanedMobile()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function wwwCanBeSet()
|
||||
{
|
||||
$value = 'www.typo3.org';
|
||||
$this->subject->setWww($value);
|
||||
$this->assertEquals($value, $this->subject->getWww());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider simplifiedWwwIsReturnedDataProvider
|
||||
*/
|
||||
public function simplifiedWwwIsReturned(string $given, string $expected)
|
||||
{
|
||||
$this->subject->setWww($given);
|
||||
$this->assertEquals($expected, $this->subject->getWwwSimplified());
|
||||
}
|
||||
|
||||
public function simplifiedWwwIsReturnedDataProvider()
|
||||
{
|
||||
return [
|
||||
'empty' => ['', ''],
|
||||
'emptyAfterTrim' => [' ', ''],
|
||||
'simpleLink' => ['www.typo3.org', 'www.typo3.org'],
|
||||
'linkWithAdditionalAttributes' => ['https://typo3.com _blank', 'https://typo3.com'],
|
||||
'linkWithAdditionalAttributes2' => ['https://typo3.com _blank TYPO3', 'https://typo3.com'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function slugCanBeSet()
|
||||
{
|
||||
$value = '/testaddress/';
|
||||
$this->subject->setSlug($value);
|
||||
$this->assertEquals($value, $this->subject->getSlug());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function skypeCanBeSet()
|
||||
{
|
||||
$value = 'fo.com';
|
||||
$this->subject->setSkype($value);
|
||||
$this->assertEquals($value, $this->subject->getSkype());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function twitterCanBeSet()
|
||||
{
|
||||
$value = '@georg_ringer';
|
||||
$this->subject->setTwitter($value);
|
||||
$this->assertEquals($value, $this->subject->getTwitter());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function wrongTwitterHandleThrowsErrorCanBeSet()
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionCode(1357530444);
|
||||
$value = 'georg_ringer';
|
||||
$this->subject->setTwitter($value);
|
||||
$this->assertEquals($value, $this->subject->getTwitter());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function facebookCanBeSet()
|
||||
{
|
||||
$value = '/fo';
|
||||
$this->subject->setFacebook($value);
|
||||
$this->assertEquals($value, $this->subject->getFacebook());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function wrongFacebookHandleThrowsErrorCanBeSet()
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionCode(1357530471);
|
||||
$value = 'some string';
|
||||
$this->subject->setFacebook($value);
|
||||
$this->assertEquals($value, $this->subject->getFacebook());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function linkedinCanBeSet()
|
||||
{
|
||||
$value = 'www.linkedin.com/bar';
|
||||
$this->subject->setLinkedin($value);
|
||||
$this->assertEquals($value, $this->subject->getLinkedin());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function emailCanBeSet()
|
||||
{
|
||||
$value = 'some@example.org';
|
||||
$this->subject->setEmail($value);
|
||||
$this->assertEquals($value, $this->subject->getEmail());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function companyCanBeSet()
|
||||
{
|
||||
$value = 'ACME';
|
||||
$this->subject->setCompany($value);
|
||||
$this->assertEquals($value, $this->subject->getCompany());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function positionCanBeSet()
|
||||
{
|
||||
$value = 'Boss';
|
||||
$this->subject->setPosition($value);
|
||||
$this->assertEquals($value, $this->subject->getPosition());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function cityCanBeSet()
|
||||
{
|
||||
$value = 'Linz';
|
||||
$this->subject->setCity($value);
|
||||
$this->assertEquals($value, $this->subject->getCity());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function zipCanBeSet()
|
||||
{
|
||||
$value = '30210';
|
||||
$this->subject->setZip($value);
|
||||
$this->assertEquals($value, $this->subject->getZip());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function regionCanBeSet()
|
||||
{
|
||||
$value = 'OOE';
|
||||
$this->subject->setRegion($value);
|
||||
$this->assertEquals($value, $this->subject->getRegion());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function countryCanBeSet()
|
||||
{
|
||||
$value = 'AT';
|
||||
$this->subject->setCountry($value);
|
||||
$this->assertEquals($value, $this->subject->getCountry());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function descriptionCanBeSet()
|
||||
{
|
||||
$value = 'lorem ipsum';
|
||||
$this->subject->setDescription($value);
|
||||
$this->assertEquals($value, $this->subject->getDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function imagesCanBeSet()
|
||||
{
|
||||
$value = new ObjectStorage();
|
||||
|
||||
$item = new FileReference();
|
||||
$item->setPid(123);
|
||||
$value->attach($item);
|
||||
$this->subject->setImage($value);
|
||||
$this->assertEquals($value, $this->subject->getImage());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function imagesCanBeAttached()
|
||||
{
|
||||
$value = new ObjectStorage();
|
||||
|
||||
$item = new FileReference();
|
||||
$item->setPid(123);
|
||||
$value->attach($item);
|
||||
|
||||
$item2 = new FileReference();
|
||||
$item2->setPid(345);
|
||||
|
||||
$this->subject->setImage($value);
|
||||
$this->subject->addImage($item2);
|
||||
$this->assertEquals(2, $this->subject->getImage()->count());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function firstImageCanBeRetrieved()
|
||||
{
|
||||
$value = new ObjectStorage();
|
||||
|
||||
$item = new FileReference();
|
||||
$item->setPid(123);
|
||||
$value->attach($item);
|
||||
|
||||
$item2 = new FileReference();
|
||||
$item2->setPid(345);
|
||||
|
||||
$this->subject->setImage($value);
|
||||
$this->assertEquals($item, $this->subject->getFirstImage());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function firstImageIsNullIfNoImages()
|
||||
{
|
||||
$value = new ObjectStorage();
|
||||
|
||||
$this->subject->setImage($value);
|
||||
$this->assertNull($this->subject->getFirstImage());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function imagesCanBeRemoved()
|
||||
{
|
||||
$value = new ObjectStorage();
|
||||
|
||||
$item = new FileReference();
|
||||
$item->setPid(123);
|
||||
$value->attach($item);
|
||||
|
||||
$item2 = new FileReference();
|
||||
$item2->setPid(345);
|
||||
$value->attach($item2);
|
||||
|
||||
$this->subject->setImage($value);
|
||||
$this->subject->removeImage($item2);
|
||||
$this->assertEquals(1, $this->subject->getImage()->count());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function categoriesCanBeSet()
|
||||
{
|
||||
$value = new ObjectStorage();
|
||||
|
||||
$item = new Category();
|
||||
$item->setPid(456);
|
||||
$value->attach($item);
|
||||
$this->subject->setCategories($value);
|
||||
$this->assertEquals($value, $this->subject->getCategories());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider fullNameDataProvider
|
||||
*/
|
||||
public function fullNameIsReturned(string $expected, array $nameParts): void
|
||||
{
|
||||
$this->subject->setTitle($nameParts[0]);
|
||||
$this->subject->setFirstName($nameParts[1]);
|
||||
$this->subject->setLastName($nameParts[2]);
|
||||
$this->subject->setTitleSuffix($nameParts[3]);
|
||||
|
||||
$this->assertEquals($expected, $this->subject->getFullName());
|
||||
}
|
||||
|
||||
public function fullNameDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'simple name' => ['John Doe', ['', 'John', 'Doe', '']],
|
||||
'name with title' => ['Dr. Jane Doe', ['Dr.', 'Jane', 'Doe', '']],
|
||||
'name with title and 2nd title' => ['Dr. Max Mustermann, Junior', ['Dr.', 'Max', 'Mustermann', 'Junior']],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FriendsOfTypo3\TtAddress\Tests\Unit\Domain\Model\Dto;
|
||||
|
||||
/**
|
||||
* This file is part of the "tt_address" Extension for TYPO3 CMS.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*/
|
||||
use FriendsOfTYPO3\TtAddress\Domain\Model\Dto\Demand;
|
||||
use TYPO3\TestingFramework\Core\BaseTestCase;
|
||||
|
||||
class DemandTest extends BaseTestCase
|
||||
{
|
||||
/** @var Demand */
|
||||
protected $subject;
|
||||
|
||||
public function setup():void
|
||||
{
|
||||
$this->subject = new Demand();
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function pagesCanBeSet()
|
||||
{
|
||||
$value = ['123', '456'];
|
||||
$this->subject->setPages($value);
|
||||
$this->assertEquals($value, $this->subject->getPages());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function sortByCanBeSet()
|
||||
{
|
||||
$value = 'title';
|
||||
$this->subject->setSortBy($value);
|
||||
$this->assertEquals($value, $this->subject->getSortBy());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function sortOrderCanBeSet()
|
||||
{
|
||||
$value = 'desc';
|
||||
$this->subject->setSortOrder($value);
|
||||
$this->assertEquals($value, $this->subject->getSortOrder());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function categoriesCanBeSet()
|
||||
{
|
||||
$value = '12,34,5';
|
||||
$this->subject->setCategories($value);
|
||||
$this->assertEquals($value, $this->subject->getCategories());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function categoryCombinationCanBeSet()
|
||||
{
|
||||
$value = 'AND';
|
||||
$this->subject->setCategoryCombination($value);
|
||||
$this->assertEquals($value, $this->subject->getCategoryCombination());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function singleRecordsCanBeSet()
|
||||
{
|
||||
$value = '7,6,1';
|
||||
$this->subject->setSingleRecords($value);
|
||||
$this->assertEquals($value, $this->subject->getSingleRecords());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function includeSubCategoriesCanBeSet()
|
||||
{
|
||||
$value = true;
|
||||
$this->subject->setIncludeSubCategories($value);
|
||||
$this->assertEquals($value, $this->subject->getIncludeSubCategories());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function ignoreWithoutCoordinatesCanBeSet()
|
||||
{
|
||||
$value = true;
|
||||
$this->subject->setIgnoreWithoutCoordinates($value);
|
||||
$this->assertEquals($value, $this->subject->getIgnoreWithoutCoordinates());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FriendsOfTypo3\TtAddress\Tests\Unit\Domain\Model\Dto;
|
||||
|
||||
/**
|
||||
* This file is part of the "tt_address" Extension for TYPO3 CMS.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*/
|
||||
use FriendsOfTYPO3\TtAddress\Domain\Model\Dto\Settings;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use TYPO3\CMS\Core\Package\PackageManager;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\TestingFramework\Core\BaseTestCase;
|
||||
|
||||
class SettingsTest extends BaseTestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$packageManagerProphecy = $this->prophesize(PackageManager::class);
|
||||
GeneralUtility::setSingletonInstance(PackageManager::class, $packageManagerProphecy->reveal());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function defaultSettingsAreAvailable()
|
||||
{
|
||||
$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['tt_address'] = [];
|
||||
$subject = new Settings();
|
||||
|
||||
$this->assertEquals('/[^\d\+\s\-]/', $subject->getTelephoneValidationPatternForPhp());
|
||||
$this->assertEquals('/[^\d\+\s\-]/g', $subject->getTelephoneValidationPatternForJs());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function settingsAreSet()
|
||||
{
|
||||
$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['tt_address'] = [
|
||||
'storeBackwardsCompatName' => false,
|
||||
'readOnlyNameField' => false,
|
||||
'telephoneValidationPatternForPhp' => 'regex1',
|
||||
'telephoneValidationPatternForJs' => 'regex2',
|
||||
];
|
||||
$subject = new Settings();
|
||||
|
||||
$this->assertEquals('regex1', $subject->getTelephoneValidationPatternForPhp());
|
||||
$this->assertEquals('regex2', $subject->getTelephoneValidationPatternForJs());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FriendsOfTypo3\TtAddress\Tests\Unit\Utility;
|
||||
|
||||
/**
|
||||
* This file is part of the "tt_address" Extension for TYPO3 CMS.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*/
|
||||
use FriendsOfTYPO3\TtAddress\Evaluation\LatitudeEvaluation;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use TYPO3\CMS\Core\Package\PackageManager;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\TestingFramework\Core\BaseTestCase;
|
||||
|
||||
class LatitudeEvaluationTest extends BaseTestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
|
||||
/** @var LatitudeEvaluation */
|
||||
protected $subject;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->subject = new LatitudeEvaluation();
|
||||
|
||||
$packageManagerProphecy = $this->prophesize(PackageManager::class);
|
||||
GeneralUtility::setSingletonInstance(PackageManager::class, $packageManagerProphecy->reveal());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function jsEvaluationIsCalled()
|
||||
{
|
||||
$this->markTestSkipped('Skipped as PageRenderer is called which leads into issues');
|
||||
$this->assertNotEmpty($this->subject->returnFieldJS());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $given
|
||||
* @param $expected
|
||||
* @test
|
||||
* @dataProvider latIsProperlyEvaluatedDataProvider
|
||||
*/
|
||||
public function latitudeIsProperlyEvaluated($given, $expected)
|
||||
{
|
||||
$this->assertEquals($expected, $this->subject->evaluateFieldValue($given));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $given
|
||||
* @param $expected
|
||||
* @test
|
||||
* @dataProvider latIsProperlyEvaluatedDataProvider
|
||||
*/
|
||||
public function latIsProperlyDeEvaluated($given, $expected)
|
||||
{
|
||||
$params = ['value' => $given];
|
||||
$this->assertEquals($expected, $this->subject->deevaluateFieldValue($params));
|
||||
}
|
||||
|
||||
public function latIsProperlyEvaluatedDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'empty string' => ['', ''],
|
||||
'int' => ['12', '12.00000000'],
|
||||
'too large number' => ['95.33', '90.00000000'],
|
||||
'regular float' => ['13.312113', '13.31211300'],
|
||||
'negative regular float' => ['-13.312113', '-13.31211300'],
|
||||
'long float' => ['-11.3121131111111111212121212', '-11.31211311'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FriendsOfTypo3\TtAddress\Tests\Unit\Utility;
|
||||
|
||||
/**
|
||||
* This file is part of the "tt_address" Extension for TYPO3 CMS.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*/
|
||||
use FriendsOfTYPO3\TtAddress\Evaluation\LongitudeEvaluation;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use TYPO3\CMS\Core\Package\PackageManager;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\TestingFramework\Core\BaseTestCase;
|
||||
|
||||
class LongitudeEvaluationTest extends BaseTestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
|
||||
/** @var LongitudeEvaluation */
|
||||
protected $subject;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->subject = new LongitudeEvaluation();
|
||||
|
||||
$packageManagerProphecy = $this->prophesize(PackageManager::class);
|
||||
GeneralUtility::setSingletonInstance(PackageManager::class, $packageManagerProphecy->reveal());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function jsEvaluationIsCalled()
|
||||
{
|
||||
$this->markTestSkipped('Skipped as PageRenderer is called which leads into issues');
|
||||
$this->assertNotEmpty($this->subject->returnFieldJS());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $given
|
||||
* @param $expected
|
||||
* @test
|
||||
* @dataProvider lngIsProperlyEvaluatedDataProvider
|
||||
*/
|
||||
public function longIsProperlyEvaluated($given, $expected)
|
||||
{
|
||||
$this->assertEquals($expected, $this->subject->evaluateFieldValue($given));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $given
|
||||
* @param $expected
|
||||
* @test
|
||||
* @dataProvider lngIsProperlyEvaluatedDataProvider
|
||||
*/
|
||||
public function lngIsProperlyDeEvaluated($given, $expected)
|
||||
{
|
||||
$params = ['value' => $given];
|
||||
$this->assertEquals($expected, $this->subject->deevaluateFieldValue($params));
|
||||
}
|
||||
|
||||
public function lngIsProperlyEvaluatedDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'empty string' => ['', ''],
|
||||
'int' => ['12', '12.00000000'],
|
||||
'too large number' => ['193.33', '180.00000000'],
|
||||
'regular float' => ['13.312113', '13.31211300'],
|
||||
'negative regular float' => ['-13.312113', '-13.31211300'],
|
||||
'long float' => ['-11.3121131111111111212121212', '-11.31211311'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FriendsOfTypo3\TtAddress\Tests\Unit\Utility;
|
||||
|
||||
/**
|
||||
* This file is part of the "tt_address" Extension for TYPO3 CMS.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*/
|
||||
use FriendsOfTYPO3\TtAddress\Domain\Model\Dto\Settings;
|
||||
use FriendsOfTYPO3\TtAddress\Evaluation\TelephoneEvaluation;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use TYPO3\CMS\Core\Package\PackageManager;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\TestingFramework\Core\BaseTestCase;
|
||||
|
||||
class TelephoneEvaluationTest extends BaseTestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
|
||||
/** @var TelephoneEvaluation */
|
||||
protected $subject;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->subject = new TelephoneEvaluation();
|
||||
|
||||
$packageManagerProphecy = $this->prophesize(PackageManager::class);
|
||||
GeneralUtility::setSingletonInstance(PackageManager::class, $packageManagerProphecy->reveal());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function constructorIsCalled()
|
||||
{
|
||||
$subject = $this->getAccessibleMock(TelephoneEvaluation::class, null, [], '', true);
|
||||
|
||||
$settings = new Settings();
|
||||
$this->assertEquals($settings, $subject->_get('extensionSettings'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function jsEvaluationIsCalled()
|
||||
{
|
||||
$this->markTestSkipped('Skipped as PageRenderer is called which leads into issues');
|
||||
$this->assertNotEmpty($this->subject->returnFieldJS());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $given
|
||||
* @param $expected
|
||||
* @test
|
||||
* @dataProvider telephoneIsProperlyEvaluatedDataProvider
|
||||
*/
|
||||
public function telephoneIsProperlyEvaluated($given, $expected)
|
||||
{
|
||||
$this->assertEquals($expected, $this->subject->evaluateFieldValue($given));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $given
|
||||
* @param $expected
|
||||
* @test
|
||||
* @dataProvider telephoneIsProperlyEvaluatedDataProvider
|
||||
*/
|
||||
public function telephoneIsProperlyDeEvaluated($given, $expected)
|
||||
{
|
||||
$params = ['value' => $given];
|
||||
$this->assertEquals($expected, $this->subject->deevaluateFieldValue($params));
|
||||
}
|
||||
|
||||
public function telephoneIsProperlyEvaluatedDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'empty string' => ['', ''],
|
||||
'example 1' => ['+43 699 12 54 12 1', '+43 699 12 54 12 1'],
|
||||
'example 2' => ['+43 (0)699 12 54 12 1', '+43 0699 12 54 12 1'],
|
||||
'example 3' => [' +43 (0)699 12 54 12 1 DW:4 ', '+43 0699 12 54 12 1 4'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FriendsOfTYPO3\TtAddress\Tests\Unit\Hooks\Tca;
|
||||
|
||||
/**
|
||||
* This file is part of the "tt_address" Extension for TYPO3 CMS.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*/
|
||||
use FriendsOfTYPO3\TtAddress\Hooks\Tca\AddFieldsToSelector;
|
||||
use TYPO3\CMS\Core\Localization\LanguageService;
|
||||
use TYPO3\TestingFramework\Core\BaseTestCase;
|
||||
|
||||
class AddFieldsToSelectorTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function constructorIsCalled()
|
||||
{
|
||||
$languageService = $this->getAccessibleMock(LanguageService::class, null, [], '', false, false);
|
||||
$GLOBALS['LANG'] = $languageService;
|
||||
|
||||
$subject = $this->getAccessibleMock(AddFieldsToSelector::class, null, [], '', true);
|
||||
$this->assertEquals($languageService, $subject->_get('languageService'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function optionsAreFilled()
|
||||
{
|
||||
foreach (AddFieldsToSelector::sortFields as $sortField) {
|
||||
$GLOBALS['TCA']['tt_address']['columns'][$sortField]['label'] = 'label_' . $sortField;
|
||||
}
|
||||
|
||||
$mockedLanguageService = $this->getAccessibleMock(LanguageService::class, ['sL'], [], '', false);
|
||||
$mockedLanguageService->expects($this->any())
|
||||
->method('sL')
|
||||
->will($this->returnCallback(function ($o) {
|
||||
return $o;
|
||||
}));
|
||||
$subject = $this->getAccessibleMock(AddFieldsToSelector::class, null, [], '', false);
|
||||
$subject->_set('languageService', $mockedLanguageService);
|
||||
|
||||
$items = [];
|
||||
$subject->main($items);
|
||||
|
||||
$expected = [
|
||||
'items' => [
|
||||
['label_address', 'address'],
|
||||
['label_birthday', 'birthday'],
|
||||
['label_building', 'building'],
|
||||
['label_city', 'city'],
|
||||
['label_company', 'company'],
|
||||
['label_country', 'country'],
|
||||
['label_email', 'email'],
|
||||
['label_fax', 'fax'],
|
||||
['label_first_name', 'first_name'],
|
||||
['label_gender', 'gender'],
|
||||
['label_last_name', 'last_name'],
|
||||
['label_middle_name', 'middle_name'],
|
||||
['label_mobile', 'mobile'],
|
||||
['label_name', 'name'],
|
||||
['label_phone', 'phone'],
|
||||
['label_region', 'region'],
|
||||
['label_room', 'room'],
|
||||
['label_title', 'title'],
|
||||
['label_www', 'www'],
|
||||
['label_zip', 'zip'],
|
||||
['LLL:EXT:tt_address/Resources/Private/Language/ff/locallang_ff.xlf:pi1_flexform.sortBy.singleSelection', 'singleSelection'],
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $items);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FriendsOfTYPO3\TtAddress\Tests\Unit\Seo;
|
||||
|
||||
/**
|
||||
* This file is part of the "tt_address" Extension for TYPO3 CMS.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*/
|
||||
use FriendsOfTYPO3\TtAddress\Domain\Model\Address;
|
||||
use FriendsOfTYPO3\TtAddress\Seo\AddressTitleProvider;
|
||||
use TYPO3\TestingFramework\Core\BaseTestCase;
|
||||
|
||||
class AddressTitleProviderTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider addressTitleProvider
|
||||
* @param string $expected
|
||||
* @param string[] $addressFields
|
||||
* @param array $configuration
|
||||
*/
|
||||
public function correctTitleIsGenerated(string $expected, array $addressFields, array $configuration): void
|
||||
{
|
||||
$address = new Address();
|
||||
foreach ($addressFields as $fieldName => $value) {
|
||||
$setter = 'set' . ucfirst($fieldName);
|
||||
$address->$setter($value);
|
||||
}
|
||||
|
||||
$mockedProvider = $this->getAccessibleMock(AddressTitleProvider::class, null, [], '', false);
|
||||
$mockedProvider->setTitle($address, $configuration);
|
||||
|
||||
$this->assertEquals($expected, $mockedProvider->getTitle());
|
||||
}
|
||||
|
||||
public function addressTitleProvider(): array
|
||||
{
|
||||
return [
|
||||
'basic example' => [
|
||||
'Max Mustermann',
|
||||
[
|
||||
'firstName' => 'Max',
|
||||
'middleName' => '',
|
||||
'lastName' => 'Mustermann'
|
||||
],
|
||||
[
|
||||
'properties' => 'firstName,middleName,lastName'
|
||||
]
|
||||
],
|
||||
'custom clue' => [
|
||||
'Max - M. - Mustermann',
|
||||
[
|
||||
'firstName' => 'Max',
|
||||
'middleName' => 'M.',
|
||||
'lastName' => 'Mustermann'
|
||||
],
|
||||
[
|
||||
'properties' => 'firstName,middleName,lastName',
|
||||
'glue' => '" - "'
|
||||
]
|
||||
],
|
||||
'empty custom clue' => [
|
||||
'Max M. Mustermann',
|
||||
[
|
||||
'firstName' => 'Max',
|
||||
'middleName' => 'M.',
|
||||
'lastName' => 'Mustermann'
|
||||
],
|
||||
[
|
||||
'properties' => 'firstName,middleName,lastName',
|
||||
'glue' => ''
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FriendsOfTYPO3\TtAddress\Tests\Unit\Service;
|
||||
|
||||
use FriendsOfTYPO3\TtAddress\Service\GeocodeService;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use TYPO3\CMS\Core\Http\RequestFactory;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\TestingFramework\Core\BaseTestCase;
|
||||
|
||||
class GeocodeServiceTest extends BaseTestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function validAPiResultIsReturned()
|
||||
{
|
||||
$content = ['status' => 200, 'CONTENT' => 123];
|
||||
$stream = $this->prophesize(StreamInterface::class);
|
||||
$stream->getContents()->willReturn(json_encode($content));
|
||||
$response = $this->prophesize(ResponseInterface::class);
|
||||
$response->getBody()->willReturn($stream);
|
||||
$requestFactory = $this->prophesize(RequestFactory::class);
|
||||
$requestFactory->request(Argument::cetera())->willReturn($response);
|
||||
|
||||
GeneralUtility::addInstance(RequestFactory::class, $requestFactory->reveal());
|
||||
|
||||
$subject = $this->getAccessibleMock(GeocodeService::class, null, [], '', false);
|
||||
$apiResponse = $subject->_call('getApiCallResult', 'http://dummy.com');
|
||||
$this->assertEquals($content, $apiResponse);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function invalidAPiResultReturnsEmptyArray()
|
||||
{
|
||||
$content = ['status' => 'OVER_QUERY_LIMIT', 'CONTENT' => 123];
|
||||
$stream = $this->prophesize(StreamInterface::class);
|
||||
$stream->getContents()->willReturn(json_encode($content));
|
||||
$response = $this->prophesize(ResponseInterface::class);
|
||||
$response->getBody()->willReturn($stream);
|
||||
$requestFactory = $this->prophesize(RequestFactory::class);
|
||||
$requestFactory->request(Argument::cetera())->willReturn($response);
|
||||
|
||||
GeneralUtility::addInstance(RequestFactory::class, $requestFactory->reveal());
|
||||
|
||||
$subject = $this->getAccessibleMock(GeocodeService::class, null, [], '', false);
|
||||
$apiResponse = $subject->_call('getApiCallResult', 'http://dummy.com');
|
||||
$this->assertEquals([], $apiResponse);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function wrongCacheThrowsException()
|
||||
{
|
||||
$this->expectException(\RuntimeException::class);
|
||||
$this->expectExceptionCode(1548785854);
|
||||
$subject = $this->getAccessibleMock(GeocodeService::class, null, [], '', false);
|
||||
$subject->_call('initializeCache', 'notExisting');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FriendsOfTypo3\TtAddress\Tests\Unit\Utility;
|
||||
|
||||
/**
|
||||
* This file is part of the "tt_address" Extension for TYPO3 CMS.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*/
|
||||
use FriendsOfTYPO3\TtAddress\Domain\Model\Address;
|
||||
use FriendsOfTYPO3\TtAddress\Utility\CacheUtility;
|
||||
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
|
||||
use TYPO3\TestingFramework\Core\BaseTestCase;
|
||||
|
||||
class CacheUtilityTest extends BaseTestCase
|
||||
{
|
||||
protected function setUp():void
|
||||
{
|
||||
$GLOBALS['TSFE'] = $this->getAccessibleMock(
|
||||
TypoScriptFrontendController::class,
|
||||
['addCacheTags'],
|
||||
[],
|
||||
'',
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function nonArrayRecordInstancesAreSkippedForCacheTags()
|
||||
{
|
||||
$addressRecords = ['dummy string'];
|
||||
|
||||
$GLOBALS['TSFE']->expects($this->once())->method('addCacheTags')->with([]);
|
||||
|
||||
CacheUtility::addCacheTagsByAddressRecords($addressRecords);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function addressRecordWithLocalizedIdAddsCacheTags()
|
||||
{
|
||||
$addressRecord = new Address();
|
||||
$addressRecord->_setProperty('uid', 42);
|
||||
$addressRecord->_setProperty('_localizedUid', 43);
|
||||
$addressRecords = [$addressRecord];
|
||||
|
||||
$GLOBALS['TSFE']->expects($this->once())->method('addCacheTags')->with(['tt_address_42', 'tt_address_43']);
|
||||
|
||||
CacheUtility::addCacheTagsByAddressRecords($addressRecords);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FriendsOfTypo3\TtAddress\Tests\Unit\Utility;
|
||||
|
||||
/**
|
||||
* This file is part of the "tt_address" Extension for TYPO3 CMS.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*/
|
||||
use FriendsOfTYPO3\TtAddress\Utility\EvalcoordinatesUtility;
|
||||
use TYPO3\TestingFramework\Core\BaseTestCase;
|
||||
|
||||
class EvalcoordinatesUtilityTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @param $given
|
||||
* @param $expected
|
||||
* @test
|
||||
* @dataProvider longIsProperlyEvaluatedDataProvider
|
||||
*/
|
||||
public function longIsProperlyEvaluated($given, $expected)
|
||||
{
|
||||
$this->assertEquals($expected, EvalcoordinatesUtility::formatLongitude($given));
|
||||
}
|
||||
|
||||
public function longIsProperlyEvaluatedDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'empty string' => ['', '.00000000'],
|
||||
'int' => ['12', '12.00000000'],
|
||||
'too large number' => ['193.33', '180.00000000'],
|
||||
'regular float' => ['13.312113', '13.31211300'],
|
||||
'negative regular float' => ['-13.312113', '-13.31211300'],
|
||||
'long float' => ['-11.3121131111111111212121212', '-11.31211311'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $given
|
||||
* @param $expected
|
||||
* @test
|
||||
* @dataProvider latIsProperlyEvaluatedDataProvider
|
||||
*/
|
||||
public function latIsProperlyEvaluated($given, $expected)
|
||||
{
|
||||
$this->assertEquals($expected, EvalcoordinatesUtility::formatLatitude($given));
|
||||
}
|
||||
|
||||
public function latIsProperlyEvaluatedDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'empty string' => ['', '.00000000'],
|
||||
'int' => ['12', '12.00000000'],
|
||||
'too large number' => ['95.33', '90.00000000'],
|
||||
'regular float' => ['13.312113', '13.31211300'],
|
||||
'negative regular float' => ['-13.312113', '-13.31211300'],
|
||||
'long float' => ['-11.3121131111111111212121212', '-11.31211311'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FriendsOfTypo3\TtAddress\Tests\Unit\Utility;
|
||||
|
||||
/**
|
||||
* This file is part of the "tt_address" Extension for TYPO3 CMS.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*/
|
||||
use FriendsOfTYPO3\TtAddress\Utility\TypoScript;
|
||||
use TYPO3\TestingFramework\Core\BaseTestCase;
|
||||
|
||||
class TypoScriptTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function tsIsOverloadedCorrectly()
|
||||
{
|
||||
$subject = new TypoScript();
|
||||
|
||||
$flexforms = [
|
||||
'default1' => 'value',
|
||||
'default_as_array' => [
|
||||
'sub' => 'value sub',
|
||||
'sub_array' => [
|
||||
'sub_sub' => 'sub_sub_value'
|
||||
]
|
||||
],
|
||||
'override_empty' => '',
|
||||
'override_int' => '0',
|
||||
'override_not_empty' => 'content_already_here',
|
||||
'override_sub' => [
|
||||
'sub_empty' => '',
|
||||
'sub_full' => 'sub_value',
|
||||
'sub_standalone' => 'standalone'
|
||||
],
|
||||
|
||||
];
|
||||
$tsData = [
|
||||
'settings' => [
|
||||
'overrideFlexformSettingsIfEmpty' => 'override_empty,override_not_existing,override_int_empty,override_not_empty,override_sub.sub_empty,override_sub.sub_full,override_sub.sub_notexisting',
|
||||
'override_empty' => 'a_value',
|
||||
'override_not_empty' => 'new_content',
|
||||
'override_int' => 'int fallback',
|
||||
'override_sub' => [
|
||||
'sub_empty' => 'some_value',
|
||||
'sub_full' => 'sub_value_2',
|
||||
'sub_standalone_2' => 'standalone'
|
||||
]
|
||||
]
|
||||
];
|
||||
$expected = [
|
||||
'default1' => 'value',
|
||||
'default_as_array' => [
|
||||
'sub' => 'value sub',
|
||||
'sub_array' => [
|
||||
'sub_sub' => 'sub_sub_value'
|
||||
]
|
||||
],
|
||||
'override_empty' => 'a_value',
|
||||
'override_not_empty' => 'content_already_here',
|
||||
'override_int' => '0',
|
||||
'override_sub' => [
|
||||
'sub_empty' => 'some_value',
|
||||
'sub_full' => 'sub_value',
|
||||
'sub_standalone' => 'standalone'
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $subject->override($flexforms, $tsData));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FriendsOfTypo3\TtAddress\Tests\Unit\ViewHelpers;
|
||||
|
||||
/**
|
||||
* This file is part of the "tt_address" Extension for TYPO3 CMS.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*/
|
||||
use FriendsOfTYPO3\TtAddress\ViewHelpers\RemoveSpacesViewHelper;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use TYPO3\TestingFramework\Core\BaseTestCase;
|
||||
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
|
||||
|
||||
class RemoveSpacesViewHelperTest extends BaseTestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
|
||||
/**
|
||||
* @var RemoveSpacesViewHelper
|
||||
*/
|
||||
protected $viewHelper;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->viewHelper = new RemoveSpacesViewHelper();
|
||||
$this->viewHelper->initializeArguments();
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function spacelessVhIsCalled()
|
||||
{
|
||||
$actualResult = $this->viewHelper->renderStatic(
|
||||
['value' => ' +43 123 56 34 34 '],
|
||||
function () {
|
||||
},
|
||||
$this->prophesize(RenderingContextInterface::class)->reveal()
|
||||
);
|
||||
|
||||
$this->assertEquals('+43123563434', $actualResult);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FriendsOfTypo3\TtAddress\Tests\Unit\ViewHelpers;
|
||||
|
||||
/**
|
||||
* This file is part of the "tt_address" Extension for TYPO3 CMS.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*/
|
||||
use FriendsOfTYPO3\TtAddress\Domain\Model\Address;
|
||||
use FriendsOfTYPO3\TtAddress\ViewHelpers\StaticGoogleMapsViewHelper;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
|
||||
use TYPO3\TestingFramework\Core\BaseTestCase;
|
||||
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
|
||||
|
||||
class StaticGoogleMapsViewHelperTest extends BaseTestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
|
||||
/**
|
||||
* @var StaticGoogleMapsViewHelper
|
||||
*/
|
||||
protected $viewHelper;
|
||||
|
||||
protected function setUp():void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->viewHelper = new StaticGoogleMapsViewHelper();
|
||||
$this->viewHelper->initializeArguments();
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider staticGoogleMapsViewHelpersIsCalledDataProvider
|
||||
*/
|
||||
public function staticGoogleMapsViewHelpersIsCalled(array $parameters, $result)
|
||||
{
|
||||
$actualResult = $this->viewHelper->renderStatic(
|
||||
$parameters,
|
||||
function () {
|
||||
},
|
||||
$this->prophesize(RenderingContextInterface::class)->reveal()
|
||||
);
|
||||
|
||||
$this->assertEquals($result, $actualResult);
|
||||
}
|
||||
|
||||
public function staticGoogleMapsViewHelpersIsCalledDataProvider(): array
|
||||
{
|
||||
$address1 = new Address();
|
||||
$address1->setLatitude(1.1);
|
||||
$address1->setLongitude(1.2);
|
||||
|
||||
$address2 = new Address();
|
||||
$address2->setLatitude(2.1);
|
||||
$address2->setLongitude(2.2);
|
||||
|
||||
$addresses1 = new ObjectStorage();
|
||||
$addresses1->attach($address1);
|
||||
|
||||
$addresses2 = new ObjectStorage();
|
||||
$addresses2->attach($address1);
|
||||
$addresses2->attach($address2);
|
||||
|
||||
return [
|
||||
'1 address' => [
|
||||
[
|
||||
'parameters' => [
|
||||
'key' => 'abcdefgh',
|
||||
'size' => '300x400',
|
||||
],
|
||||
'addresses' => $addresses1
|
||||
],
|
||||
'https://maps.googleapis.com/maps/api/staticmap?&key=abcdefgh&size=300x400&zoom=13&markers=1.1,1.2'
|
||||
],
|
||||
'2 addresses' => [
|
||||
[
|
||||
'parameters' => [
|
||||
'key' => 'abcdefgh',
|
||||
'size' => '300x400',
|
||||
],
|
||||
'addresses' => $addresses2
|
||||
],
|
||||
'https://maps.googleapis.com/maps/api/staticmap?&key=abcdefgh&size=300x400&markers=1.1,1.2&markers=2.1,2.2'
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user