From 5be419e3a11409355dd79cf6f7ff9f91bd63c61b Mon Sep 17 00:00:00 2001
From: Oliver Hader <oliver@typo3.org>
Date: Wed, 19 Feb 2014 11:56:16 +0100
Subject: [PATCH] [BUGFIX] Discard vs. Delete workspace changes in tests

Discarding workspace changes works with the version command
"clearWSID" which might come down to a "delete" action if the
versioned records have a delete or new placeholder (which is
the case for copied or localized elements).
However, the functional tests need to use the "clearWSID"
instead of the "delete" command.

Resolves: #56111
Releases: 6.2
Change-Id: Id10413048a68abdb5ef05bb6e20e6cb6460f9742
Reviewed-on: https://review.typo3.org/27712
Reviewed-by: Oliver Hader
Tested-by: Oliver Hader
---
 .../DataHandling/Framework/ActionService.php  | 36 ++++++++++++++++++-
 .../ForeignField/AbstractActionTestCase.php   | 27 ++++++++++----
 ...entRecordAndDiscardDeletedParentRecord.csv | 24 +++++++++++++
 ...hildRecordAndDiscardAllModifiedRecords.csv |  4 +--
 ...ldRecordAndDiscardModifiedParentRecord.csv |  2 +-
 5 files changed, 83 insertions(+), 10 deletions(-)
 create mode 100644 typo3/sysext/workspaces/Tests/Functional/DataHandling/InlineRelationalRecordEditing/ForeignField/DataSet/Assertion/deleteParentContentRecordAndDiscardDeletedParentRecord.csv

diff --git a/typo3/sysext/core/Tests/Functional/DataHandling/Framework/ActionService.php b/typo3/sysext/core/Tests/Functional/DataHandling/Framework/ActionService.php
index a48c8007c1f6..be94b4bbdb9e 100644
--- a/typo3/sysext/core/Tests/Functional/DataHandling/Framework/ActionService.php
+++ b/typo3/sysext/core/Tests/Functional/DataHandling/Framework/ActionService.php
@@ -151,9 +151,10 @@ class ActionService {
 	/**
 	 * @param string $tableName
 	 * @param integer $uid
+	 * @return array
 	 */
 	public function deleteRecord($tableName, $uid) {
-		$this->deleteRecords(
+		return $this->deleteRecords(
 			array(
 				$tableName => array($uid),
 			)
@@ -162,6 +163,7 @@ class ActionService {
 
 	/**
 	 * @param array $tableRecordIds
+	 * @return array
 	 */
 	public function deleteRecords(array $tableRecordIds) {
 		$commandMap = array();
@@ -174,6 +176,38 @@ class ActionService {
 		}
 		$this->dataHandler->start(array(), $commandMap);
 		$this->dataHandler->process_cmdmap();
+		// Deleting workspace records is actually a copy(!)
+		return $this->dataHandler->copyMappingArray;
+	}
+
+	/**
+	 * @param string $tableName
+	 * @param integer $uid
+	 */
+	public function clearWorkspaceRecord($tableName, $uid) {
+		$this->clearWorkspaceRecords(
+			array(
+				$tableName => array($uid),
+			)
+		);
+	}
+
+	/**
+	 * @param array $tableRecordIds
+	 */
+	public function clearWorkspaceRecords(array $tableRecordIds) {
+		$commandMap = array();
+		foreach ($tableRecordIds as $tableName => $ids) {
+			foreach ($ids as $uid) {
+				$commandMap[$tableName][$uid] = array(
+					'version' => array(
+						'action' => 'clearWSID',
+					)
+				);
+			}
+		}
+		$this->dataHandler->start(array(), $commandMap);
+		$this->dataHandler->process_cmdmap();
 	}
 
 	/**
diff --git a/typo3/sysext/workspaces/Tests/Functional/DataHandling/InlineRelationalRecordEditing/ForeignField/AbstractActionTestCase.php b/typo3/sysext/workspaces/Tests/Functional/DataHandling/InlineRelationalRecordEditing/ForeignField/AbstractActionTestCase.php
index 4a65c9b3b70b..e833f07da66b 100644
--- a/typo3/sysext/workspaces/Tests/Functional/DataHandling/InlineRelationalRecordEditing/ForeignField/AbstractActionTestCase.php
+++ b/typo3/sysext/workspaces/Tests/Functional/DataHandling/InlineRelationalRecordEditing/ForeignField/AbstractActionTestCase.php
@@ -90,6 +90,16 @@ abstract class AbstractActionTestCase extends \TYPO3\CMS\Core\Tests\Functional\D
 		$this->assertAssertionDataSet('deleteParentContentRecord');
 	}
 
+	/**
+	 * @test
+	 */
+	public function deleteParentContentRecordAndDiscardDeletedParentRecord() {
+		$newTableIds = $this->actionService->deleteRecord(self::TABLE_Content, self::VALUE_ContentIdLast);
+		$versionedDeletedContentId = $newTableIds[self::TABLE_Content][self::VALUE_ContentIdLast];
+		$this->actionService->clearWorkspaceRecord(self::TABLE_Content, $versionedDeletedContentId);
+		$this->assertAssertionDataSet('deleteParentContentRecordAndDiscardDeletedParentRecord');
+	}
+
 	/**
 	 * @test
 	 */
@@ -213,7 +223,8 @@ abstract class AbstractActionTestCase extends \TYPO3\CMS\Core\Tests\Functional\D
 		$newContentId = $newTableIds['tt_content'][0];
 		$copiedTableIds = $this->actionService->copyRecord(self::TABLE_Content, $newContentId, self::VALUE_PageId);
 		$copiedContentId = $copiedTableIds[self::TABLE_Content][$newContentId];
-		$this->actionService->deleteRecord(self::TABLE_Content, $copiedContentId);
+		$versionedCopiedContentId = $this->actionService->getDataHander()->getAutoVersionId(self::TABLE_Content, $copiedContentId);
+		$this->actionService->clearWorkspaceRecord(self::TABLE_Content, $versionedCopiedContentId);
 		$this->assertAssertionDataSet('createAndCopyParentContentRecordWithHotelAndOfferChildRecordsAndDiscardCopiedParentRecord');
 	}
 
@@ -252,7 +263,8 @@ abstract class AbstractActionTestCase extends \TYPO3\CMS\Core\Tests\Functional\D
 		$newContentId = $newTableIds[self::TABLE_Content][0];
 		$localizedTableIds = $this->actionService->localizeRecord(self::TABLE_Content, $newContentId, self::VALUE_LanguageId);
 		$localizedContentId = $localizedTableIds[self::TABLE_Content][$newContentId];
-		$this->actionService->deleteRecord(self::TABLE_Content, $localizedContentId);
+		$versionedLocalizedContentId = $this->actionService->getDataHander()->getAutoVersionId(self::TABLE_Content, $localizedContentId);
+		$this->actionService->clearWorkspaceRecord(self::TABLE_Content, $versionedLocalizedContentId);
 		$this->assertAssertionDataSet('createAndLocalizeParentContentRecordWithHotelAndOfferChildRecordsAndDiscardLocalizedParentRecord');
 	}
 
@@ -297,7 +309,8 @@ abstract class AbstractActionTestCase extends \TYPO3\CMS\Core\Tests\Functional\D
 				self::TABLE_Content => array('uid' => self::VALUE_ContentIdFirst, 'tx_irretutorial_hotels' => '3,4'),
 			)
 		);
-		$this->actionService->deleteRecord(self::TABLE_Content, self::VALUE_ContentIdFirst);
+		$modifiedContentId = $this->actionService->getDataHander()->getAutoVersionId(self::TABLE_Content, self::VALUE_ContentIdFirst);
+		$this->actionService->clearWorkspaceRecord(self::TABLE_Content, $modifiedContentId);
 		$this->assertAssertionDataSet('modifyParentRecordWithHotelChildRecordAndDiscardModifiedParentRecord');
 	}
 
@@ -312,10 +325,12 @@ abstract class AbstractActionTestCase extends \TYPO3\CMS\Core\Tests\Functional\D
 				self::TABLE_Content => array('uid' => self::VALUE_ContentIdFirst, 'tx_irretutorial_hotels' => '3,4'),
 			)
 		);
