appConfig = $this->createMock(AppConfig::class); $this->directEditor = new DirectEditor( "onlyoffice", $this->createStub(IL10N::class), $this->createStub(LoggerInterface::class), $this->appConfig, $this->createStub(Crypt::class), ); } /** * Returns an empty array when the user is not allowed to use the app, without inspecting format settings. */ public function testGetMimetypesReturnsEmptyWhenUserNotAllowed(): void { $this->appConfig->method("isUserAllowedToUse")->willReturn(false); $this->assertSame([], $this->directEditor->getMimetypes()); } /** * Returns only the mime types of formats marked as default (def=true), filtering out non-default formats. */ public function testGetMimetypesReturnsOnlyDefaultFormats(): void { $this->appConfig->method("isUserAllowedToUse")->willReturn(true); $this->appConfig->method("formatsSetting")->willReturn([ "docx" => ["mime" => ["application/vnd.openxmlformats-officedocument.wordprocessingml.document"], "def" => true], "xlsx" => ["mime" => ["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"], "def" => true], "pdf" => ["mime" => ["application/pdf"]], ]); $result = $this->directEditor->getMimetypes(); $this->assertCount(2, $result); $this->assertContains("application/vnd.openxmlformats-officedocument.wordprocessingml.document", $result); $this->assertContains("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", $result); $this->assertNotContains("application/pdf", $result); } /** * Returns an empty array when no formats are marked as default. */ public function testGetMimetypesReturnsEmptyWhenNoDefaultFormats(): void { $this->appConfig->method("isUserAllowedToUse")->willReturn(true); $this->appConfig->method("formatsSetting")->willReturn([ "pdf" => ["mime" => ["application/pdf"]], ]); $this->assertSame([], $this->directEditor->getMimetypes()); } /** * Returns an empty array when the user is not allowed to use the app, without inspecting format settings. */ public function testGetMimetypesOptionalReturnsEmptyWhenUserNotAllowed(): void { $this->appConfig->method("isUserAllowedToUse")->willReturn(false); $this->assertSame([], $this->directEditor->getMimetypesOptional()); } /** * Returns only the mime types of formats not marked as default, complementing getMimetypes(). */ public function testGetMimetypesOptionalReturnsNonDefaultFormats(): void { $this->appConfig->method("isUserAllowedToUse")->willReturn(true); $this->appConfig->method("formatsSetting")->willReturn([ "docx" => ["mime" => ["application/vnd.openxmlformats-officedocument.wordprocessingml.document"], "def" => true], "pdf" => ["mime" => ["application/pdf"]], "odt" => ["mime" => ["application/vnd.oasis.opendocument.text"], "def" => false], ]); $result = $this->directEditor->getMimetypesOptional(); $this->assertCount(2, $result); $this->assertContains("application/pdf", $result); $this->assertContains("application/vnd.oasis.opendocument.text", $result); $this->assertNotContains("application/vnd.openxmlformats-officedocument.wordprocessingml.document", $result); } /** * Partitions all formats between getMimetypes() and getMimetypesOptional() with no overlap. */ public function testGetMimetypesAndOptionalAreDisjointAndComplete(): void { $this->appConfig->method("isUserAllowedToUse")->willReturn(true); $this->appConfig->method("formatsSetting")->willReturn([ "docx" => ["mime" => ["application/vnd.openxmlformats-officedocument.wordprocessingml.document"], "def" => true], "xlsx" => ["mime" => ["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"], "def" => true], "pdf" => ["mime" => ["application/pdf"]], "odt" => ["mime" => ["application/vnd.oasis.opendocument.text"], "def" => false], ]); $default = $this->directEditor->getMimetypes(); $optional = $this->directEditor->getMimetypesOptional(); $this->assertEmpty(array_intersect($default, $optional)); $this->assertCount(4, array_merge($default, $optional)); } /** * Returns an empty array when the user is not allowed to use the app, presenting no file creation options. */ public function testGetCreatorsReturnsEmptyWhenUserNotAllowed(): void { $this->appConfig->method("isUserAllowedToUse")->willReturn(false); $this->assertSame([], $this->directEditor->getCreators()); } /** * Returns exactly three creators (docx, xlsx, pptx) when the user is allowed, one per supported format. */ public function testGetCreatorsReturnsThreeCreatorsWhenAllowed(): void { $this->appConfig->method("isUserAllowedToUse")->willReturn(true); $creators = $this->directEditor->getCreators(); $this->assertCount(3, $creators); } }