From 2b3f79345f83c42a1b45cfd860dc364d33300883 Mon Sep 17 00:00:00 2001 From: Tim Curwick Date: Sun, 4 Sep 2016 10:42:58 -0500 Subject: [PATCH 1/4] Fix ConvertTo-Html single matched column header bug Fix ConvertTo-Html single matched column header bug Add ConvertTo-Html pester tests for single matched column header bug --- .../commands/utility/convert-HTML.cs | 18 +++--------------- .../ConvertTo-Html.Tests.ps1 | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 15 deletions(-) create mode 100644 test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/convert-HTML.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/convert-HTML.cs index 8acbd47b444..25917111625 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/convert-HTML.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/convert-HTML.cs @@ -22,7 +22,7 @@ namespace Microsoft.PowerShell.Commands /// [Cmdlet(VerbsData.ConvertTo, "Html", DefaultParameterSetName = "Page", - HelpUri = "https://go.microsoft.com/fwlink/?LinkID=113290", RemotingCapability = RemotingCapability.None)] + HelpUri = "http://go.microsoft.com/fwlink/?LinkID=113290", RemotingCapability = RemotingCapability.None)] public sealed class ConvertToHtmlCommand : PSCmdlet { @@ -283,24 +283,12 @@ private void InitializeResolvedNameMshParameters() string width = p.GetEntry(ConvertHTMLParameterDefinitionKeys.WidthEntryKey) as string; MshExpression ex = p.GetEntry(FormatParameterDefinitionKeys.ExpressionEntryKey) as MshExpression; List resolvedNames = ex.ResolveNames(_inputObject); - if (resolvedNames.Count == 1) + foreach (MshExpression resolvedName in resolvedNames) { Hashtable ht = CreateAuxPropertyHT(label, alignment, width); - if (ex.Script != null) - ht.Add(FormatParameterDefinitionKeys.ExpressionEntryKey, ex.Script); - else - ht.Add(FormatParameterDefinitionKeys.ExpressionEntryKey, ex.ToString()); + ht.Add(FormatParameterDefinitionKeys.ExpressionEntryKey, resolvedName.ToString()); resolvedNameProperty.Add(ht); } - else - { - foreach (MshExpression resolvedName in resolvedNames) - { - Hashtable ht = CreateAuxPropertyHT(label, alignment, width); - ht.Add(FormatParameterDefinitionKeys.ExpressionEntryKey, resolvedName.ToString()); - resolvedNameProperty.Add(ht); - } - } } _resolvedNameMshParameters = ProcessParameter(resolvedNameProperty.ToArray()); } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 new file mode 100644 index 00000000000..28e93551374 --- /dev/null +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 @@ -0,0 +1,17 @@ +Describe "ConvertTo-Html test" -Tags "CI" { + $customPSObject = [pscustomobject]@{ "prop1" = "val1"; "prop2" = "val2" } + + It "Test ConvertTo-Html header with default single property" -Skip:( $IsLinux -or $IsOSX -or $IsCoreCLR ) { + $returnObject = $customPSObject | Select prop1 | ConvertTo-Html + $columnHeader = $returnObject.Where{ $_.StartsWith( '' ) }[0] + $expectedValue = 'prop1' + $columnHeader | Should Be $expectedValue + } + + It "Test ConvertTo-Html header with matched single property" -Skip:( $IsLinux -or $IsOSX -or $IsCoreCLR ) { + $returnObject = $customPSObject | Select prop1 | ConvertTo-Html -Property prop* + $columnHeader = $returnObject.Where{ $_.StartsWith( '' ) }[0] + $expectedValue = 'prop1' + $columnHeader | Should Be $expectedValue + } +} \ No newline at end of file From 3ff33ec796dd9ac71fbc48acdbc9e0d6f33a78b9 Mon Sep 17 00:00:00 2001 From: Tim Curwick Date: Sun, 4 Sep 2016 11:17:53 -0500 Subject: [PATCH 2/4] Update convert-HTML.cs --- .../commands/utility/convert-HTML.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/convert-HTML.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/convert-HTML.cs index 25917111625..e1349558ff6 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/convert-HTML.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/convert-HTML.cs @@ -22,7 +22,7 @@ namespace Microsoft.PowerShell.Commands /// [Cmdlet(VerbsData.ConvertTo, "Html", DefaultParameterSetName = "Page", - HelpUri = "http://go.microsoft.com/fwlink/?LinkID=113290", RemotingCapability = RemotingCapability.None)] + HelpUri = "https://go.microsoft.com/fwlink/?LinkID=113290", RemotingCapability = RemotingCapability.None)] public sealed class ConvertToHtmlCommand : PSCmdlet { From 8aa1772e72730ad4732e7968147d65e1d598e81a Mon Sep 17 00:00:00 2001 From: Tim Curwick Date: Fri, 11 Nov 2016 11:55:44 -0800 Subject: [PATCH 3/4] Replaced aliases in ConvertTo-HTML.tests.ps1 --- .../Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 index 28e93551374..40f5c389410 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 @@ -2,16 +2,16 @@ $customPSObject = [pscustomobject]@{ "prop1" = "val1"; "prop2" = "val2" } It "Test ConvertTo-Html header with default single property" -Skip:( $IsLinux -or $IsOSX -or $IsCoreCLR ) { - $returnObject = $customPSObject | Select prop1 | ConvertTo-Html + $returnObject = $customPSObject | Select-Object prop1 | ConvertTo-Html $columnHeader = $returnObject.Where{ $_.StartsWith( '' ) }[0] $expectedValue = 'prop1' $columnHeader | Should Be $expectedValue } It "Test ConvertTo-Html header with matched single property" -Skip:( $IsLinux -or $IsOSX -or $IsCoreCLR ) { - $returnObject = $customPSObject | Select prop1 | ConvertTo-Html -Property prop* + $returnObject = $customPSObject | Select-Object prop1 | ConvertTo-Html -Property prop* $columnHeader = $returnObject.Where{ $_.StartsWith( '' ) }[0] $expectedValue = 'prop1' $columnHeader | Should Be $expectedValue } -} \ No newline at end of file +} From 6b1ecd4f9bc579525adb865035d6989443add1fa Mon Sep 17 00:00:00 2001 From: Tim Curwick Date: Fri, 11 Nov 2016 12:35:37 -0800 Subject: [PATCH 4/4] Resolved conflicts --- .../ConvertTo-Html.Tests.ps1 | 160 ++++++++++++++++-- 1 file changed, 148 insertions(+), 12 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 index 40f5c389410..a77e8d04fe0 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 @@ -1,17 +1,153 @@ -Describe "ConvertTo-Html test" -Tags "CI" { - $customPSObject = [pscustomobject]@{ "prop1" = "val1"; "prop2" = "val2" } +Describe "ConvertTo-Html Tests" -Tags "CI" { - It "Test ConvertTo-Html header with default single property" -Skip:( $IsLinux -or $IsOSX -or $IsCoreCLR ) { - $returnObject = $customPSObject | Select-Object prop1 | ConvertTo-Html - $columnHeader = $returnObject.Where{ $_.StartsWith( '' ) }[0] - $expectedValue = 'prop1' - $columnHeader | Should Be $expectedValue + BeforeAll { + $customObject = [pscustomobject]@{"Name" = "John Doe"; "Age" = 42; "Friends" = ("Jack", "Jill")} + $newLine = "`r`n" } - It "Test ConvertTo-Html header with matched single property" -Skip:( $IsLinux -or $IsOSX -or $IsCoreCLR ) { - $returnObject = $customPSObject | Select-Object prop1 | ConvertTo-Html -Property prop* - $columnHeader = $returnObject.Where{ $_.StartsWith( '' ) }[0] - $expectedValue = 'prop1' - $columnHeader | Should Be $expectedValue + function normalizeLineEnds([string]$text) + { + $text -replace "`r`n?|`n", "`r`n" + } + + It "Test ConvertTo-Html with no parameters" { + $returnObject = $customObject | ConvertTo-Html + $returnObject -is [System.Array] | Should Be $true + $returnString = $returnObject -join $newLine + $expectedValue = normalizeLineEnds @" + + + +HTML TABLE + + + + + +
NameAgeFriends
John Doe42System.Object[]
+ +"@ + $returnString | Should Be $expectedValue + } + + It "Test ConvertTo-Html Fragment parameter" { + $returnString = ($customObject | ConvertTo-Html -Fragment) -join $newLine + $expectedValue = normalizeLineEnds @" + + + + +
NameAgeFriends
John Doe42System.Object[]
+"@ + $returnString | Should Be $expectedValue + } + + It "Test ConvertTo-Html as List" { + $returnString = ($customObject | ConvertTo-Html -As List) -join $newLine + $expectedValue = normalizeLineEnds @" + + + +HTML TABLE + + + + + +
Name:John Doe
Age:42
Friends:System.Object[]
+ +"@ + $returnString | Should Be $expectedValue + } + + It "Test ConvertTo-Html specified properties" { + $returnString = ($customObject | ConvertTo-Html -Property Name, Friends -As List) -join $newLine + $expectedValue = normalizeLineEnds @" + + + +HTML TABLE + + + + +
Name:John Doe
Friends:System.Object[]
+ +"@ + $returnString | Should Be $expectedValue + } + + It "Test ConvertTo-Html using page parameters" { + $returnString = ($customObject | ConvertTo-Html -Title "Custom Object" -Body "Body Text" -CssUri "page.css" -As List) -join $newLine + $expectedValue = normalizeLineEnds @" + + + +Custom Object + + +Body Text + + + + +
Name:John Doe
Age:42
Friends:System.Object[]
+ +"@ + $returnString | Should Be $expectedValue + } + + It "Test ConvertTo-Html pre and post" { + $returnString = ($customObject | ConvertTo-Html -PreContent "Before the object" -PostContent "After the object") -join $newLine + $expectedValue = normalizeLineEnds @" + + + +HTML TABLE + +Before the object + + + + +
NameAgeFriends
John Doe42System.Object[]
+After the object + +"@ + $returnString | Should Be $expectedValue + } + It "Test ConvertTo-Html header with default single property" { + $returnString = ($customObject | Select-Object Name | ConvertTo-Html) -join $newLine + $expectedValue = normalizeLineEnds @" + + + +HTML TABLE + + + + + +
Name
John Doe
+ +"@ + $returnString | Should Be $expectedValue + } + It "Test ConvertTo-Html header with matched single property" { + $returnString = ($customObject | ConvertTo-Html -Property Name*) -join $newLine + $expectedValue = normalizeLineEnds @" + + + +HTML TABLE + + + + + +
Name
John Doe
+ +"@ + $returnString | Should Be $expectedValue } }