-		$this->actionService->deleteRecords(
+		$modifiedContentId = $this->actionService->getDataHander()->getAutoVersionId(self::TABLE_Content, self::VALUE_ContentIdFirst);
+		$modifiedHotelId = $this->actionService->getDataHander()->getAutoVersionId(self::TABLE_Hotel, 4);
+		$this->actionService->clearWorkspaceRecords(
 				array(
-					self::TABLE_Hotel => array(4),
-					self::TABLE_Content => array(self::VALUE_ContentIdFirst),
+					self::TABLE_Hotel => array($modifiedHotelId),
+					self::TABLE_Content => array($modifiedContentId),
 				)
 		);
 		$this->assertAssertionDataSet('modifyParentRecordWithHotelChildRecordAndDiscardAllModifiedRecords');
diff --git a/typo3/sysext/workspaces/Tests/Functional/DataHandling/InlineRelationalRecordEditing/ForeignField/DataSet/Assertion/deleteParentContentRecordAndDiscardDeletedParentRecord.csv b/typo3/sysext/workspaces/Tests/Functional/DataHandling/InlineRelationalRecordEditing/ForeignField/DataSet/Assertion/deleteParentContentRecordAndDiscardDeletedParentRecord.csv
new file mode 100644
index 000000000000..405ca32f4c6b
--- /dev/null
+++ b/typo3/sysext/workspaces/Tests/Functional/DataHandling/InlineRelationalRecordEditing/ForeignField/DataSet/Assertion/deleteParentContentRecordAndDiscardDeletedParentRecord.csv
@@ -0,0 +1,24 @@
+tt_content
+,uid,pid,sorting,deleted,sys_language_uid,l18n_parent,t3ver_wsid,t3ver_state,t3ver_stage,t3ver_oid,t3ver_move_id,header,image,categories,tx_irretutorial_hotels
+,297,89,256,0,0,0,0,0,0,0,0,"Regular Element #1",,0,2
+,298,89,512,0,0,0,0,0,0,0,0,"Regular Element #2",,0,1
+tx_irretutorial_1nff_hotel
+,uid,pid,sorting,deleted,sys_language_uid,t3ver_wsid,t3ver_state,t3ver_stage,t3ver_oid,t3ver_move_id,title,parentid,parenttable,parentidentifier,offers
+,3,89,1,0,0,0,0,0,0,0,"Hotel #1",297,tt_content,,2
+,4,89,2,0,0,0,0,0,0,0,"Hotel #2",297,tt_content,,1
+,5,89,1,0,0,0,0,0,0,0,"Hotel #1",298,tt_content,,1
+tx_irretutorial_1nff_offer
+,uid,pid,sorting,deleted,sys_language_uid,t3ver_wsid,t3ver_state,t3ver_stage,t3ver_oid,t3ver_move_id,title,parentid,parenttable,parentidentifier,prices
+,5,89,1,0,0,0,0,0,0,0,"Offer #1.1",3,tx_irretutorial_1nff_hotel,,3
+,6,89,2,0,0,0,0,0,0,0,"Offer #1.2",3,tx_irretutorial_1nff_hotel,,2
+,7,89,1,0,0,0,0,0,0,0,"Offer #2.1",4,tx_irretutorial_1nff_hotel,,1
+,8,89,1,0,0,0,0,0,0,0,"Offer #1.1",5,tx_irretutorial_1nff_hotel,,1
+tx_irretutorial_1nff_price
+,uid,pid,sorting,deleted,sys_language_uid,t3ver_wsid,t3ver_state,t3ver_stage,t3ver_oid,t3ver_move_id,title,parentid,parenttable,parentidentifier
+,7,89,1,0,0,0,0,0,0,0,"Price #1.1.1",5,tx_irretutorial_1nff_offer,
+,8,89,2,0,0,0,0,0,0,0,"Price #1.1.2",5,tx_irretutorial_1nff_offer,
+,9,89,3,0,0,0,0,0,0,0,"Price #1.1.3",5,tx_irretutorial_1nff_offer,
+,10,89,1,0,0,0,0,0,0,0,"Price #1.2.1",6,tx_irretutorial_1nff_offer,
+,11,89,2,0,0,0,0,0,0,0,"Price #1.2.2",6,tx_irretutorial_1nff_offer,
+,12,89,1,0,0,0,0,0,0,0,"Price #2.1.1",7,tx_irretutorial_1nff_offer,
+,13,89,1,0,0,0,0,0,0,0,"Price #1.1.1",8,tx_irretutorial_1nff_offer,
diff --git a/typo3/sysext/workspaces/Tests/Functional/DataHandling/InlineRelationalRecordEditing/ForeignField/DataSet/Assertion/modifyParentRecordWithHotelChildRecordAndDiscardAllModifiedRecords.csv b/typo3/sysext/workspaces/Tests/Functional/DataHandling/InlineRelationalRecordEditing/ForeignField/DataSet/Assertion/modifyParentRecordWithHotelChildRecordAndDiscardAllModifiedRecords.csv
index 99b1a005cfd2..04f8f66743b5 100644
--- a/typo3/sysext/workspaces/Tests/Functional/DataHandling/InlineRelationalRecordEditing/ForeignField/DataSet/Assertion/modifyParentRecordWithHotelChildRecordAndDiscardAllModifiedRecords.csv
+++ b/typo3/sysext/workspaces/Tests/Functional/DataHandling/InlineRelationalRecordEditing/ForeignField/DataSet/Assertion/modifyParentRecordWithHotelChildRecordAndDiscardAllModifiedRecords.csv
@@ -2,13 +2,13 @@ tt_content
 ,uid,pid,sorting,deleted,sys_language_uid,l18n_parent,t3ver_wsid,t3ver_state,t3ver_stage,t3ver_oid,t3ver_move_id,header,image,categories,tx_irretutorial_hotels
 ,297,89,256,0,0,0,0,0,0,0,0,"Regular Element #1",,0,2
 ,298,89,512,0,0,0,0,0,0,0,0,"Regular Element #2",,0,1
-,299,-1,256,0,0,0,1,2,0,297,0,"Regular Element #1",0,0,2
+,299,-1,256,0,0,0,0,0,0,297,0,"Regular Element #1",0,0,2
 tx_irretutorial_1nff_hotel
 ,uid,pid,sorting,deleted,sys_language_uid,t3ver_wsid,t3ver_state,t3ver_stage,t3ver_oid,t3ver_move_id,title,parentid,parenttable,parentidentifier,offers
 ,3,89,1,0,0,0,0,0,0,0,"Hotel #1",297,tt_content,,2
 ,4,89,2,0,0,0,0,0,0,0,"Hotel #2",297,tt_content,,1
 ,5,89,1,0,0,0,0,0,0,0,"Hotel #1",298,tt_content,,1
-,6,-1,2,0,0,1,2,0,4,0,"Testing #1",299,tt_content,,1
+,6,-1,2,0,0,0,0,0,4,0,"Testing #1",299,tt_content,,1
 ,7,-1,1,0,0,1,0,0,3,0,"Hotel #1",299,tt_content,,2
 tx_irretutorial_1nff_offer
 ,uid,pid,sorting,deleted,sys_language_uid,t3ver_wsid,t3ver_state,t3ver_stage,t3ver_oid,t3ver_move_id,title,parentid,parenttable,parentidentifier,prices
diff --git a/typo3/sysext/workspaces/Tests/Functional/DataHandling/InlineRelationalRecordEditing/ForeignField/DataSet/Assertion/modifyParentRecordWithHotelChildRecordAndDiscardModifiedParentRecord.csv b/typo3/sysext/workspaces/Tests/Functional/DataHandling/InlineRelationalRecordEditing/ForeignField/DataSet/Assertion/modifyParentRecordWithHotelChildRecordAndDiscardModifiedParentRecord.csv
index f2128dbfcd50..af7494f8c052 100644
--- a/typo3/sysext/workspaces/Tests/Functional/DataHandling/InlineRelationalRecordEditing/ForeignField/DataSet/Assertion/modifyParentRecordWithHotelChildRecordAndDiscardModifiedParentRecord.csv
+++ b/typo3/sysext/workspaces/Tests/Functional/DataHandling/InlineRelationalRecordEditing/ForeignField/DataSet/Assertion/modifyParentRecordWithHotelChildRecordAndDiscardModifiedParentRecord.csv
@@ -2,7 +2,7 @@ tt_content
 ,uid,pid,sorting,deleted,sys_language_uid,l18n_parent,t3ver_wsid,t3ver_state,t3ver_stage,t3ver_oid,t3ver_move_id,header,image,categories,tx_irretutorial_hotels
 ,297,89,256,0,0,0,0,0,0,0,0,"Regular Element #1",,0,2
 ,298,89,512,0,0,0,0,0,0,0,0,"Regular Element #2",,0,1
-,299,-1,256,0,0,0,1,2,0,297,0,"Regular Element #1",0,0,2
+,299,-1,256,0,0,0,0,0,0,297,0,"Regular Element #1",0,0,2
 tx_irretutorial_1nff_hotel
 ,uid,pid,sorting,deleted,sys_language_uid,t3ver_wsid,t3ver_state,t3ver_stage,t3ver_oid,t3ver_move_id,title,parentid,parenttable,parentidentifier,offers
 ,3,89,1,0,0,0,0,0,0,0,"Hotel #1",297,tt_content,,2
-- 
GitLab