From 73a1f8cebe1256db7ae92beba55eb177ea9a8ca2 Mon Sep 17 00:00:00 2001 From: Serhii Kurylchyk Date: Mon, 28 Aug 2023 10:18:59 +0300 Subject: [PATCH 1/4] #162 Remove-IshPublicationOutput cmdlet * Fixed the Remove-IshPublicationOutput cmdlet for Tridion Docs 15.1 * Added the Pester tests for the Remove-IshPublicationOutput cmdlet * Added the ".editorconfig" file to overwrite an IDE setting of using "tabs" and "spaces" in files --- .editorconfig | 24 ++++++ .../RemoveIshPublicationOutput.Tests.ps1 | 76 +++++++++++++++++++ .../RemoveIshPublicationOutput.cs | 25 +++--- 3 files changed, 114 insertions(+), 11 deletions(-) create mode 100644 .editorconfig create mode 100644 Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/PublicationOutput/RemoveIshPublicationOutput.Tests.ps1 diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..ba793dce --- /dev/null +++ b/.editorconfig @@ -0,0 +1,24 @@ +# To learn more about .editorconfig see https://aka.ms/editorconfigdocs + +root = true + +# All files +[*] +indent_style = space +indent_size = 2 +end_of_line = crlf +max_line_length = off +charset = utf-8 +insert_final_newline = true +trim_trailing_whitespace = true + +# Code files +[*.cs] +end_of_line = crlf +indent_size = 4 + +[*.ps1] +end_of_line = crlf +indent_size = 4 + + diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/PublicationOutput/RemoveIshPublicationOutput.Tests.ps1 b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/PublicationOutput/RemoveIshPublicationOutput.Tests.ps1 new file mode 100644 index 00000000..fd4fce05 --- /dev/null +++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/PublicationOutput/RemoveIshPublicationOutput.Tests.ps1 @@ -0,0 +1,76 @@ +BeforeAll { + $cmdletName = "Remove-IshPublicationOutput" + Write-Host ("`r`nLoading ISHRemote.PesterSetup.ps1 over BeforeAll-block for MyCommand[" + $cmdletName + "]...") + . (Join-Path (Split-Path -Parent $PSCommandPath) "\..\..\ISHRemote.PesterSetup.ps1") + + Write-Host ("Running "+$cmdletName+" Test Data and Variables initialization") +} + +Describe "Remove-IshPublicationOutput" -Tags "Delete" { + BeforeAll { + $requestedMetadata = Set-IshRequestedMetadataField -IshSession $ishSession -Name "FNAME" | + Set-IshRequestedMetadataField -IshSession $ishSession -Name "FDOCUMENTTYPE" | + Set-IshRequestedMetadataField -IshSession $ishSession -Name "READ-ACCESS" -ValueType Element | + Set-IshRequestedMetadataField -IshSession $ishSession -Name "FUSERGROUP" -ValueType Element + $ishFolderTestRootOriginal = Get-IshFolder -IShSession $ishSession -FolderPath $folderTestRootPath -RequestedMetadata $requestedMetadata + $folderIdTestRootOriginal = $ishFolderTestRootOriginal.IshFolderRef + $folderTypeTestRootOriginal = $ishFolderTestRootOriginal.IshFolderType + Write-Debug ("folderIdTestRootOriginal[" + $folderIdTestRootOriginal + "] folderTypeTestRootOriginal[" + $folderTypeTestRootOriginal + "]") + $ownedByTestRootOriginal = Get-IshMetadataField -IshSession $ishSession -Name "FUSERGROUP" -ValueType Element -IshField $ishFolderTestRootOriginal.IshField + $readAccessTestRootOriginal = (Get-IshMetadataField -IshSession $ishSession -Name "READ-ACCESS" -ValueType Element -IshField $ishFolderTestRootOriginal.IshField).Split($ishSession.Separator) + + $global:ishFolderCmdlet = Add-IshFolder -IShSession $ishSession -ParentFolderId $folderIdTestRootOriginal -FolderType $folderTypeTestRootOriginal -FolderName $cmdletName -OwnedBy $ownedByTestRootOriginal -ReadAccess $readAccessTestRootOriginal + $ishFolderPub = Add-IshFolder -IshSession $ishSession -ParentFolderId ($global:ishFolderCmdlet.IshFolderRef) -FolderType ISHPublication -FolderName "Publication" -OwnedBy $ownedByTestRootOriginal -ReadAccess $readAccessTestRootOriginal + + $ishPublicationOutputMetadata = Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level Logical -Value "Pub $cmdletName $timestamp" | + Set-IshMetadataField -IshSession $ishSession -Name "FISHPUBSOURCELANGUAGES" -Level Version -ValueType Element -Value $ishLng | + Set-IshMetadataField -IshSession $ishSession -Name "FISHREQUIREDRESOLUTIONS" -Level Version -ValueType Element -Value $ishResolution + $ishObjectPubA = Add-IshPublicationOutput -IshSession $ishSession -IshFolder $ishFolderPub -LanguageCombination $ishLngCombination -OutputFormat $ishOutputFormatDitaXml -Metadata $ishPublicationOutputMetadata + } + + Context "Remove-IshPublicationOutput check exceptions" { + It "-LogicalId does not exist. Force=Yes" { + {Remove-IshPublicationOutput -IshSession $ishSession -LogicalId "NON-EXISTING-LOGICAL-ID" -Version "1" -LanguageCombination $ishLngCombination -OutputFormat $ishOutputFormatDitaXml -Force} | Should -Throw + } + It "-LogicalId does not exist" { + {Remove-IshPublicationOutput -IshSession $ishSession -LogicalId "NON-EXISTING-LOGICAL-ID" -Version "1" -LanguageCombination $ishLngCombination -OutputFormat $ishOutputFormatDitaXml} | Should -Throw + } + It "-Version does not exist. Force=Yes" { + {Remove-IshPublicationOutput -IshSession $ishSession -LogicalId $ishObjectPubA.IshRef -Version "999" -LanguageCombination $ishLngCombination -OutputFormat $ishOutputFormatDitaXml -Force} | Should -Throw + } + It "-Version does not exist" { + {Remove-IshPublicationOutput -IshSession $ishSession -LogicalId $ishObjectPubA.IshRef -Version "999" -LanguageCombination $ishLngCombination -OutputFormat $ishOutputFormatDitaXml} | Should -Throw + } + It "-LanguageCombination does not exist. Force=Yes" { + {Remove-IshPublicationOutput -IshSession $ishSession -LogicalId $ishObjectPubA.IshRef -Version "1" -LanguageCombination "NON-EXISTING-LANGUAGE-COMBINATION" -OutputFormat $ishOutputFormatDitaXml -Force} | Should -Throw + } + It "-LanguageCombination does not exist" { + {Remove-IshPublicationOutput -IshSession $ishSession -LogicalId $ishObjectPubA.IshRef -Version "1" -LanguageCombination "NON-EXISTING-LANGUAGE-COMBINATION" -OutputFormat $ishOutputFormatDitaXml} | Should -Throw + } + It "-OutputFormat does not exist. Force=Yes" { + {Remove-IshPublicationOutput -IshSession $ishSession -LogicalId $ishObjectPubA.IshRef -Version "999" -LanguageCombination $ishLngCombination -OutputFormat "NON-EXISTING-OUTPUT-FORMAT" -Force} | Should -Throw + } + It "-OutputFormat does not exist" { + {Remove-IshPublicationOutput -IshSession $ishSession -LogicalId $ishObjectPubA.IshRef -Version "999" -LanguageCombination $ishLngCombination -OutputFormat "NON-EXISTING-OUTPUT-FORMAT"} | Should -Throw + } + } + + Context "Remove-IshPublicationOutput remove PublicationOutput" { + It "Logical level. Force=Yes" { + $ishPubMetadata = $ishPublicationOutputMetadata | Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level Logical -Value "$($____Pester.CurrentTest.Name) $timestamp" + $ishPub = Add-IshPublicationOutput -IshSession $ishSession -IshFolder $ishFolderPub -LanguageCombination $ishLngCombination -OutputFormat $ishOutputFormatDitaXml -Metadata $ishPubMetadata + Remove-IshPublicationOutput -IshSession $ishSession -LogicalId $ishPub.IshRef -Version $ishPub.version_version_value -LanguageCombination $ishPub.fishpublngcombination -OutputFormat $ishPub.fishoutputformatref_lng_element -Force + $requestedMetadataRetrieve = Set-IshRequestedMetadataField -IshSession $ishSession -Name 'FTITLE' -Level Logical + $publicationOutput = Get-IshPublicationOutput -IshSession $ishSession -LogicalId $ishPub.IshRef -RequestedMetadata $requestedMetadataRetrieve + $publicationOutput.length -eq 0 | Should -Be $true + } + } +} + +AfterAll { + Write-Host ("Running "+$cmdletName+" Test Data and Variables cleanup") + $folderCmdletRootPath = (Join-Path $folderTestRootPath $cmdletName) + try { Get-IshFolder -IshSession $ishSession -FolderPath $folderCmdletRootPath -Recurse | Get-IshFolderContent -IshSession $ishSession | Remove-IshPublicationOutput -IshSession $ishSession -Force } catch { Write-Host "An error occurred: $_" } + try { Remove-IshFolder -IshSession $ishSession -FolderPath $folderCmdletRootPath -Recurse } catch { Write-Host "An error occurred: $_" } +} + diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/PublicationOutput/RemoveIshPublicationOutput.cs b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/PublicationOutput/RemoveIshPublicationOutput.cs index 52835f03..cb0928f6 100644 --- a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/PublicationOutput/RemoveIshPublicationOutput.cs +++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/PublicationOutput/RemoveIshPublicationOutput.cs @@ -200,22 +200,25 @@ protected override void ProcessRecord() } } - // Delete logical cards which do not have any languages anymore - foreach (string logicalId in logicalIdsVersionsCollection.AllKeys) + if ((IshSession.ServerIshVersion.MajorVersion < 15) || ((IshSession.ServerIshVersion.MajorVersion == 15) && (IshSession.ServerIshVersion.MinorVersion < 1))) { - bool logicalIdFound = false; - foreach (var retrievedObject in retrievedObjects) + // Delete logical cards which do not have any languages anymore + foreach (string logicalId in logicalIdsVersionsCollection.AllKeys) { - if (retrievedObject.IshRef == logicalId) + bool logicalIdFound = false; + foreach (var retrievedObject in retrievedObjects) { - logicalIdFound = true; + if (retrievedObject.IshRef == logicalId) + { + logicalIdFound = true; + } } - } - if (!logicalIdFound) - { - if (ShouldProcess(logicalId + "===")) + if (!logicalIdFound) { - IshSession.PublicationOutput25.Delete(logicalId, "", "", "", ""); + if (ShouldProcess(logicalId + "===")) + { + IshSession.PublicationOutput25.Delete(logicalId, "", "", "", ""); + } } } } From 820b88ec385e7f257ed61c21bb6737efa8531c9d Mon Sep 17 00:00:00 2001 From: Serhii Kurylchyk Date: Tue, 29 Aug 2023 13:19:25 +0300 Subject: [PATCH 2/4] [SCTCT-1630] Updated the ".editorconfig" file --- .editorconfig | 2 -- 1 file changed, 2 deletions(-) diff --git a/.editorconfig b/.editorconfig index ba793dce..39dbcefb 100644 --- a/.editorconfig +++ b/.editorconfig @@ -14,11 +14,9 @@ trim_trailing_whitespace = true # Code files [*.cs] -end_of_line = crlf indent_size = 4 [*.ps1] -end_of_line = crlf indent_size = 4 From d92afd534645ed355e497c703e9c0a07379c0df1 Mon Sep 17 00:00:00 2001 From: Serhii Kurylchyk Date: Mon, 4 Sep 2023 18:23:23 +0300 Subject: [PATCH 3/4] Renamed test --- .../PublicationOutput/RemoveIshPublicationOutput.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/PublicationOutput/RemoveIshPublicationOutput.Tests.ps1 b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/PublicationOutput/RemoveIshPublicationOutput.Tests.ps1 index fd4fce05..580ff985 100644 --- a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/PublicationOutput/RemoveIshPublicationOutput.Tests.ps1 +++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/PublicationOutput/RemoveIshPublicationOutput.Tests.ps1 @@ -56,7 +56,7 @@ Describe "Remove-IshPublicationOutput" -Tags "Delete" { } Context "Remove-IshPublicationOutput remove PublicationOutput" { - It "Logical level. Force=Yes" { + It "Logical level removed with Force=Yes" { $ishPubMetadata = $ishPublicationOutputMetadata | Set-IshMetadataField -IshSession $ishSession -Name "FTITLE" -Level Logical -Value "$($____Pester.CurrentTest.Name) $timestamp" $ishPub = Add-IshPublicationOutput -IshSession $ishSession -IshFolder $ishFolderPub -LanguageCombination $ishLngCombination -OutputFormat $ishOutputFormatDitaXml -Metadata $ishPubMetadata Remove-IshPublicationOutput -IshSession $ishSession -LogicalId $ishPub.IshRef -Version $ishPub.version_version_value -LanguageCombination $ishPub.fishpublngcombination -OutputFormat $ishPub.fishoutputformatref_lng_element -Force From f3b64dfba9829b89e528fcbb65399956d3042067 Mon Sep 17 00:00:00 2001 From: Serhii Kurylchyk Date: Mon, 4 Sep 2023 19:07:20 +0300 Subject: [PATCH 4/4] Fixed the Continuous Integration build --- .github/workflows/continuous-integration.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index ed701f5e..b45a9a33 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -72,6 +72,7 @@ jobs: Add-Content -Path $filePath -Value '$baseUrl = $env:ISH_BASE_URL' Add-Content -Path $filePath -Value 'if ($baseUrl -like "*.sdlproducts.com*")' Add-Content -Path $filePath -Value '{' + Add-Content -Path $filePath -Value ' $ishEventTypeToPurge = ''TESTBACKGROUNDTASK''' # before 14SP4 use ''PUSHTRANSLATIONS''' Add-Content -Path $filePath -Value ' $ishLngLabel = ''en-us''' Add-Content -Path $filePath -Value ' $ishLngTarget1 = ''VLANGUAGEESES''' Add-Content -Path $filePath -Value ' $ishLngTarget1Label = ''es-es'''