ILIAS  release_8 Revision v8.24
AbstractBaseResourceBuilderTest.php
Go to the documentation of this file.
1<?php
2
19namespace ILIAS\ResourceStorage;
20
22require_once('AbstractBaseTest.php');
24require_once('DummyIDGenerator.php');
25
40use Psr\Http\Message\UploadedFileInterface;
41
47{
51 protected $revision;
55 protected $information;
59 protected $upload_result;
80 protected \ILIAS\ResourceStorage\Resource\ResourceBuilder $resource_builder;
88 protected $locking;
96 protected $stream_access;
98
99 protected function setUp(): void
100 {
101 parent::setUp();
102 $this->storage_handler = $this->createMock(StorageHandler::class);
103 $this->storage_handler_factory = $this->createMock(StorageHandlerFactory::class);
104 $this->storage_handler_factory->method('getPrimary')->willReturn($this->storage_handler);
105 $this->revision_repository = $this->createMock(RevisionRepository::class);
106 $this->resource_repository = $this->createMock(ResourceRepository::class);
107 $this->collection_repository = $this->createMock(CollectionRepository::class);
108 $this->information_repository = $this->createMock(InformationRepository::class);
109 $this->stakeholder_repository = $this->createMock(StakeholderRepository::class);
110 $this->repositories = new Repositories(
111 $this->revision_repository,
112 $this->resource_repository,
113 $this->collection_repository,
114 $this->information_repository,
115 $this->stakeholder_repository
116 );
117 $this->locking = $this->createMock(LockHandler::class);
118 $this->stream_access = $this->createMock(StreamAccess::class);
119 $this->information = $this->createMock(Information::class);
120 $this->revision = $this->createMock(Revision::class);
121 }
122
126 protected function mockResourceAndRevision(
127 string $expected_file_name,
128 string $expected_mime_type,
129 int $expected_size,
130 int $expected_version_number,
131 int $expected_owner_id
132 ): array {
133 $identification = $this->id_generator->getUniqueResourceIdentification();
134
136 $expected_file_name,
137 $expected_mime_type,
138 $expected_size
139 );
140
141 $info_resolver = new UploadInfoResolver(
143 $expected_version_number,
144 $expected_owner_id,
145 $upload_result->getName()
146 );
147
148 // MOCKS
149 $blank_resource = new StorableFileResource($identification);
150 $this->resource_repository->expects($this->once())
151 ->method('blank')
152 ->willReturn($blank_resource);
153
154 $blank_revision = new UploadedFileRevision($blank_resource->getIdentification(), $upload_result);
155 $blank_revision->setVersionNumber($info_resolver->getNextVersionNumber());
156 $this->revision_repository->expects($this->once())
157 ->method('blankFromUpload')
158 ->with(
159 $info_resolver,
160 $blank_resource,
162 )
163 ->willReturn($blank_revision);
164 return [$upload_result, $info_resolver, $identification];
165 }
166}
mockResourceAndRevision(string $expected_file_name, string $expected_mime_type, int $expected_size, int $expected_version_number, int $expected_owner_id)
ILIAS ResourceStorage Resource ResourceBuilder $resource_builder
getDummyUploadResult(string $file_name, string $mime_type, int $size)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...