TYPO3 测试框架 - FunctionalTestCase 未从扩展加载 TCA 覆盖
Posted
技术标签:
【中文标题】TYPO3 测试框架 - FunctionalTestCase 未从扩展加载 TCA 覆盖【英文标题】:TYPO3 Testing Framework - FunctionalTestCase not loading TCA overrides from extension 【发布时间】:2021-09-06 21:19:58 【问题描述】:如何在 FunctionalTestCase 类中应用 TCA 覆盖?
我正在为扩展 FrontendUser 域模型和存储库的扩展编写 TYPO3 功能测试。 TYPO3 测试框架用于运行测试,但它似乎没有从Configuration/TCA/Overrides/fe_users.php
文件加载覆盖 TCA。是否有我缺少的Bootstrap
功能或者可能是额外的设置? (< >
标签下面的任何内容都已被替换为 NDA 目的,例如内部扩展密钥)
这是错误:
┐
├ TYPO3\CMS\Extbase\Persistence\Generic\Storage\Exception\SqlErrorException: Unknown column 'gender' in 'field list'
│
╵ <extension-folder>/.Build/Web/typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbBackend.php:146
╵ <extension-folder>/.Build/Web/typo3/sysext/extbase/Classes/Persistence/Generic/Backend.php:634
╵ <extension-folder>/.Build/Web/typo3/sysext/extbase/Classes/Persistence/Generic/Backend.php:282
╵ <extension-folder>/.Build/Web/typo3/sysext/extbase/Classes/Persistence/Generic/Backend.php:269
╵ <extension-folder>/.Build/Web/typo3/sysext/extbase/Classes/Persistence/Generic/PersistenceManager.php:166
╵ <extension-folder>/Tests/Functional/Domain/Repository/FrontendUserRepositoryTest.php:96
┴
这是功能测试类:
class FrontendUserRepositoryTest extends FunctionalTestCase
protected $testExtensionsToLoad = [
'typo3conf/ext/<my-extension-key>'
];
protected $coreExtensionsToLoad = [
'typo3/sysext/extbase'
];
/**
* @var FrontendUserRepository
*/
protected $frontendUserRepository;
/**
* @var PersistenceManager
*/
protected $persistenceManager;
/**
* @var FrontendUser
*/
protected $frontendUser;
/**
* @var string
*/
protected $email;
/**
* @var string
*/
protected $firstName;
/**
* @var string
*/
protected $lastName;
protected function setUp(): void
parent::setUp();
Bootstrap::initializeBackendUser();
$GLOBALS['BE_USER']->user['admin'] = 1;
$GLOBALS['BE_USER']->user['uid'] = 1;
$GLOBALS['BE_USER']->workspace = 0;
Bootstrap::initializeLanguageObject();
/** @var PersistenceManager $persistenceManager */
$this->persistenceManager = GeneralUtility::makeInstance(PersistenceManager::class);
$objectContainer = new Container($this->getContainer());
$objectManager = new ObjectManager($this->getContainer(), $objectContainer);
$this->frontendUserRepository = new FrontendUserRepository($objectManager);
$this->frontendUserRepository->injectPersistenceManager($this->persistenceManager);
$this->email = 'test@test.com';
$this->firstName = 'Tester';
$this->lastName = 'Man';
$this->frontendUser = GeneralUtility::makeInstance(FrontendUser::class);
$this->frontendUser->setEmail($this->email);
$this->frontendUser->setFirstName($this->firstName);
$this->frontendUser->setLastName($this->lastName);
/**
* @test
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
*/
public function testRetrieveByEmailFromRepository()
$this->frontendUserRepository->add($this->frontendUser);
$this->persistenceManager->persistAll();
/** @var FrontendUser $frontendUser */
$frontendUser = $this->frontendUserRepository->findUserByEmail($this->email)->getFirst();
$this->assertEquals($this->email, $frontendUser->getEmail());
$this->assertEquals($this->firstName, $frontendUser->getFirstName());
$this->assertEquals($this->lastName, $frontendUser->getLastName());
/**
* @test
*/
public function checkIfTableExists()
$queryBuilder = $this->getConnectionPool()->getQueryBuilderForTable('INFORMATION_SCHEMA.COLUMNS');
$queryBuilder->getRestrictions()->removeAll();
$query = $queryBuilder->select('COLUMN_NAME')
->from('INFORMATION_SCHEMA.COLUMNS')
->where(
$queryBuilder->expr()->eq('TABLE_NAME', $queryBuilder->createNamedParameter('fe_users'))
)
->execute();
/* Dumps the base fe_users table columns without the TCA overrides applied */
var_dump($query->fetchAllAssociative());
【问题讨论】:
【参考方案1】:我通过在 ext_tables.sql
文件中明确定义缺少的列解决了这个问题,但这不应该是必要的,因为扩展在没有这个定义的情况下工作:
CREATE TABLE fe_users (
gender tinyint DEFAULT 0 NOT NULL,
status tinyint DEFAULT 0 NOT NULL,
privacy tinyint(1) DEFAULT false NOT NULL,
--etc. etc.
);
如果有人能告诉我 TCA 覆盖保存到数据库表的位置,那将不胜感激。
【讨论】:
TCA 不会自动创建数据库列。您总是需要ext_tables.sql
来获取新字段,以便数据库比较工具将它们添加到数据库中。以上是关于TYPO3 测试框架 - FunctionalTestCase 未从扩展加载 TCA 覆盖的主要内容,如果未能解决你的问题,请参考以下文章
TYPO3 6.2 性能、Typoscript 选择、Typoscript 缓存
PHP OpenSSL 扩展在安装 TYPO3 CMS 7.4.0 时不起作用
如何在https TYPO3后端处理“非https”(http)站点
TYPO3:使用 TYPO3 Querybuilder 在 OrderBy 中使用 IS NULL 和 COALESCE