ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
AbstractBaseResourceBuilderTestCase.php
Go to the documentation of this file.
1<?php
2
19namespace ILIAS\ResourceStorage;
20
21use PHPUnit\Framework\MockObject\MockObject;
23
25require_once('AbstractTestBase.php');
27require_once('DummyIDGenerator.php');
28
44use Psr\Http\Message\UploadedFileInterface;
45
51{
55 public MockObject $flavour_repository;
59 protected MockObject $revision;
63 protected MockObject $information;
67 protected $upload_result;
71 protected MockObject $information_repository;
75 protected MockObject $resource_repository;
79 protected MockObject $collection_repository;
83 protected MockObject $revision_repository;
87 protected MockObject $storage_handler;
92 protected MockObject $stakeholder_repository;
96 protected MockObject $locking;
100 protected MockObject $storage_handler_factory;
105 protected MockObject $stream_access;
107
108 #[\Override]
109 protected function setUp(): void
110 {
112 $this->storage_handler = $this->createMock(StorageHandler::class);
113 $this->storage_handler_factory = $this->createMock(StorageHandlerFactory::class);
114 $this->storage_handler_factory->method('getPrimary')->willReturn($this->storage_handler);
115 $this->revision_repository = $this->createMock(RevisionRepository::class);
116 $this->resource_repository = $this->createMock(ResourceRepository::class);
117 $this->collection_repository = $this->createMock(CollectionRepository::class);
118 $this->information_repository = $this->createMock(InformationRepository::class);
119 $this->stakeholder_repository = $this->createMock(StakeholderRepository::class);
120 $this->flavour_repository = $this->createMock(FlavourRepository::class);
121 $this->repositories = new Repositories(
122 $this->revision_repository,
123 $this->resource_repository,
124 $this->collection_repository,
125 $this->information_repository,
126 $this->stakeholder_repository,
127 $this->flavour_repository
128 );
129 $this->locking = $this->createMock(LockHandler::class);
130 $this->stream_access = $this->createMock(StreamAccess::class);
131 $this->information = $this->createMock(Information::class);
132 $this->revision = $this->createMock(Revision::class);
133 }
134
138 protected function mockResourceAndRevision(
139 string $expected_file_name,
140 string $expected_mime_type,
141 int $expected_size,
142 int $expected_version_number,
143 int $expected_owner_id
144 ): array {
145 $identification = $this->id_generator->getUniqueResourceIdentification();
146
148 $expected_file_name,
149 $expected_mime_type,
150 $expected_size
151 );
152
153 $info_resolver = new UploadInfoResolver(
155 $expected_version_number,
156 $expected_owner_id,
157 $upload_result->getName()
158 );
159
160 // MOCKS
161 $blank_resource = new StorableFileResource($identification);
162 $this->resource_repository->expects($this->once())
163 ->method('blank')
164 ->willReturn($blank_resource);
165
166 $blank_revision = new UploadedFileRevision($blank_resource->getIdentification(), $upload_result);
167 $blank_revision->setVersionNumber($info_resolver->getNextVersionNumber());
168 $this->revision_repository->expects($this->once())
169 ->method('blankFromUpload')
170 ->with(
171 $info_resolver,
172 $blank_resource,
174 )
175 ->willReturn($blank_revision);
176 return [$upload_result, $info_resolver, $identification];
177 }
178}
mockResourceAndRevision(string $expected_file_name, string $expected_mime_type, int $expected_size, int $expected_version_number, int $expected_owner_id)
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...