|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace OCA\Text\Tests; |
| 4 | + |
| 5 | +use OCA\Text\DirectEditing\TextDocumentCreator; |
| 6 | +use OCP\IAppConfig; |
| 7 | +use OCP\IL10N; |
| 8 | + |
| 9 | +class TextDocumentCreatorTest extends \PHPUnit\Framework\TestCase { |
| 10 | + private TextDocumentCreator $textDocumentCreator; |
| 11 | + |
| 12 | + private IL10N $l10n; |
| 13 | + |
| 14 | + private IAppConfig $appConfig; |
| 15 | + |
| 16 | + protected function setUp(): void { |
| 17 | + $this->l10n = $this->createMock(IL10N::class); |
| 18 | + $this->appConfig = $this->createMock(IAppConfig::class); |
| 19 | + $this->textDocumentCreator = new TextDocumentCreator($this->l10n, $this->appConfig); |
| 20 | + } |
| 21 | + |
| 22 | + public function testGetId(): void { |
| 23 | + $this->assertEquals('textdocument', $this->textDocumentCreator->getId()); |
| 24 | + } |
| 25 | + |
| 26 | + public function testGetName(): void { |
| 27 | + $this->l10n->expects($this->once()) |
| 28 | + ->method('t') |
| 29 | + ->with('text document') |
| 30 | + ->willReturn('text document'); |
| 31 | + $this->assertEquals('text document', $this->textDocumentCreator->getName()); |
| 32 | + } |
| 33 | + |
| 34 | + public function testGetDefaultExtension(): void { |
| 35 | + $this->appConfig->expects($this->once()) |
| 36 | + ->method('getValueString') |
| 37 | + ->with('text', 'default_file_extension', 'md') |
| 38 | + ->willReturn('md'); |
| 39 | + $this->assertEquals('md', $this->textDocumentCreator->getExtension()); |
| 40 | + } |
| 41 | + |
| 42 | + public function testGetExtensionFromConfig(): void { |
| 43 | + $this->appConfig->expects($this->once()) |
| 44 | + ->method('getValueString') |
| 45 | + ->with('text', 'default_file_extension', 'md') |
| 46 | + ->willReturn('txt'); |
| 47 | + |
| 48 | + $this->assertEquals('txt', $this->textDocumentCreator->getExtension()); |
| 49 | + } |
| 50 | + |
| 51 | + public function testGetDefaultMimetype(): void { |
| 52 | + $this->assertEquals('text/markdown', $this->textDocumentCreator->getMimetype()); |
| 53 | + } |
| 54 | + |
| 55 | + public function testGetMimetypeFromConfig(): void { |
| 56 | + $this->appConfig->expects($this->once()) |
| 57 | + ->method('getValueString') |
| 58 | + ->with('text', 'default_file_extension', 'md') |
| 59 | + ->willReturn('txt'); |
| 60 | + |
| 61 | + $this->assertEquals('text/plain', $this->textDocumentCreator->getMimetype()); |
| 62 | + } |
| 63 | +} |
0 commit comments