@@ -213,6 +213,15 @@ Describe "Get-BloggerPost" {
213213 $frontMatter.postId | Should - Be " 123"
214214 }
215215
216+ It " Should write title to frontmatter" {
217+ # act
218+ Get-BloggerPost - PostId $postId - Format Markdown - OutDirectory " TestDrive:\"
219+
220+ # assert
221+ $frontMatter = Get-MarkdownFrontMatter - File $outFile
222+ $frontMatter.title | Should - Be " Test Post"
223+ }
224+
216225 It " Should write labels to frontmatter" {
217226 # act
218227 Get-BloggerPost - PostId $postId - Format Markdown - OutDirectory " TestDrive:\"
@@ -250,6 +259,54 @@ Describe "Get-BloggerPost" {
250259 $frontMatter [' tags' ] -eq $null | Should - BeFalse
251260 $frontMatter [' tags' ] | Should - Be @ ()
252261 }
262+
263+ Context " Illegal characters in title" {
264+ It " Should sanitize filename when title contains special character (<character>)" - TestCases @ (
265+ @ { character = ' ?' ; }
266+ @ { character = ' /' ; }
267+ @ { character = ' :' ; }
268+ @ { character = ' *' ; }
269+ @ { character = ' "' ; }
270+ @ { character = ' <' ; }
271+ @ { character = ' >' ; }
272+ @ { character = ' |' ; }
273+ ) {
274+ $title = " Test$ ( $character ) Post"
275+
276+ # arrange
277+ InModuleScope PSBlogger - Parameters @ { testTitle = $title } {
278+ param ($testTitle )
279+
280+ $script :currentTitle = $testTitle
281+
282+ # Mock the session to return a test blog ID
283+ $BloggerSession.BlogId = " test-blog-id"
284+
285+ $postId = " 123"
286+
287+ # mock post retrieval
288+ Mock Invoke-GApi - MockWith {
289+ [pscustomobject ]@ {
290+ id = " 123"
291+ title = $script :currentTitle
292+ published = [datetime ]" 2023-10-01T17:30:00-04:00"
293+ content = " <h1>Hello World</h1><p>This is a post.</p>"
294+ }
295+ }
296+ }
297+
298+ $expectedFileName = " Test_Post.md"
299+ $outFile = Get-TestFilePath $expectedFileName
300+
301+ # act
302+ Get-BloggerPost - PostId $postId - Format Markdown - OutDirectory " TestDrive:\"
303+
304+ # assert
305+ Test-Path $outFile | Should - BeTrue
306+ $frontMatter = Get-MarkdownFrontMatter - File $outFile
307+ $frontMatter.title | Should - Be $title
308+ }
309+ }
253310 }
254311
255312 Context " As Json" {
0 commit comments