Last active
January 11, 2016 02:19
-
-
Save AdamNaj/b36ea095e3668c22c07e to your computer and use it in GitHub Desktop.
Add-ItemVersion & Remove-ItemVersion tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$testPath = "master:\content\item-test" | |
$targetLang = "pl-PL" | |
$format = @{Property = @("ID", "Name", "Language", "Version", "Text"); AutoSize=$true } | |
$giParams = @{Path=$testPath; Version="*"; } | |
Set-HostProperty -HostWidth 180 | |
& { | |
if(Test-Path $testPath){ | |
Remove-Item $testPath -Force -Recurse | |
} | |
Copy-Item master:\content\home $testPath | |
Copy-Item master:\content\home "$testPath\item1" | |
Copy-Item master:\content\home "$testPath\item2" | |
Copy-Item master:\content\home "$testPath\item1\item11" | |
} | |
function Get-ItemAndChildren { | |
[CmdletBinding()] | |
param | |
( | |
[Parameter()] | |
[string]$Language | |
) | |
@(Get-Item $testPath -Language $Language) + (Get-ChildItem $testPath -Language $Language -Recurse) | |
} | |
function Invoke-Test { | |
[CmdletBinding()] | |
param | |
( | |
[Parameter()] | |
[string]$Message, | |
[Parameter()] | |
[ScriptBlock]$block, | |
[Parameter()] | |
[bool]$showTestData = $false, | |
[Parameter()] | |
[string]$messageColor = "Green" | |
) | |
Write-Host -ForegroundColor $messageColor $Message | |
& $block | |
if($showTestData){ | |
Get-ItemAndChildren $targetLang | ft @format | |
} | |
} | |
Invoke-Test "Create polish version of items out of Japanese versions (recursiveness from pipeline)" { | |
Get-ItemAndChildren "ja-JP" | Add-ItemVersion -TargetLanguage $targetLang -IfExist Append | Out-Null | |
} $true | |
Invoke-Test "Create a new version from German to Polish - append new version (recursiveness from pipeline)" { | |
Get-ItemAndChildren de-DE | Add-ItemVersion -TargetLanguage $targetLang -IfExist Append | Out-Null | |
} $true | |
Invoke-Test "Create a new version from English to Polish - append new version (recursiveness in cmdlet)" { | |
Add-ItemVersion -Path $testPath -Language en -TargetLanguage $targetLang -Recurse -IfExist Append | ft @format | |
} | |
Invoke-Test "Overwrite the English copy with Japanese copyfor the Polish version - append new version (recursiveness in cmdlet)" { | |
Add-ItemVersion -Path $testPath -Language ja-JP -TargetLanguage $targetLang -Recurse -IfExist OverwriteLatest | ft @format | |
} | |
Invoke-Test "Try Overwriting the Japanese copy with German for the Polish version - should not do anything as it already exists" { | |
Add-ItemVersion -Path $testPath -Language de-DE -TargetLanguage $targetLang -Recurse -IfExist Skip | ft @format | |
} $true | |
Invoke-Test "Try Overwrite the Japanese copy with German for the Polish version without recursing - only root item should change" { | |
Add-ItemVersion -Path $testPath -Language de-DE -TargetLanguage $targetLang -IfExist OverwriteLatest | Out-Null | |
} $true | |
Invoke-Test "Add 4 more Japanese versions based on German version to root item" { | |
Add-ItemVersion -Path $testPath -Language de-DE -TargetLanguage ja-JP -IfExist Append | Out-Null | |
Add-ItemVersion -Path $testPath -Language de-DE -TargetLanguage ja-JP -IfExist Append | Out-Null | |
Add-ItemVersion -Path $testPath -Language de-DE -TargetLanguage ja-JP -IfExist Append | Out-Null | |
Add-ItemVersion -Path $testPath -Language de-DE -TargetLanguage ja-JP -IfExist Append | Out-Null | |
Get-Item -Path $testPath -Language ja-JP -Version * | ft @format | |
} | |
Invoke-Test "Add 3 more Japanese versions based on itself" { | |
Add-ItemVersion -Path $testPath -Language ja-JP -IfExist Append | Out-Null | |
Add-ItemVersion -Path $testPath -Language ja-JP -IfExist Append | Out-Null | |
Add-ItemVersion -Path $testPath -Language ja-JP -IfExist Append | Out-Null | |
Get-Item -Path $testPath -Language ja-JP -Version * | ft @format | |
} | |
Invoke-Test "WhatIf - Remove version 2 from root and Children - items from pipeline" { | |
@(Get-Item $testPath -Language pl* -Version 2 ) + (Get-ChildItem $testPath -Language pl* -Version 2 -Recurse) | Remove-ItemVersion -WhatIf | |
} $false "Red" | |
Invoke-Test "WhatIf - Remove ALL polish versions from root and Children - items from pipeline" { | |
@(Get-Item $testPath -Language pl* ) + (Get-ChildItem $testPath -Language pl* -Recurse) | Remove-ItemVersion -WhatIf -Max 0 | |
} $false "Red" | |
Invoke-Test "WhatIf - Remove Version '2' from ALL test items" { | |
Remove-ItemVersion -Path $testPath -Language * -Version 2 -What -Recurse | |
} | |
Invoke-Test "WhatIf - Limit version number to 1 for root test item" { | |
Remove-ItemVersion -Path $testPath -Language * -MaxVersions 1 -What # -Recurse | |
} | |
Invoke-Test "WhatIf - Remove Polish and Japanese Language from root test item" { | |
Remove-ItemVersion -Path $testPath -Language "pl-pl", "ja-jp" -WhatIf | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment