Skip to content

Commit

Permalink
[TASK] Fix MM TCA of blog_example
Browse files Browse the repository at this point in the history
Extension blog_example is used in various extbase
tests. It defines invalid relations from tags
table over MM to post and persons.

The patch fixes the TCA - those relations now
work in BE as well, when the fixture blog_example
is activated.

Essentially all functional tests that works with
this extension break with the fixed TCA now. The
major part of the patch is to disentangle the .csv
import and export files to make them independent
from each other per test-case, and to fix the
imported and asserted db state along the way.

Resolves: #101528
Releases: main, 12.4
Change-Id: I4fb7d6ac82962f8ef7b630b261d543f4ff626bde
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/80295
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
  • Loading branch information
lolli42 committed Aug 2, 2023
1 parent b46ab5c commit a2e7236
Show file tree
Hide file tree
Showing 69 changed files with 1,885 additions and 1,364 deletions.
Expand Up @@ -83,36 +83,30 @@
'tags' => [
'label' => 'LLL:EXT:blog_example/Resources/Private/Language/locallang_db.xlf:tx_blogexample_domain_model_person.tags',
'config' => [
'type' => 'inline',
'type' => 'select',
'renderType' => 'selectMultipleSideBySide',
'foreign_table' => 'tx_blogexample_domain_model_tag',
'MM' => 'tx_blogexample_domain_model_tag_mm',
'MM_match_fields' => [
'fieldname' => 'tags',
'tablenames' => 'tx_blogexample_domain_model_person',
],
'appearance' => [
'useCombination' => 1,
'useSortable' => 1,
'collapseAll' => 1,
'expandSingle' => 1,
],
'MM_opposite_field' => 'items',
],
],
'tags_special' => [
'exclude' => true,
'label' => 'LLL:EXT:blog_example/Resources/Private/Language/locallang_db.xlf:tx_blogexample_domain_model_person.tags_special',
'config' => [
'type' => 'inline',
'type' => 'select',
'renderType' => 'selectMultipleSideBySide',
'foreign_table' => 'tx_blogexample_domain_model_tag',
'MM' => 'tx_blogexample_domain_model_tag_mm',
'MM_match_fields' => [
'fieldname' => 'tags_special',
'tablenames' => 'tx_blogexample_domain_model_person',
],
'appearance' => [
'useCombination' => 1,
'useSortable' => 1,
'collapseAll' => 1,
'expandSingle' => 1,
],
'MM_opposite_field' => 'items',
],
],
],
Expand Down
Expand Up @@ -178,15 +178,15 @@
'exclude' => true,
'label' => 'LLL:EXT:blog_example/Resources/Private/Language/locallang_db.xlf:tx_blogexample_domain_model_post.tags',
'config' => [
'type' => 'inline',
'type' => 'select',
'renderType' => 'selectMultipleSideBySide',
'foreign_table' => 'tx_blogexample_domain_model_tag',
'MM' => 'tx_blogexample_post_tag_mm',
'appearance' => [
'useCombination' => 1,
'useSortable' => 1,
'collapseAll' => 1,
'expandSingle' => 1,
'MM' => 'tx_blogexample_domain_model_tag_mm',
'MM_match_fields' => [
'fieldname' => 'tags',
'tablenames' => 'tx_blogexample_domain_model_post',
],
'MM_opposite_field' => 'items',
],
],
'comments' => [
Expand Down
Expand Up @@ -63,29 +63,28 @@
'max' => 256,
],
],
'posts' => [
'items' => [
'exclude' => true,
'label' => 'LLL:EXT:blog_example/Resources/Private/Language/locallang_db.xlf:tx_blogexample_domain_model_tag.posts',
'label' => 'LLL:EXT:blog_example/Resources/Private/Language/locallang_db.xlf:tx_blogexample_domain_model_tag.items',
'config' => [
'type' => 'select',
'renderType' => 'selectMultipleSideBySide',
'type' => 'group',
'allowed' => 'tx_blogexample_domain_model_person,tx_blogexample_domain_model_post',
'size' => 10,
'autoSizeMax' => 30,
'multiple' => 0,
'foreign_table' => 'tx_blogexample_domain_model_post',
'MM' => 'tx_blogexample_post_tag_mm',
// @todo: Broken. tx_blogexample_post_tag should be the local side, not the foreign side,
// since it is used from both _post and _person table. This field should drop
// MM_opposite_field and add MM_oppositeUsage instead, similar to sys_category items.
// The counterparts in _post and _person table need adaptions, too.
// It also does not make much sense to call this field 'posts' in the first place,
// since it is used from _person, too.
'MM_opposite_field' => 'tags',
'MM' => 'tx_blogexample_domain_model_tag_mm',
'MM_oppositeUsage' => [
'tx_blogexample_domain_model_person' => [
'tags',
'tags_special',
],
'tx_blogexample_domain_model_post' => [
'tags',
],
],
],
],
],
'types' => [
'1' => ['showitem' => 'sys_language_uid, hidden, name, posts'],
'1' => ['showitem' => 'sys_language_uid, hidden, name, items'],
],
'palettes' => [
'1' => ['showitem' => ''],
Expand Down
Expand Up @@ -117,8 +117,8 @@
<trans-unit id="tx_blogexample_domain_model_tag.name" resname="tx_blogexample_domain_model_tag.name">
<source>Name</source>
</trans-unit>
<trans-unit id="tx_blogexample_domain_model_tag.posts" resname="tx_blogexample_domain_model_tag.posts">
<source>Related posts</source>
<trans-unit id="tx_blogexample_domain_model_tag.items" resname="tx_blogexample_domain_model_tag.items">
<source>Related items</source>
</trans-unit>
<trans-unit id="tx_blogexample_domain_model_info" resname="tx_blogexample_domain_model_info">
<source>Additional Info</source>
Expand Down
Expand Up @@ -5,7 +5,7 @@ CREATE TABLE tx_blogexample_domain_model_blog (
title varchar(255) DEFAULT '' NOT NULL,
subtitle varchar(255) DEFAULT '',
description text NOT NULL,
logo tinyblob NOT NULL,
logo tinyblob NOT NULL default '',
administrator int(11) DEFAULT '0' NOT NULL,

posts varchar(255) DEFAULT '' NOT NULL
Expand Down Expand Up @@ -48,6 +48,7 @@ CREATE TABLE tx_blogexample_domain_model_person (
firstname varchar(255) DEFAULT '' NOT NULL,
lastname varchar(255) DEFAULT '' NOT NULL,
email varchar(255) DEFAULT '' NOT NULL,
salutation varchar(4) DEFAULT '' NOT NULL,
tags int(11) unsigned DEFAULT '0' NOT NULL,
tags_special int(11) unsigned DEFAULT '0' NOT NULL
);
Expand All @@ -57,37 +58,7 @@ CREATE TABLE tx_blogexample_domain_model_person (
#
CREATE TABLE tx_blogexample_domain_model_tag (
name varchar(255) DEFAULT '' NOT NULL,
posts int(11) unsigned DEFAULT '0' NOT NULL
);

#
# Table structure for table 'tx_blogexample_domain_model_tag_mm'
# @todo: Should be dropped when TCA is fixed.
#
CREATE TABLE tx_blogexample_domain_model_tag_mm (
uid_local int(11) unsigned DEFAULT '0' NOT NULL,
uid_foreign int(11) unsigned DEFAULT '0' NOT NULL,
tablenames varchar(255) DEFAULT '' NOT NULL,
fieldname varchar(255) DEFAULT '' NOT NULL,
sorting int(11) unsigned DEFAULT '0' NOT NULL,
sorting_foreign int(11) unsigned DEFAULT '0' NOT NULL,

KEY uid_local (uid_local),
KEY uid_foreign (uid_foreign)
);

#
# Table structure for table 'tx_blogexample_post_tag_mm'
# @todo: Should be dropped when TCA is fixed.
#
CREATE TABLE tx_blogexample_post_tag_mm (
uid_local int(11) unsigned DEFAULT '0' NOT NULL,
uid_foreign int(11) unsigned DEFAULT '0' NOT NULL,
sorting int(11) unsigned DEFAULT '0' NOT NULL,
sorting_foreign int(11) unsigned DEFAULT '0' NOT NULL,

KEY uid_local (uid_local),
KEY uid_foreign (uid_foreign)
items int(11) unsigned DEFAULT '0' NOT NULL
);

#
Expand Down
9 changes: 0 additions & 9 deletions typo3/sysext/extbase/Tests/Functional/Fixtures/pages.csv

This file was deleted.

Expand Up @@ -52,7 +52,7 @@ protected function setUp(): void
{
parent::setUp();

$this->importCSVDataSet(__DIR__ . '/../../Persistence/Fixtures/translatedBlogExampleData.csv');
$this->importCSVDataSet(__DIR__ . '/Fixture/ControllerArgumentsMappingTestImport.csv');

$configuration = [
'persistence' => [
Expand Down
@@ -0,0 +1,8 @@
"pages"
,"uid","pid","sorting","deleted","t3_origuid","t3ver_wsid","t3ver_state","t3ver_stage","t3ver_oid","title"
,1,0,256,0,0,0,0,0,0,"FunctionalTest"
,20,1,256,0,0,0,0,0,0,"Blog example test"
"tx_blogexample_domain_model_blog"
,"uid","pid","title","sys_language_uid","l18n_parent","administrator","subtitle","description","t3_origuid","deleted","hidden","posts","logo"
,1,20,"Blog 1",0,0,0,,,0,0,0,10,
,2,20,"Blog 1 DK",1,1,0,,,1,0,0,6,
Expand Up @@ -41,6 +41,12 @@ final class ActionControllerValidationTest extends FunctionalTestCase
'typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example',
];

public function setUp(): void
{
parent::setUp();
$this->importCSVDataSet(__DIR__ . '/Fixtures/ActionControllerValidationTestImport.csv');
}

public static function forwardedActionValidatesPreviouslyIgnoredArgumentDataProvider(): array
{
return [
Expand All @@ -66,10 +72,6 @@ public function forwardedActionValidatesPreviouslyIgnoredArgument(array $blogPos
$GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->create('default');
$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] = 'testkey';

$this->importCSVDataSet(__DIR__ . '/../../Fixtures/pages.csv');
$this->importCSVDataSet(__DIR__ . '/../../Persistence/Fixtures/blogs.csv');
$this->importCSVDataSet(__DIR__ . '/../../Persistence/Fixtures/posts.csv');

$response = new Response();
$serverRequest = (new ServerRequest())->withAttribute('extbase', new ExtbaseRequestParameters())->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_BE);
$GLOBALS['TYPO3_REQUEST'] = $serverRequest;
Expand Down Expand Up @@ -119,10 +121,6 @@ public function validationResultsAreProvidedForTheSameObjectInDifferentArguments
$GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->create('default');
$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] = 'testkey';

$this->importCSVDataSet(__DIR__ . '/../../Fixtures/pages.csv');
$this->importCSVDataSet(__DIR__ . '/../../Persistence/Fixtures/blogs.csv');
$this->importCSVDataSet(__DIR__ . '/../../Persistence/Fixtures/posts.csv');

$response = new Response();
$serverRequest = (new ServerRequest())->withAttribute('extbase', new ExtbaseRequestParameters())->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_BE);
$GLOBALS['TYPO3_REQUEST'] = $serverRequest;
Expand Down Expand Up @@ -186,10 +184,6 @@ public function argumentsOfOriginalRequestRemainOnValidationErrors(): void
$GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->create('default');
$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] = 'testkey';

$this->importCSVDataSet(__DIR__ . '/../../Fixtures/pages.csv');
$this->importCSVDataSet(__DIR__ . '/../../Persistence/Fixtures/blogs.csv');
$this->importCSVDataSet(__DIR__ . '/../../Persistence/Fixtures/posts.csv');

$response = new Response();
$serverRequest = (new ServerRequest())->withAttribute('extbase', new ExtbaseRequestParameters())
->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_BE);
Expand Down
@@ -0,0 +1,43 @@
"pages"
,"uid","pid","sorting","title","deleted","perms_everybody"
,1,0,128,"Root",0,15
,2,1,128,"Dummy 1-2",0,15
,3,2,128,"Dummy 1-2-3",0,15
,4,3,128,"Dummy 1-2-3-4",0,15
,5,1,256,"Dummy 1-5",0,15
,6,5,128,"Dummy 1-5-6",0,15
,7,0,256,"Root 2",0,15
tx_blogexample_domain_model_blog
,uid,pid,title,description,logo,l18n_diffsource,deleted,posts,administrator,categories,t3ver_oid,t3ver_state,t3ver_wsid,hidden
,1,0,Blog1,"Blog1 Description",,,0,10,0,0,0,0,0,0
,2,0,Blog2,"Blog2 Description",,,0,1,4,0,0,0,0,0
,3,0,Blog3,"Blog3 Description",,,0,1,3,0,0,0,0,0
,4,0,Blog4Hidden,"Blog4 Description",,,0,1,0,0,0,0,0,1
,5,0,Blog5Deleted,"Blog5 Description",,,1,1,3,0,0,0,0,0
,6,0,Blog6Hidden,"Blog6 Description",,,0,1,0,0,0,0,0,1
,7,0,BlogNoPosts,"Blog with w/o posts",,,0,0,0,0,0,0,0,0
,101,0,"WorkspaceOverlay Blog1","WorkspaceOverlay Blog1 Description",,,0,10,0,2,1,0,1,0
,102,0,"WorkspaceOverlay Blog6Enabled","WorkspaceOverlay Blog6 Description",,,0,1,0,1,6,0,1,0
,103,0,"WorkspaceOverlay Blog2HiddenInWorkspace","WorkspaceOverlay Blog2HiddenInWorkspace Description",,,0,1,0,0,2,0,1,1
,104,0,"WorkspaceOverlay Blog4HiddenInLiveAndWorkspace","WorkspaceOverlay Blog4HiddenInLiveAndWorkspace Description",,,0,1,0,0,4,0,1,1
tx_blogexample_domain_model_post
,uid,pid,tstamp,blog,author,reviewer,tags,date,categories,title,content,l18n_diffsource,sorting,deleted,hidden,related_posts,t3ver_oid,t3ver_state,t3ver_wsid
,1,0,121319,1,3,2,10,1502275450,3,Post1,"Lorem ipsum...",,1,0,0,1,0,0,0
,2,0,0,1,2,2,1,1502275450,0,Post2,"Lorem ipsum...",,2,0,0,0,0,0,0
,3,0,0,1,2,1,1,1502275450,0,Post3,"Lorem ipsum...",,3,0,0,0,0,0,0
,4,0,0,1,1,2,1,1502275450,0,Post4,"Lorem ipsum...",,4,0,0,0,0,0,0
,5,0,0,1,1,0,1,1502275450,0,Post5,"Lorem ipsum...",,5,0,0,0,0,0,0
,6,0,0,1,0,0,1,1502275450,0,Post6,"Lorem ipsum...",,6,0,0,0,0,0,0
,7,0,0,1,1,2,1,1502275450,0,Post7,"Lorem ipsum...",,7,0,0,0,0,0,0
,8,0,0,1,1,2,1,1502275450,0,Post8,"Lorem ipsum...",,8,0,0,0,0,0,0
,9,0,0,1,1,2,1,1502275450,0,Post9, "Lorem ipsum...",,9,0,0,0,0,0,0
,10,0,0,1,1,2,1,1502275450,0,Post10,"Lorem ipsum...",,10,0,0,0,0,0,0
,11,0,0,2,2,1,0,1502275450,0,post1,"Lorem ipsum...",,11,0,0,0,0,0,0
,12,0,0,3,0,2,1,1502275450,0,"post with tag","Lorem ipsum...",,1,0,0,0,0,0,0
,13,0,0,3,1,2,0,1502275450,0,"post with tagged author","Lorem ipsum...",,2,0,0,0,0,0,0
,14,0,0,3,1,2,1,1502275450,0,"post with tag and tagged author","Lorem ipsum...",,2,0,0,0,0,0,0
,20,0,0,3,1,3,0,1502275450,0,"post20 hidden","Lorem ipsum...",,11,0,1,0,0,0,0
,30,0,0,3,1,3,0,1502275450,0,"post30 deleted","Lorem ipsum...",,11,1,0,0,0,0,0
,101,0,121319,1,3,2,10,1502275450,3,"WorkspaceOverlay Post1","WorkspaceOverlay Lorem ipsum...",,1,0,0,1,1,0,1
,102,0,0,1,2,2,1,1502275450,0,"WorkspaceOverlay Post2","WorkspaceOverlay Lorem ipsum...",,2,0,0,0,2,0,1
,103,0,0,1,2,1,1,1502275450,0,"WorkspaceOverlay Post3","WorkspaceOverlay Lorem ipsum...",,3,0,0,0,3,0,1
Expand Up @@ -35,7 +35,7 @@ final class QueryResultPaginatorTest extends FunctionalTestCase
protected function setUp(): void
{
parent::setUp();
$this->importCSVDataSet(__DIR__ . '/../Persistence/Fixtures/posts.csv');
$this->importCSVDataSet(__DIR__ . '/Fixtures/QueryResultPaginatorTestImport.csv');
$this->postRepository = $this->get(PostRepository::class);
$request = (new ServerRequest())->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_BE);
$GLOBALS['TYPO3_REQUEST'] = $request;
Expand Down
16 changes: 7 additions & 9 deletions typo3/sysext/extbase/Tests/Functional/Persistence/AddTest.php
Expand Up @@ -29,7 +29,9 @@

final class AddTest extends FunctionalTestCase
{
protected array $testExtensionsToLoad = ['typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example'];
protected array $testExtensionsToLoad = [
'typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example',
];

protected PersistenceManager $persistentManager;
protected BlogRepository $blogRepository;
Expand Down Expand Up @@ -59,8 +61,7 @@ public function addSimpleObjectTest(): void
$this->persistentManager->persistAll();

$queryBuilder = (new ConnectionPool())->getQueryBuilderForTable('tx_blogexample_domain_model_blog');
$queryBuilder->getRestrictions()
->removeAll();
$queryBuilder->getRestrictions()->removeAll();
$newBlogCount = $queryBuilder
->count('*')
->from('tx_blogexample_domain_model_blog')
Expand Down Expand Up @@ -88,8 +89,7 @@ public function addObjectSetsDefaultLanguageTest(): void
$this->persistentManager->persistAll();

$queryBuilder = (new ConnectionPool())->getQueryBuilderForTable('tx_blogexample_domain_model_blog');
$queryBuilder->getRestrictions()
->removeAll();
$queryBuilder->getRestrictions()->removeAll();
$newBlogRecord = $queryBuilder
->select('*')
->from('tx_blogexample_domain_model_blog')
Expand Down Expand Up @@ -118,8 +118,7 @@ public function addObjectSetsDefinedLanguageTest(): void
$this->persistentManager->persistAll();

$queryBuilder = (new ConnectionPool())->getQueryBuilderForTable('tx_blogexample_domain_model_blog');
$queryBuilder->getRestrictions()
->removeAll();
$queryBuilder->getRestrictions()->removeAll();
$newBlogRecord = $queryBuilder
->select('*')
->from('tx_blogexample_domain_model_blog')
Expand Down Expand Up @@ -154,8 +153,7 @@ public function addObjectSetsNullAsNullForSimpleTypes(): void
$this->persistentManager->persistAll();

$queryBuilder = (new ConnectionPool())->getQueryBuilderForTable('tx_blogexample_domain_model_blog');
$queryBuilder->getRestrictions()
->removeAll();
$queryBuilder->getRestrictions()->removeAll();
$newBlogRecord = $queryBuilder
->select('*')
->from('tx_blogexample_domain_model_blog')
Expand Down

0 comments on commit a2e7236

Please sign in to comment.