Initial commit - Typo3 11.5.41
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FriendsOfTYPO3\TtAddress\Tests\Functional\Service;
|
||||
|
||||
/**
|
||||
* 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\Service\CategoryService;
|
||||
use TYPO3\CMS\Core\Cache\CacheManager;
|
||||
use TYPO3\CMS\Core\Information\Typo3Version;
|
||||
use TYPO3\CMS\Core\TimeTracker\TimeTracker;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
|
||||
|
||||
class CategoryServiceTest extends FunctionalTestCase
|
||||
{
|
||||
/** @var CategoryService */
|
||||
protected $subject;
|
||||
|
||||
protected array $testExtensionsToLoad = ['typo3conf/ext/tt_address'];
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->subject = GeneralUtility::makeInstance(CategoryService::class);
|
||||
|
||||
$this->importCSVDataSet(__DIR__ . '/../Fixtures/sys_categories.csv');
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function findChildCategories()
|
||||
{
|
||||
$categories = $this->subject->getChildrenCategories('2,4');
|
||||
$this->assertEquals('2,4,20,21,211,212,30,31,32', $categories);
|
||||
|
||||
$categories = $this->subject->getChildrenCategories('4,5,10919,6,7,8');
|
||||
$this->assertEquals('4,5,8', $categories);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function loggerInvokedWithTooManyCategories()
|
||||
{
|
||||
$mockedTimeTracker = $this->getAccessibleMock(TimeTracker::class, ['setTSlogMessage'], [], '', false);
|
||||
$mockedTimeTracker->expects($this->any())->method('setTSlogMessage');
|
||||
|
||||
$subject = $this->getAccessibleMock(CategoryService::class, null, [], '', false);
|
||||
$subject->_set('timeTracker', $mockedTimeTracker);
|
||||
|
||||
$versionInformation = GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion();
|
||||
$cacheIdentifier = $versionInformation >= 11 ? 'ttaddress_category' : 'cache_ttaddress_category';
|
||||
$subject->_set('cache', GeneralUtility::makeInstance(CacheManager::class)->getCache($cacheIdentifier));
|
||||
|
||||
$categories = $subject->getChildrenCategories('2,4', 100000);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FriendsOfTYPO3\TtAddress\Tests\Functional\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\Service\GeocodeService;
|
||||
use TYPO3\CMS\Backend\Utility\BackendUtility;
|
||||
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
|
||||
|
||||
class GeocodeServiceTest extends FunctionalTestCase
|
||||
{
|
||||
protected array $testExtensionsToLoad = ['typo3conf/ext/tt_address'];
|
||||
|
||||
protected array $coreExtensionsToLoad = ['fluid', 'extensionmanager'];
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->importCSVDataSet(__DIR__ . '/../Fixtures/tt_address.csv');
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function properRecordsAreFound()
|
||||
{
|
||||
$subject = $this->getAccessibleMock(GeocodeService::class, ['getCoordinatesForAddress'], ['123']);
|
||||
$subject->expects($this->any())->method('getCoordinatesForAddress')
|
||||
->withConsecutive([], [], [])
|
||||
->willReturnOnConsecutiveCalls(
|
||||
['latitude' => 10.000, 'longitude' => 12.000],
|
||||
['latitude' => 10.000, 'longitude' => 12.000],
|
||||
[],
|
||||
['latitude' => 13.000, 'longitude' => 14.000]
|
||||
);
|
||||
|
||||
$count = $subject->calculateCoordinatesForAllRecordsInTable('pid=100');
|
||||
$this->assertEquals(3, $count);
|
||||
|
||||
$row = BackendUtility::getRecord('tt_address', 21);
|
||||
$this->assertEquals(['latitude' => $row['latitude'], 'longitude' => $row['longitude']], ['latitude' => 10.000000000000, 'longitude' => 12.000000000000]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function urlforAddressesIsBuiltCorrectly()
|
||||
{
|
||||
$result1 = ['results' => [0 => ['geometry' => ['location' => ['lat' => 11, 'lng' => '13']]]]];
|
||||
$resultEmpty = ['results' => []];
|
||||
|
||||
$subject = $this->getAccessibleMock(GeocodeService::class, ['getApiCallResult'], ['123']);
|
||||
$subject->expects($this->any())->method('getApiCallResult')
|
||||
->willReturnOnConsecutiveCalls($result1, $resultEmpty);
|
||||
|
||||
$response = $subject->getCoordinatesForAddress('DummyStr', '1', 'London', 'UK');
|
||||
$this->assertEquals($response, ['latitude' => 11, 'longitude' => '13']);
|
||||
$response2 = $subject->getCoordinatesForAddress('DummyStr', '1', 'London', 'UK');
|
||||
$response3 = $subject->getCoordinatesForAddress('DummyStr', '2', 'Vienna', 'UK');
|
||||
$response4 = $subject->getCoordinatesForAddress();
|
||||
$this->assertEquals([], $response4);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function findRecordsByUid()
|
||||
{
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user