ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
UploadHandlerTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ILIAS\LegalDocuments\test\ContainerMock;
24use ILIAS\UI\Component\Input\Field\UploadHandler as UploadHandlerInterface;
25use PHPUnit\Framework\TestCase;
30
31require_once __DIR__ . '/../ContainerMock.php';
32
33class UploadHandlerTest extends TestCase
34{
35 use ContainerMock;
36
37 public function testConstruct(): void
38 {
39 $this->assertInstanceOf(UploadHandler::class, new UploadHandler($this->fail(...), $this->fail(...), $this->fail(...)));
40 }
41
42 public function testGetFileIdentifierParameterName(): void
43 {
44 $instance = new UploadHandler($this->fail(...), $this->fail(...), $this->fail(...));
45 $this->assertSame(UploadHandlerInterface::DEFAULT_FILE_ID_PARAMETER, $instance->getFileIdentifierParameterName());
46 }
47
48 public function testLinks(): void
49 {
50 $instance = new UploadHandler(
51 static fn(string $to): string => 'Will link to: ' . $to,
52 $this->fail(...),
53 $this->fail(...)
54 );
55 $this->assertGetter($instance, [
56 'getUploadURL' => 'Will link to: upload',
57 'getFileRemovalURL' => 'Will link to: rm',
58 'getExistingFileInfoURL' => 'Will link to: info',
59 'supportsChunkedUploads' => false,
60 ]);
61 $this->assertSame([], $instance->getInfoForExistingFiles([]));
62 $this->assertSame([], $instance->getInfoForExistingFiles(['foo']));
63 }
64
65 public function testInfoResultWithResult(): void
66 {
67 $value = 'Lorem ipsum';
68 $document_content = $this->mockTree(DocumentContent::class, [
69 'value' => $value,
70 'type' => 'html',
71 ]);
72 $content = fn() => new Ok($document_content);
73 $instance = new UploadHandler($this->fail(...), $content, fn(string $s) => 'Translated ' . $s);
74 $info = $instance->getInfoResult('foo');
75 $this->assertSame(strlen($value), $info->getSize());
76 $this->assertSame('html', $info->getMimeType());
77 $this->assertSame('Translated updated_document', $info->getName());
78 $this->assertSame('foo', $info->getFileIdentifier());
79 }
80
81 public function testInfoResultWithoutResult(): void
82 {
83 $content = fn() => new Error('Nothing uploaded yet.');
84
85 $instance = new UploadHandler($this->fail(...), $content, $this->fail(...));
86 $this->assertSame(null, $instance->getInfoResult('foo'));
87 }
88}
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:31
$info
Definition: entry_point.php:21