From 6ea5720f2cfabf53378db40bd6e7a92e97fcb340 Mon Sep 17 00:00:00 2001 From: Sebastian Helzle Date: Mon, 28 Oct 2024 09:14:29 +0100 Subject: [PATCH] TASK: Adjust tests to collection removal protection --- .../JavaScript/dev-server/src/fixtures/index.ts | 16 ++++++++++++++-- .../Private/JavaScript/dev-server/src/server.ts | 2 ++ phpstan.neon | 1 + 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Resources/Private/JavaScript/dev-server/src/fixtures/index.ts b/Resources/Private/JavaScript/dev-server/src/fixtures/index.ts index 52cad7cec..8e4ff0b20 100644 --- a/Resources/Private/JavaScript/dev-server/src/fixtures/index.ts +++ b/Resources/Private/JavaScript/dev-server/src/fixtures/index.ts @@ -77,6 +77,7 @@ const assetCollections: AssetCollection[] = range(3).map((index) => ({ : null, // TODO: Recalculate assetCount of assetCollections after generation of assets assetCount: 0, + canDelete: true, })); const getUsageDetailsForAsset = (assetId: string): UsageDetailsGroup[] => { @@ -154,6 +155,17 @@ const assets = range(150).map((index) => { const isCloud = index > 120; const filename = getExampleFilename(index); + const collectionsForAsset = range(index % 2).map( + (i) => assetCollections[(i * 2 + index) % assetCollections.length] + ); + + collectionsForAsset.forEach((collection) => { + collection.assetCount++; + collection.canDelete = false; + }); + + const tagsForAsset = range(index % 3).map((i) => tags[(i * 3 + index) % tags.length]); + return { __typename: 'Asset', id: index.toString(), @@ -163,8 +175,8 @@ const assets = range(150).map((index) => { label: `Example asset ${index + 1}`, caption: `The caption for example asset ${index + 1}`, filename: 'example1.jpg', - tags: range(index % 3).map((i) => tags[(i * 3 + index) % tags.length]), - collections: range(index % 2).map((i) => assetCollections[(i * 2 + index) % assetCollections.length]), + tags: tagsForAsset, + collections: collectionsForAsset, copyrightNotice: 'The Neos team', lastModified: new Date(`2020-06-16 15:${Math.floor((150 - index) / 60)}:${(150 - index) % 60}`), iptcProperties: index % 5 === 0 ? getIptcProperties(index) : [], diff --git a/Resources/Private/JavaScript/dev-server/src/server.ts b/Resources/Private/JavaScript/dev-server/src/server.ts index a1d9df7d4..4e6235e47 100644 --- a/Resources/Private/JavaScript/dev-server/src/server.ts +++ b/Resources/Private/JavaScript/dev-server/src/server.ts @@ -217,6 +217,7 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url)); deleteAssetCollection: ($_, { id }: { id: string }): boolean => { const assetCollection = assetCollections.find((assetCollection) => assetCollection.id === id); if (!assetCollection) return false; + if (assetCollection.assetCount > 0) return false; assetCollections = assetCollections.filter((assetCollection) => assetCollection.id !== id); return true; }, @@ -236,6 +237,7 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url)); : null, tags: [], assetCount: 0, + canDelete: true, }; assetCollections.push(newCollection); return newCollection; diff --git a/phpstan.neon b/phpstan.neon index 81c93a815..7a12b1867 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -4,3 +4,4 @@ parameters: - Classes ignoreErrors: - '#Call to an undefined method [a-zA-Z0-9\\_]+Repository::findBy[a-zA-Z]+\(\)#' + - '#Call to an undefined method [a-zA-Z0-9\\_]+Repository::findOneBy[a-zA-Z]+\(\)#'