|
19 | 19 | Get-Font -Name 'Akshar*' | Should -Not -BeNullOrEmpty |
20 | 20 | } |
21 | 21 |
|
22 | | - It '[Install-GoogleFont] - Skips an already-installed font' { |
23 | | - { Install-GoogleFont -Name 'Akshar' } | Should -Not -Throw |
24 | | - $verboseOutput = Install-GoogleFont -Name 'Akshar' -Verbose 4>&1 |
25 | | - ($verboseOutput | Out-String) | Should -Match 'Installing \[0\] fonts' |
26 | | - } |
27 | | - |
28 | | - It '[Install-GoogleFont] - Supports wildcard names' { |
29 | | - { Install-GoogleFont -Name 'ABee*' } | Should -Not -Throw |
30 | | - Get-Font -Name 'ABee*' | Should -Not -BeNullOrEmpty |
31 | | - } |
32 | | - |
33 | 22 | # It '[Install-GoogleFont] - Installs all fonts' { |
34 | 23 | # { Install-GoogleFont -All -Verbose } | Should -Not -Throw |
35 | 24 | # Get-Font -Name 'Nabla*' | Should -Not -BeNullOrEmpty |
36 | 25 | # } |
37 | 26 | } |
38 | | - |
39 | | - InModuleScope GoogleFonts { |
40 | | - Context 'Function: Install-GoogleFont (mocked download paths)' { |
41 | | - BeforeEach { |
42 | | - $script:originalGoogleFonts = $script:GoogleFonts |
43 | | - $script:originalDisableParallel = $env:PSMODULE_GOOGLEFONTS_DISABLE_PARALLEL |
44 | | - $script:originalDisableParallelForTests = $script:DisableParallelDownloadsForTests |
45 | | - $env:PSMODULE_GOOGLEFONTS_DISABLE_PARALLEL = '1' |
46 | | - $script:DisableParallelDownloadsForTests = $true |
47 | | - |
48 | | - $script:GoogleFonts = @( |
49 | | - [pscustomobject]@{ |
50 | | - Name = 'UnitTestFont' |
51 | | - Variant = 'regular' |
52 | | - URL = 'https://example.invalid/unittestfont.ttf' |
53 | | - } |
54 | | - ) |
55 | | - |
56 | | - Mock -CommandName Get-Font -MockWith { @() } |
57 | | - Mock -CommandName Install-Font -MockWith { } |
58 | | - Mock -CommandName Copy-Item -MockWith { } |
59 | | - Mock -CommandName New-Item -MockWith { [pscustomobject]@{ FullName = 'mock' } } |
60 | | - Mock -CommandName Test-Admin -MockWith { $true } |
61 | | - } |
62 | | - |
63 | | - AfterEach { |
64 | | - $script:GoogleFonts = $script:originalGoogleFonts |
65 | | - $env:PSMODULE_GOOGLEFONTS_DISABLE_PARALLEL = $script:originalDisableParallel |
66 | | - $script:DisableParallelDownloadsForTests = $script:originalDisableParallelForTests |
67 | | - } |
68 | | - |
69 | | - It '[Install-GoogleFont] - Uses cache hit path without new download' { |
70 | | - Mock -CommandName Test-Path -MockWith { |
71 | | - param( |
72 | | - [string] $Path, |
73 | | - [string] $LiteralPath, |
74 | | - [object] $PathType |
75 | | - ) |
76 | | - |
77 | | - if ($PSBoundParameters.ContainsKey('LiteralPath')) { |
78 | | - return $true |
79 | | - } |
80 | | - |
81 | | - return $true |
82 | | - } |
83 | | - |
84 | | - Mock -CommandName Invoke-WebRequest -MockWith { |
85 | | - throw 'Invoke-WebRequest should not be called when cache is used' |
86 | | - } |
87 | | - |
88 | | - { Install-GoogleFont -Name 'UnitTestFont' -Confirm:$false } | Should -Not -Throw |
89 | | - Assert-MockCalled -CommandName Invoke-WebRequest -Times 0 -Exactly |
90 | | - Assert-MockCalled -CommandName Copy-Item -Times 1 |
91 | | - Assert-MockCalled -CommandName Install-Font -Times 1 -Exactly |
92 | | - } |
93 | | - |
94 | | - It '[Install-GoogleFont] - Throws for AllUsers scope without admin rights' { |
95 | | - Mock -CommandName Test-Admin -MockWith { $false } |
96 | | - |
97 | | - { Install-GoogleFont -Name 'UnitTestFont' -Scope AllUsers -Confirm:$false } | Should -Throw |
98 | | - } |
99 | | - } |
100 | | - } |
101 | 27 | } |
0 commit comments