TYPO3 Testing Framework - FunctionalTestCase not loading TCA overrides from extension

Viewed 59

How can I apply TCA overrides in a FunctionalTestCase class?

I am writing a TYPO3 functional test for an extension that extends the FrontendUser domain model and repository. The TYPO3 testing framework is used to run the test but it does not seem to load the override TCAs from the Configuration/TCA/Overrides/fe_users.php file. Is there a Bootstrap function I am missing or perhaps extra setup? (Anything below in < > tags has been replaced for NDA purposes, such as internal extension keys)

This is the error:

   ┐
   ├ 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
   ┴

This is the functional test class:

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 Answers

I solved this by defining the missing columns explicitly in the ext_tables.sql file, but this should not be neccessary since the extension was working without this defined:

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.
);

If someone can tell me where the TCA overrides are persisted to the database table, that would be greatly appreciated.

Related