ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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{
52 public MockObject $flavour_repository;
56 protected MockObject $revision;
60 protected MockObject $information;
64 protected $upload_result;
68 protected MockObject $information_repository;
72 protected MockObject $resource_repository;
76 protected MockObject $collection_repository;
80 protected MockObject $revision_repository;
84 protected MockObject $storage_handler;
89 protected MockObject $stakeholder_repository;
93 protected MockObject $locking;
97 protected MockObject $storage_handler_factory;
101 protected MockObject $stream_access;
103
104 #[\Override]
105 protected function setUp(): void
106 {
107 parent::setUp();
108 $this->storage_handler = $this->createMock(StorageHandler::class);
109 $this->storage_handler_factory = $this->createMock(StorageHandlerFactory::class);
110 $this->storage_handler_factory->method('getPrimary')->willReturn($this->storage_handler);
111 $this->revision_repository = $this->createMock(RevisionRepository::class);
112 $this->resource_repository = $this->createMock(ResourceRepository::class);
113 $this->collection_repository = $this->createMock(CollectionRepository::class);
114 $this->information_repository = $this->createMock(InformationRepository::class);
115 $this->stakeholder_repository = $this->createMock(StakeholderRepository::class);
116 $this->flavour_repository = $this->createMock(FlavourRepository::class);
117 $this->repositories = new Repositories(
118 $this->revision_repository,
119 $this->resource_repository,
120 $this->collection_repository,
121 $this->information_repository,
122 $this->stakeholder_repository,
123 $this->flavour_repository
124 );
125 $this->locking = $this->createMock(LockHandler::class);
126 $this->stream_access = $this->createMock(StreamAccess::class);
127 $this->information = $this->createMock(Information::class);
128 $this->revision = $this->createMock(Revision::class);
129 }
130
134 protected function mockResourceAndRevision(
135 string $expected_file_name,
136 string $expected_mime_type,
137 int $expected_size,
138 int $expected_version_number,
139 int $expected_owner_id
140 ): array {
141 $identification = $this->id_generator->getUniqueResourceIdentification();
142
144 $expected_file_name,
145 $expected_mime_type,
146 $expected_size
147 );
148
149 $info_resolver = new UploadInfoResolver(
151 $expected_version_number,
152 $expected_owner_id,
153 $upload_result->getName()
154 );
155
156 // MOCKS
157 $blank_resource = new StorableFileResource($identification);
158 $this->resource_repository->expects($this->once())
159 ->method('blank')
160 ->willReturn($blank_resource);
161
162 $blank_revision = new UploadedFileRevision($blank_resource->getIdentification(), $upload_result);
163 $blank_revision->setVersionNumber($info_resolver->getNextVersionNumber());
164 $this->revision_repository->expects($this->once())
165 ->method('blankFromUpload')
166 ->with(
167 $info_resolver,
168 $blank_resource,
170 )
171 ->willReturn($blank_revision);
172 return [$upload_result, $info_resolver, $identification];
173 }
174}
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...