Skip to content

EspoCRM – Open Source CRM Application

Entity Manager Tool test. Register custom namespace

Yurii4291dc6edbc1
diff --git a/tests/integration/Core/BaseTestCase.php b/tests/integration/Core/BaseTestCase.php
index 0408c79197..0e41205c11 100644
--- a/tests/integration/Core/BaseTestCase.php
+++ b/tests/integration/Core/BaseTestCase.php
@@ -197,6 +197,9 @@ abstract class BaseTestCase extends TestCase
return $this->espoTester->normalizePath($path);
}
+ /**
+ * Important. CWD is not set to `build/test before `setUp` is called. Do not clean up anything before.
+ */
protected function setUp(): void
{
$params = [
diff --git a/tests/integration/Core/Registry.php b/tests/integration/Core/Registry.php
index b0cb4e39f2..27f48c5091 100644
--- a/tests/integration/Core/Registry.php
+++ b/tests/integration/Core/Registry.php
@@ -32,4 +32,9 @@ namespace tests\integration\Core;
class Registry
{
public static $isCleanAndReady = false;
+
+ /**
+ * Set before the first test run, and never set back.
+ */
+ public static $isNamespaceConfigured = false;
}
diff --git a/tests/integration/Core/Tester.php b/tests/integration/Core/Tester.php
index e687e71882..079aa1ab7e 100644
--- a/tests/integration/Core/Tester.php
+++ b/tests/integration/Core/Tester.php
@@ -29,6 +29,7 @@
namespace tests\integration\Core;
+use Composer\Autoload\ClassLoader;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Schema\SchemaException;
use Doctrine\DBAL\Schema\Table;
@@ -338,6 +339,10 @@ class Tester
$installer->setSuccess();
Registry::$isCleanAndReady = true;
+
+ if (!Registry::$isNamespaceConfigured) {
+ $this->configureNamespace();
+ }
}
// PDO can't be instantiated as dbname is set but database does not exist.
@@ -639,4 +644,17 @@ class Tester
return $services;
}
+
+ /**
+ * Called after cwd if set to the install-path.
+ */
+ private function configureNamespace(): void
+ {
+ $classLoader = new ClassLoader();
+
+ $classLoader->setPsr4("Espo\\Custom\\", "custom/Espo/Custom");
+ $classLoader->register();
+
+ Registry::$isNamespaceConfigured = true;
+ }
}
diff --git a/tests/integration/Espo/Tools/EntityTypeManager/EntityTypeManagerTest.php b/tests/integration/Espo/Tools/EntityTypeManager/EntityTypeManagerTest.php
new file mode 100644
index 0000000000..7459142052
--- /dev/null
+++ b/tests/integration/Espo/Tools/EntityTypeManager/EntityTypeManagerTest.php
@@ -0,0 +1,80 @@
+<?php
+/************************************************************************
+ * This file is part of EspoCRM.
+ *
+ * EspoCRM – Open Source CRM application.
+ * Copyright (C) 2014-2026 EspoCRM, Inc.
+ * Website: https://www.espocrm.com
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The interactive user interfaces in modified source and object code versions
+ * of this program must display Appropriate Legal Notices, as required under
+ * Section 5 of the GNU Affero General Public License version 3.
+ *
+ * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
+ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
+ ************************************************************************/
+
+namespace tests\integration\Espo\Tools\EntityTypeManager;
+
+use Espo\Core\Templates\Entities\BasePlus;
+use Espo\Tools\EntityManager\EntityManager;
+use integration\Core\NoTransaction;
+use tests\integration\Core\BaseTestCase;
+
+#[NoTransaction]
+class EntityTypeManagerTest extends BaseTestCase
+{
+ private const string PARAM_CATEGORIES = 'categories';
+
+ /**
+ * @noinspection PhpUnhandledExceptionInspection
+ */
+ public function testCreateUpdateDelete(): void
+ {
+ $name = 'TestEntityType';
+
+ $tool = $this->getInjectableFactory()->create(EntityManager::class);
+
+ $tool->create($name, BasePlus::TEMPLATE_TYPE, [
+ 'stream' => true,
+ ]);
+
+ //
+
+ $tool->update('C' . $name, [
+ 'stream' => false,
+ self::PARAM_CATEGORIES => true,
+ ]);
+
+ $this->reCreateApplication();
+
+ $em = $this->getEntityManager();
+
+ $this->assertTrue($em->hasRepository("C$name"));
+ $this->assertTrue($em->hasRepository("C{$name}Category"));
+
+ //
+
+ $tool->delete('C' . $name);
+
+ $this->reCreateApplication();
+
+ $em = $this->getEntityManager();
+
+ $this->assertFalse($em->hasRepository("C{$name}Category"));
+ $this->assertFalse($em->hasRepository("C$name"));
+ }
+}