Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to TYPO3 testing framework #115

Merged
merged 5 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 72 additions & 35 deletions Tests/Functional/AbstractElasticsearchTest.php
Original file line number Diff line number Diff line change
@@ -1,41 +1,51 @@
<?php
declare(strict_types = 1);

declare(strict_types=1);

namespace PAGEmachine\Searchable\Tests\Functional;

use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
use Elasticsearch\Client as ElasticsearchClient;
use Nimut\TestingFramework\TestCase\FunctionalTestCase;
use PAGEmachine\Searchable\Connection;
use PAGEmachine\Searchable\Indexer\PagesIndexer;
use PAGEmachine\Searchable\Indexer\TcaIndexer;
use PAGEmachine\Searchable\LinkBuilder\TypoLinkBuilder;
use PAGEmachine\Searchable\Preview\NoPreviewRenderer;
use PAGEmachine\Searchable\Service\IndexingService;
use Pagemachine\SearchableExtbaseL10nTest\Preview\ContentPreviewRenderer;
use TYPO3\CMS\Core\Configuration\SiteConfiguration;
use TYPO3\CMS\Core\Core\Bootstrap;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Crypto\Random;
use TYPO3\CMS\Core\Domain\Repository\PageRepository;
use TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;

abstract class AbstractElasticsearchTest extends FunctionalTestCase
{
use ArraySubsetAsserts;
use WebserverTrait;
use SiteBasedTestTrait;

/**
* @var array
*/
protected $testExtensionsToLoad = [
protected array $testExtensionsToLoad = [
'typo3conf/ext/searchable',
'typo3conf/ext/searchable/Tests/Functional/Fixtures/Extensions/extbase_l10n_test',
'typo3conf/ext/searchable/Tests/Functional/Fixtures/Extensions/unlocalized_table_test',
];

protected $frameworkExtensionsToLoad = [
'Resources/Core/Functional/Extensions/private_container',
];

protected const LANGUAGE_PRESETS = [
'EN' => ['id' => 0, 'title' => 'English', 'locale' => 'en_US.UTF8'],
'DE' => ['id' => 1, 'title' => 'Deutsch', 'locale' => 'de_DE.UTF8'],
];

/**
* @var string[]
*/
Expand Down Expand Up @@ -156,65 +166,78 @@ protected function setUp(): void
]
);

$this->getDatabaseConnection()->insertArray('pages', [
$this->insertArray('pages', [
'uid' => 1,
'doktype' => PageRepository::DOKTYPE_DEFAULT,
'title' => 'Foo Root',
]);
$this->getDatabaseConnection()->insertArray('pages', [
$this->insertArray('pages', [
'uid' => 2,
'pid' => 1,
'sys_language_uid' => 1,
'l10n_parent' => 1,
'doktype' => PageRepository::DOKTYPE_DEFAULT,
'title' => 'Dansk Foo Root',
]);
$this->getDatabaseConnection()->insertArray('pages', [
$this->insertArray('pages', [
'uid' => 100,
'doktype' => PageRepository::DOKTYPE_DEFAULT,
'title' => 'Bar Root',
]);
$this->getDatabaseConnection()->insertArray('pages', [
$this->insertArray('pages', [
'uid' => 200,
'doktype' => PageRepository::DOKTYPE_DEFAULT,
'title' => 'Qux Root',
]);

$typoScriptConstantsFile = 'EXT:searchable/Configuration/TypoScript/constants.typoscript';
$typoScriptSetupFile = 'EXT:searchable/Configuration/TypoScript/setup.typoscript';
$this->setUpFrontendRootPage(1, [
__DIR__ . '/Fixtures/TypoScript/page.typoscript',
$typoScriptSetupFile,
]);
$this->setUpFrontendRootPage(100);
$this->setUpFrontendRootPage(200);
$this->getDatabaseConnection()->updateArray(
'sys_template',
[
'pid' => 1,
$rootPageConfig = [
'setup' => [
'EXT:searchable/Tests/Functional/Fixtures/TypoScript/page.typoscript',
'EXT:searchable/Configuration/TypoScript/setup.typoscript',
],
'constants' => [
'EXT:searchable/Configuration/TypoScript/constants.typoscript',
],
];
$this->setUpFrontendRootPage(1, $rootPageConfig);
$this->setUpFrontendRootPage(100, $rootPageConfig);
$this->setUpFrontendRootPage(200, $rootPageConfig);

$this->writeSiteConfiguration(
'1',
$this->buildSiteConfiguration(1, '/'),
[
'constants' => '<INCLUDE_TYPOSCRIPT: source="FILE:' . $typoScriptConstantsFile . '">',
$this->buildDefaultLanguageConfiguration('EN', '/'),
$this->buildDefaultLanguageConfiguration('DE', '/de/'),
]
);
$this->writeSiteConfiguration(
'100',
$this->buildSiteConfiguration(100, '/'),
[
$this->buildDefaultLanguageConfiguration('EN', '100/'),
]
);
$this->writeSiteConfiguration(
'200',
$this->buildSiteConfiguration(200, '/'),
[
$this->buildDefaultLanguageConfiguration('EN', '200/'),
]
);

// Necessary for \TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseUserPermissionCheck
$this->importCSVDataSet(__DIR__ . '/Fixtures/be_users.csv');
$this->setUpBackendUser(1);

// Necessary for \TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseSystemLanguageRows
Bootstrap::initializeLanguageObject();

$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$this->indexingService = $objectManager->get(IndexingService::class);
$this->indexingService->setup();

$this->startWebserver();

// Update internally created site to flush all caches
$siteConfiguration = GeneralUtility::makeInstance(
SiteConfiguration::class,
Environment::getConfigPath() . '/sites'
);
$siteConfiguration->write('1', $siteConfiguration->load('1'));

// Necessary for \TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseUserPermissionCheck
$this->setUpBackendUserFromFixture(1);
// Necessary for \TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseSystemLanguageRows
Bootstrap::initializeLanguageObject();
}

/**
Expand All @@ -227,6 +250,20 @@ protected function tearDown(): void
]);

$this->stopWebserver();

unset($this->indexingService);

parent::tearDown();
}

protected function insertArray($tableName, $record)
{
return $this->getConnectionPool()->getConnectionForTable($tableName)->insert($tableName, $record);
}

protected function updateArray($tableName, $record, $identifier)
{
return $this->getConnectionPool()->getConnectionForTable($tableName)->update($tableName, $record, $identifier);
}

protected function assertIndexEmpty(int $languageId = 0): void
Expand Down Expand Up @@ -295,7 +332,7 @@ protected function syncIndices(): void
$this->getElasticsearchClient()->indices()->flushSynced([
'index' => implode(',', array_merge(
$this->indexNames,
[ 'searchable_updates' ]
['searchable_updates']
)),
]);
}
Expand Down
4 changes: 4 additions & 0 deletions Tests/Functional/Fixtures/be_users.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"be_users"
,"uid","pid","tstamp","username","password","admin","disable","starttime","endtime","options","crdate","workspace_perms","deleted","TSconfig","lastlogin","workspace_id"
# The password is "password"
,1,0,1366642540,"admin","$1$tCrlLajZ$C0sikFQQ3SWaFAZ1Me0Z/1",1,0,0,0,0,1366642540,1,0,,1371033743,0
22 changes: 20 additions & 2 deletions Tests/Functional/Middleware/UriBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,37 @@

namespace PAGEmachine\Searchable\Tests\Functional\Middleware;

use Nimut\TestingFramework\TestCase\FunctionalTestCase;
use PAGEmachine\Searchable\Tests\Functional\WebserverTrait;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Http\RequestFactory;
use TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;

/**
* Testcase for PAGEmachine\Searchable\Middleware\UriBuilder
*/
final class UriBuilderTest extends FunctionalTestCase
{
use WebserverTrait;
use SiteBasedTestTrait;

/**
* @var array
*/
protected $testExtensionsToLoad = [
protected array $testExtensionsToLoad = [
'typo3conf/ext/searchable',
];

protected $frameworkExtensionsToLoad = [
'Resources/Core/Functional/Extensions/private_container',
];

protected const LANGUAGE_PRESETS = [
'EN' => ['id' => 0, 'title' => 'English', 'locale' => 'en_US.UTF8'],
'DE' => ['id' => 1, 'title' => 'Deutsch', 'locale' => 'de_DE.UTF8'],
];

/**
* @test
*/
Expand Down Expand Up @@ -67,6 +78,13 @@ public function buildsUriForTypolinkParameter(): void
);

$this->setUpFrontendRootPage(1);
$this->writeSiteConfiguration(
'1',
$this->buildSiteConfiguration(1, '/'),
[
$this->buildDefaultLanguageConfiguration('EN', '/'),
]
);

$response = GeneralUtility::makeInstance(RequestFactory::class)->request(
'http://localhost:8080/-/searchable/urls',
Expand Down
6 changes: 3 additions & 3 deletions Tests/Functional/Query/SearchQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ final class SearchQueryTest extends AbstractElasticsearchTest
*/
public function searchesByTerm(): void
{
$this->getDatabaseConnection()->insertArray('pages', [
$this->insertArray('pages', [
'uid' => 3,
'pid' => 1,
'doktype' => PageRepository::DOKTYPE_DEFAULT,
'title' => 'Test page',
]);
$this->getDatabaseConnection()->insertArray('pages', [
$this->insertArray('pages', [
'uid' => 4,
'pid' => 1,
'doktype' => PageRepository::DOKTYPE_DEFAULT,
'title' => 'Another test page',
]);
$this->getDatabaseConnection()->insertArray('pages', [
$this->insertArray('pages', [
'uid' => 5,
'pid' => 1,
'doktype' => PageRepository::DOKTYPE_DEFAULT,
Expand Down
Loading