["application/vnd.openxmlformats-officedocument.wordprocessingml.document", "document"], "spreadsheet" => ["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "spreadsheet"], "presentation" => ["application/vnd.openxmlformats-officedocument.presentationml.presentation", "presentation"], "unknown" => ["application/pdf", ""], ]; } #[DataProvider("mimeToTypeProvider")] /** * Maps each Office mime type to its corresponding template type string, returning empty for unknown types. */ public function testGetTypeTemplateReturnsExpectedType(string $mime, string $expected): void { $this->assertSame($expected, TemplateManager::getTypeTemplate($mime)); } public static function typeToMimeProvider(): array { return [ "document" => ["document", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"], "spreadsheet" => ["spreadsheet", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"], "presentation" => ["presentation", "application/vnd.openxmlformats-officedocument.presentationml.presentation"], "unknown" => ["pdf", ""], ]; } #[DataProvider("typeToMimeProvider")] /** * Maps each template type string back to its full Office mime type, returning empty for unknown types. */ public function testGetMimeTemplateReturnsExpectedMime(string $type, string $expected): void { $this->assertSame($expected, TemplateManager::getMimeTemplate($type)); } public static function templateTypeProvider(): array { return [ "docx" => ["file.docx", true], "xlsx" => ["file.xlsx", true], "pptx" => ["file.pptx", true], "uppercase DOCX" => ["file.DOCX", true], "pdf" => ["file.pdf", false], "no extension" => ["file", false], ]; } #[DataProvider("templateTypeProvider")] /** * Recognises docx, xlsx, and pptx as template types (case-insensitively) and rejects all other extensions. */ public function testIsTemplateTypeReturnsExpectedResult(string $name, bool $expected): void { $this->assertSame($expected, TemplateManager::isTemplateType($name)); } /** * Maps a known language code to its BCP 47 locale folder and ends the path with the expected filename. */ public function testGetEmptyTemplatePathContainsLocaleFolderForKnownLanguage(): void { $path = TemplateManager::getEmptyTemplatePath("en", ".docx"); $this->assertStringContainsString("en-US", $path); $this->assertStringEndsWith("new.docx", $path); } /** * Falls back to the "default" locale folder for an unrecognised language code without throwing. */ public function testGetEmptyTemplatePathFallsBackToDefaultForUnknownLanguage(): void { $path = TemplateManager::getEmptyTemplatePath("xx", ".xlsx"); $this->assertStringContainsString("default", $path); $this->assertStringEndsWith("new.xlsx", $path); } /** * Resolves underscore-separated locale variants (e.g. de_DE, pt_BR, zh_CN) to their hyphenated BCP 47 counterparts. */ public function testGetEmptyTemplatePathMapsLocaleVariantsCorrectly(): void { $this->assertStringContainsString("de-DE", TemplateManager::getEmptyTemplatePath("de_DE", ".pptx")); $this->assertStringContainsString("pt-BR", TemplateManager::getEmptyTemplatePath("pt_BR", ".docx")); $this->assertStringContainsString("zh-CN", TemplateManager::getEmptyTemplatePath("zh_CN", ".docx")); } }