Skip to content

EspoCRM – Open Source CRM Application

Full text search test fixes

Yuriiba40fb378f4c
diff --git a/application/Espo/Core/Utils/Database/Schema/RebuildActions/PrepareForFulltextIndex.php b/application/Espo/Core/Utils/Database/Schema/RebuildActions/PrepareForFulltextIndex.php
index cc2a60ecce..4abe7ccb0c 100644
--- a/application/Espo/Core/Utils/Database/Schema/RebuildActions/PrepareForFulltextIndex.php
+++ b/application/Espo/Core/Utils/Database/Schema/RebuildActions/PrepareForFulltextIndex.php
@@ -70,8 +70,8 @@ class PrepareForFulltextIndex implements RebuildAction
continue;
}
- foreach ($index->getIndexedColumns() as $column) {
- $columnName = $column->getColumnName()->toString();
+ foreach ($index->getIndexedColumns() as $indexedColumn) {
+ $columnName = $indexedColumn->getColumnName()->getIdentifier()->getValue();
$quotedColumnName = $pdo->quote($columnName);
diff --git a/tests/integration/Espo/Core/FulltextIndex/CheckCreatedIndexTest.php b/tests/integration/Espo/Core/FulltextIndex/CheckCreatedIndexTest.php
index f5af1b56b5..92ef4557a0 100644
--- a/tests/integration/Espo/Core/FulltextIndex/CheckCreatedIndexTest.php
+++ b/tests/integration/Espo/Core/FulltextIndex/CheckCreatedIndexTest.php
@@ -29,8 +29,14 @@
namespace tests\integration\Espo\Core\FulltextIndex;
+use Doctrine\DBAL\Schema\Index\IndexType;
+use Doctrine\DBAL\Schema\Table;
+use Espo\Core\ORM\DatabaseParamsFactory;
+use Espo\Core\Utils\Database\Schema\SchemaManager;
use Espo\Core\Utils\Util;
+use PDO;
use PHPUnit\Framework\Attributes\DataProvider;
+use RuntimeException;
use tests\integration\Core\BaseTestCase;
class CheckCreatedIndexTest extends BaseTestCase
@@ -38,7 +44,7 @@ class CheckCreatedIndexTest extends BaseTestCase
protected ?string $dataFile = 'InitData.php';
protected ?string $pathToFiles = 'Core/FulltextIndex/customFiles';
- static public function entityList()
+ static public function entityTypeList(): array
{
return [
['Email'],
@@ -47,35 +53,85 @@ class CheckCreatedIndexTest extends BaseTestCase
];
}
- #[DataProvider('entityList')]
- public function testCreatedIndexes($entityName)
+ #[DataProvider('entityTypeList')]
+ public function testCreatedIndexes(string $entityType): void
{
- $entityManager = $this->getContainer()->get('entityManager');
- $pdo = $entityManager->getPDO();
+ if ($this->getPlatform() === 'Postgresql') {
+ return;
+ }
- $fulltextFieldList = $entityManager->getMetadata()->get($entityName, 'fullTextSearchColumnList');
+ $entityManager = $this->getEntityManager();
+
+ $fulltextFieldList = $entityManager->getMetadata()->get($entityType, 'fullTextSearchColumnList');
if (!$fulltextFieldList) {
$this->assertNull($fulltextFieldList);
+
return;
}
- $query = "SHOW INDEX FROM `". Util::toCamelCase($entityName) ."` WHERE Index_type = 'FULLTEXT'";
- $sth = $pdo->prepare($query);
- $sth->execute();
+ $expectedList = array_map(fn (string $it) => Util::toUnderScore($it), $fulltextFieldList);
+
+
+ $table = $this->getTable(Util::camelCaseToUnderscore($entityType));
+
+ $indexes = $table->getIndexes();
- $rowList = $sth->fetchAll(\PDO::FETCH_ASSOC);
+ $foundIndex = null;
- $this->assertNotEmpty($rowList);
+ foreach ($indexes as $index) {
+ if ($index->getType() !== IndexType::FULLTEXT) {
+ continue;
+ }
- $result = [];
- foreach ($rowList as $row) {
- $result[] = Util::toCamelCase($row['Column_name']);
+ $foundIndex = $index;
}
- asort($fulltextFieldList);
- asort($result);
+ if (!$foundIndex) {
+ throw new RuntimeException("Full-text index not found.");
+ }
+
+ $columnNames = [];
+
+ foreach ($foundIndex->getIndexedColumns() as $indexedColumn) {
+ $columnNames[] = $indexedColumn->getColumnName()->getIdentifier()->getValue();
+ }
+
+ asort($expectedList);
+ asort($columnNames);
+
+ $this->assertEquals($expectedList, $columnNames);
+ }
+
+ /**
+ * @noinspection PhpUnhandledExceptionInspection
+ */
+ private function getTable(string $name): Table
+ {
+ $manager = $this->getInjectableFactory()->create(SchemaManager::class);
+
+ $helper = $manager->getDatabaseHelper();
+
+ $tables = $helper->getDbalConnection()
+ ->createSchemaManager()
+ ->introspectTables();
+
+ foreach ($tables as $table) {
+ if ($table->getObjectName()->getUnqualifiedName()->getValue() !== $name) {
+ continue;
+ }
+
+ return $table;
+ }
+
+ throw new RuntimeException("Table '$name' not found.");
+ }
+
+ private function getPlatform(): ?string
+ {
+ $params = $this->getInjectableFactory()->create(DatabaseParamsFactory::class)
+ ->create();
- $this->assertEquals($fulltextFieldList, $result);
+ return $params->getPlatform();
}
}