2016-08-26 23:49:44 +02:00
|
|
|
Describe 'Testing of script internationalization' -Tags "CI" {
|
|
|
|
BeforeAll {
|
|
|
|
$dir=$PSScriptRoot
|
2016-08-30 02:54:20 +02:00
|
|
|
$defaultParamValues = $PSDefaultParameterValues.Clone()
|
|
|
|
#This works only for en-US or fr-FR
|
|
|
|
if ($PSUICulture -ne 'en-US' -and $PSUICulture -ne 'fr-FR')
|
|
|
|
{
|
|
|
|
$PSDefaultParameterValues["It:Skip"] = $true
|
2016-08-26 23:49:44 +02:00
|
|
|
}
|
2016-08-30 02:54:20 +02:00
|
|
|
}
|
|
|
|
AfterAll {
|
|
|
|
$global:PSDefaultParameterValues = $defaultParamValues
|
2017-01-16 22:31:14 +01:00
|
|
|
}
|
|
|
|
|
2016-08-26 23:49:44 +02:00
|
|
|
|
2016-08-30 02:54:20 +02:00
|
|
|
It 'convertFromString-Data should work with data statement.' {
|
2016-08-26 23:49:44 +02:00
|
|
|
|
|
|
|
data mydata
|
|
|
|
{
|
|
|
|
ConvertFrom-StringData @'
|
|
|
|
string1=string1
|
|
|
|
string2=string2
|
|
|
|
'@
|
|
|
|
}
|
|
|
|
|
2016-08-30 02:54:20 +02:00
|
|
|
$mydata.string1 | Should Be 'string1'
|
|
|
|
$mydata.string2 | Should Be 'string2'
|
2016-08-26 23:49:44 +02:00
|
|
|
}
|
|
|
|
|
2016-08-30 02:54:20 +02:00
|
|
|
It 'Import default culture is done correctly' {
|
2016-08-26 23:49:44 +02:00
|
|
|
|
|
|
|
import-localizedData mydata;
|
|
|
|
|
2016-08-30 02:54:20 +02:00
|
|
|
$mydata.string1 | Should Be 'string1 for en-US'
|
|
|
|
$mydata.string2 | Should be 'string2 for en-US'
|
2016-08-26 23:49:44 +02:00
|
|
|
}
|
|
|
|
|
2016-08-30 02:54:20 +02:00
|
|
|
It 'Import specific culture(en-US)' {
|
2016-08-26 23:49:44 +02:00
|
|
|
|
|
|
|
import-localizedData mydata -uiculture en-US
|
|
|
|
|
2016-08-30 02:54:20 +02:00
|
|
|
$mydata.string1 | Should Be 'string1 for en-US'
|
|
|
|
$mydata.string2 | Should Be 'string2 for en-US'
|
2016-08-26 23:49:44 +02:00
|
|
|
|
|
|
|
import-localizedData mydata -uiculture fr-FR
|
|
|
|
|
2016-08-30 02:54:20 +02:00
|
|
|
$mydata.string1 | Should Be 'string1 for fr-FR'
|
|
|
|
$mydata.string2 | Should Be 'string2 for fr-FR'
|
2016-08-26 23:49:44 +02:00
|
|
|
}
|
|
|
|
|
2016-08-30 02:54:20 +02:00
|
|
|
It 'Import non existing culture is done correctly' {
|
2017-01-16 22:31:14 +01:00
|
|
|
|
2016-08-26 23:49:44 +02:00
|
|
|
import-localizedData mydata -uiculture nl-NL -ea SilentlyContinue -ev ev
|
|
|
|
|
|
|
|
$ev[0].Exception.GetType() | Should Be System.Management.Automation.PSInvalidOperationException
|
|
|
|
}
|
|
|
|
|
2016-08-30 02:54:20 +02:00
|
|
|
It 'Import different file name is done correctly' {
|
2016-08-26 23:49:44 +02:00
|
|
|
|
|
|
|
import-localizedData mydata -filename foo
|
|
|
|
|
2016-08-30 02:54:20 +02:00
|
|
|
$mydata.string1 | Should Be 'string1 from foo in en-US'
|
|
|
|
$mydata.string2 | Should Be 'string2 from foo in en-US'
|
2016-08-26 23:49:44 +02:00
|
|
|
|
|
|
|
import-localizedData mydata -filename foo -uiculture fr-FR
|
|
|
|
|
2016-08-30 02:54:20 +02:00
|
|
|
$mydata.string1 | Should Be 'string1 from foo in fr-FR'
|
|
|
|
$mydata.string2 | Should Be 'string2 from foo in fr-FR'
|
2016-08-26 23:49:44 +02:00
|
|
|
}
|
|
|
|
|
2016-08-30 02:54:20 +02:00
|
|
|
It 'Import different file base is done correctly' {
|
2017-01-16 22:31:14 +01:00
|
|
|
|
2016-08-26 23:49:44 +02:00
|
|
|
import-localizedData mydata -basedirectory "${dir}\newbase"
|
|
|
|
|
2016-08-30 02:54:20 +02:00
|
|
|
$mydata.string1 | Should Be 'string1 for en-US under newbase'
|
|
|
|
$mydata.string2 | Should Be 'string2 for en-US under newbase'
|
2016-08-26 23:49:44 +02:00
|
|
|
|
|
|
|
import-localizedData mydata -basedirectory "${dir}\newbase" -uiculture fr-FR
|
|
|
|
|
2016-08-30 02:54:20 +02:00
|
|
|
$mydata.string1 | Should Be 'string1 for fr-FR under newbase'
|
|
|
|
$mydata.string2 | Should Be 'string2 for fr-FR under newbase'
|
2016-08-26 23:49:44 +02:00
|
|
|
}
|
|
|
|
|
2016-08-30 02:54:20 +02:00
|
|
|
It 'Import different file base and file name' {
|
2017-01-16 22:31:14 +01:00
|
|
|
|
2016-08-26 23:49:44 +02:00
|
|
|
import-localizedData mydata -basedirectory "${dir}\newbase" -filename foo
|
|
|
|
|
2016-08-30 02:54:20 +02:00
|
|
|
$mydata.string1 | Should Be 'string1 for en-US from foo under newbase'
|
|
|
|
$mydata.string2 | Should Be 'string2 for en-US from foo under newbase'
|
2016-08-26 23:49:44 +02:00
|
|
|
|
|
|
|
import-localizedData mydata -basedirectory "${dir}\newbase" -filename foo -uiculture fr-FR
|
|
|
|
|
2016-08-30 02:54:20 +02:00
|
|
|
$mydata.string1 | Should Be 'string1 for fr-FR from foo under newbase'
|
|
|
|
$mydata.string2 | Should Be 'string2 for fr-FR from foo under newbase'
|
2016-08-26 23:49:44 +02:00
|
|
|
}
|
|
|
|
|
2017-01-16 22:31:14 +01:00
|
|
|
It "Import variable that doesn't exist" {
|
2016-08-26 23:49:44 +02:00
|
|
|
|
2017-01-16 22:31:14 +01:00
|
|
|
import-localizedData mydata2
|
2016-08-26 23:49:44 +02:00
|
|
|
|
2016-08-30 02:54:20 +02:00
|
|
|
$mydata2.string1 | Should Be 'string1 for en-US'
|
|
|
|
$mydata2.string2 | Should Be 'string2 for en-US'
|
2016-08-26 23:49:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It 'Import bad psd1 file - tests the use of disallowed variables' {
|
2017-01-16 22:31:14 +01:00
|
|
|
|
2016-08-26 23:49:44 +02:00
|
|
|
$script:exception = $null
|
2017-01-16 22:31:14 +01:00
|
|
|
& {
|
2016-08-26 23:49:44 +02:00
|
|
|
trap {$script:exception = $_ ; continue }
|
|
|
|
import-localizedData mydata -filename bad
|
2017-01-16 22:31:14 +01:00
|
|
|
}
|
2016-08-26 23:49:44 +02:00
|
|
|
|
|
|
|
$script:exception.exception.gettype() | Should Be System.management.automation.psinvalidoperationexception
|
|
|
|
}
|
|
|
|
|
2016-08-30 02:54:20 +02:00
|
|
|
It 'Import if psd1 file is done correctly' {
|
2017-01-16 22:31:14 +01:00
|
|
|
|
2016-08-26 23:49:44 +02:00
|
|
|
import-localizedData mydata -filename if
|
|
|
|
|
|
|
|
if ($psculture -eq 'en-US')
|
2017-01-16 22:31:14 +01:00
|
|
|
{
|
2016-08-30 02:54:20 +02:00
|
|
|
$mydata.string1 | Should Be 'string1 for en-US in if'
|
|
|
|
$mydata.string2 | Should Be 'string2 for en-US in if'
|
2016-08-26 23:49:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-30 02:54:20 +02:00
|
|
|
$mydata | Should Be $null
|
2016-08-26 23:49:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-27 04:37:51 +02:00
|
|
|
$testData = @(
|
2016-09-02 20:07:18 +02:00
|
|
|
@{cmd = 'data d { @{ x=$(get-command)} }';Expected='get-command'},
|
|
|
|
@{cmd = 'data d { if ($(get-command)) {} }';Expected='get-command'},
|
|
|
|
@{cmd = 'data d { @(get-command) }';Expected='get-command'}
|
2016-08-27 04:37:51 +02:00
|
|
|
)
|
2016-08-26 23:49:44 +02:00
|
|
|
|
2016-08-27 04:37:51 +02:00
|
|
|
It 'Allowed cmdlets checked properly' -TestCase:$testData {
|
|
|
|
param ($cmd, $Expected)
|
2016-08-26 23:49:44 +02:00
|
|
|
|
|
|
|
$script:exception = $null
|
|
|
|
& {
|
2017-01-16 22:31:14 +01:00
|
|
|
trap {$script:exception = $_.Exception ; continue }
|
|
|
|
invoke-expression $cmd
|
|
|
|
}
|
|
|
|
|
2016-09-02 20:07:18 +02:00
|
|
|
$exception | Should Match $Expected
|
2016-08-26 23:49:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-30 02:54:20 +02:00
|
|
|
it 'Check alternate syntax that also supports complex variable names' {
|
2017-01-16 22:31:14 +01:00
|
|
|
|
2016-08-26 23:49:44 +02:00
|
|
|
& {
|
2016-09-02 20:07:18 +02:00
|
|
|
$script:mydata = data { 123 }
|
|
|
|
}
|
2016-08-30 02:54:20 +02:00
|
|
|
$mydata | Should Be 123
|
2016-08-26 23:49:44 +02:00
|
|
|
|
|
|
|
$mydata = data { 456 }
|
|
|
|
& {
|
|
|
|
# This import should not clobber the one at script scope
|
|
|
|
import-localizedData mydata -uiculture en-US
|
|
|
|
}
|
2016-08-30 02:54:20 +02:00
|
|
|
$mydata | Should Be 456
|
2016-08-26 23:49:44 +02:00
|
|
|
|
|
|
|
& {
|
|
|
|
# This import should clobber the one at script scope
|
|
|
|
import-localizedData script:mydata -uiculture en-US
|
2017-01-16 22:31:14 +01:00
|
|
|
}
|
2016-08-30 02:54:20 +02:00
|
|
|
$script:mydata.string1 | Should Be 'string1 for en-US'
|
2016-08-26 23:49:44 +02:00
|
|
|
}
|
|
|
|
|
2016-08-30 02:54:20 +02:00
|
|
|
It 'Check fallback to current directory plus -SupportedCommand parameter is done correctly' {
|
2017-01-16 22:31:14 +01:00
|
|
|
|
2016-08-26 23:49:44 +02:00
|
|
|
new-alias MyConvertFrom-StringData ConvertFrom-StringData
|
|
|
|
|
|
|
|
import-localizeddata local:mydata -uiculture fr-ca -filename I18n.Tests_fallback.psd1 -SupportedCommand MyConvertFrom-StringData
|
2016-08-30 02:54:20 +02:00
|
|
|
$mydata[0].string1 | Should Be 'fallback string1 for en-US'
|
|
|
|
$mydata[1] | Should Be 42
|
2016-08-26 23:49:44 +02:00
|
|
|
}
|
|
|
|
}
|