ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ILIAS\ResourceStorage\Flavours\FlavourTest Class Reference

Class FlavorTest. More...

+ Inheritance diagram for ILIAS\ResourceStorage\Flavours\FlavourTest:
+ Collaboration diagram for ILIAS\ResourceStorage\Flavours\FlavourTest:

Public Member Functions

 testDefinitionVariantNameLengths ()
 
 testHasFlavour ()
 
 testNewFlavour ()
 
- Public Member Functions inherited from ILIAS\ResourceStorage\AbstractTestBase
 getDummyStream ()
 

Data Fields

 $resource_builder
 

Protected Member Functions

 setUp ()
 
- Protected Member Functions inherited from ILIAS\ResourceStorage\AbstractTestBase
 setUp ()
 
 getDummyUploadResult (string $file_name, string $mime_type, int $size)
 
 getDummyFileRevision (ResourceIdentification $id)
 

Protected Attributes

 $storage_handler_factory
 
- Protected Attributes inherited from ILIAS\ResourceStorage\AbstractTestBase
ILIAS ResourceStorage DummyIDGenerator $id_generator
 
 $db_mock
 

Private Attributes

const BASE_DIR = '/var'
 
Factory $machine_factory
 
StorageHandler $storage_handler_mock
 
FlavourRepository $flavour_repo
 
StreamAccess $stream_access
 

Detailed Description

Class FlavorTest.

Author
Fabian Schmid fabia.nosp@m.n@sr.nosp@m..solu.nosp@m.tion.nosp@m.s

Definition at line 47 of file FlavourTest.php.

Member Function Documentation

◆ setUp()

ILIAS\ResourceStorage\Flavours\FlavourTest::setUp ( )
protected

Definition at line 60 of file FlavourTest.php.

60  : void
61  {
62  $this->machine_factory = new Factory(new \ILIAS\ResourceStorage\Flavour\Engine\Factory());
63  $this->storage_handler_mock = $this->createMock(StorageHandler::class);
64  $this->storage_handler_mock->expects($this->any())->method('isPrimary')->willReturn(true);
65  $this->storage_handler_factory = new StorageHandlerFactory([
66  $this->storage_handler_mock
67  ], self::BASE_DIR);
68  $this->flavour_repo = $this->createMock(FlavourRepository::class);
69  $this->resource_builder = $this->createMock(ResourceBuilder::class);
70  $this->stream_access = new StreamAccess(self::BASE_DIR, $this->storage_handler_factory);
71  }
Interface Observer Contains several chained tasks and infos about them.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

◆ testDefinitionVariantNameLengths()

ILIAS\ResourceStorage\Flavours\FlavourTest::testDefinitionVariantNameLengths ( )

Definition at line 74 of file FlavourTest.php.

References ILIAS\ResourceStorage\Flavour\Flavours\$flavour_builder, and ILIAS\ResourceStorage\Flavour\FlavourBuilder\has().

74  : void
75  {
76  $flavour_builder = new FlavourBuilder(
77  $this->flavour_repo,
78  $this->machine_factory,
79  $this->resource_builder,
80  $this->storage_handler_factory,
81  $this->stream_access,
82  new Subject()
83  );
84 
85  // Length OK
86  $flavour_definition = $this->createMock(FlavourDefinition::class);
87  $flavour_definition->expects($this->exactly(2))
88  ->method('getVariantName')
89  ->willReturn(str_repeat('a', 768));
90 
92  new ResourceIdentification('1'),
93  $flavour_definition
94  );
95  $this->assertTrue(true); // no exception thrown
96 
97  // Too long
98  $flavour_definition = $this->createMock(FlavourDefinition::class);
99  $flavour_definition->expects($this->exactly(2))
100  ->method('getVariantName')
101  ->willReturn(str_repeat('a', 769));
102 
103  $this->expectException(\InvalidArgumentException::class);
105  new ResourceIdentification('1'),
106  $flavour_definition
107  );
108  }
has(ResourceIdentification $identification, FlavourDefinition $definition)
+ Here is the call graph for this function:

◆ testHasFlavour()

ILIAS\ResourceStorage\Flavours\FlavourTest::testHasFlavour ( )

Definition at line 110 of file FlavourTest.php.

References ILIAS\ResourceStorage\Flavour\Flavours\$flavour_builder, and ILIAS\ResourceStorage\Flavour\FlavourBuilder\has().

110  : void
111  {
112  // Data
113  $rid_one = new ResourceIdentification('1');
114  $rid_two = new ResourceIdentification('2');
115  $flavour_builder = new FlavourBuilder(
116  $this->flavour_repo,
117  $this->machine_factory,
118  $this->resource_builder,
119  $this->storage_handler_factory,
120  $this->stream_access,
121  new Subject()
122  );
123 
124  // Expectations
125  $flavour_definition = $this->createMock(FlavourDefinition::class);
126  $flavour_definition->expects($this->exactly(4))
127  ->method('getVariantName')
128  ->willReturn('short');
129 
130 
131  $consecutive = [
132  [[$rid_one, 0, $flavour_definition], false],
133  [[$rid_two, 0, $flavour_definition], true],
134  ];
135  $this->flavour_repo
136  ->expects($this->exactly(2))
137  ->method('has')
138  ->willReturnCallback(
139  function ($rid, $mid, $def) use (&$consecutive) {
140  list($expected, $ret) = array_shift($consecutive);
141  $this->assertEquals($expected, [$rid, $mid, $def]);
142  return $ret;
143  }
144  );
145 
146  // Assertions
147  $this->assertFalse(
149  $rid_one,
150  $flavour_definition
151  )
152  );
153  $this->assertTrue(
155  $rid_two,
156  $flavour_definition
157  )
158  );
159  }
has(ResourceIdentification $identification, FlavourDefinition $definition)
+ Here is the call graph for this function:

◆ testNewFlavour()

ILIAS\ResourceStorage\Flavours\FlavourTest::testNewFlavour ( )

Definition at line 161 of file FlavourTest.php.

References ILIAS\ResourceStorage\Flavour\Flavours\$flavour_builder, ILIAS\ResourceStorage\Flavour\FlavourBuilder\get(), and ILIAS\Filesystem\Stream\Streams\ofString().

161  : void
162  {
163  // Data
164  $rid_one = new ResourceIdentification('1');
165  $flavour_builder = new FlavourBuilder(
166  $this->flavour_repo,
167  $this->machine_factory,
168  $this->resource_builder,
169  $this->storage_handler_factory,
170  $this->stream_access,
171  new Subject()
172  );
173 
174  // Expectations
175  $flavour_definition = $this->createMock(FlavourDefinition::class);
176  $flavour_definition->expects($this->any())
177  ->method('getVariantName')
178  ->willReturn('short');
179 
180  $this->flavour_repo->expects($this->once())
181  ->method('has')
182  ->with($rid_one, 0, $flavour_definition)
183  ->willReturn(false);
184 
185  $this->resource_builder->expects($this->exactly(1))
186  ->method('has')
187  ->with($rid_one)
188  ->willReturn(true);
189 
190  $revision = $this->createMock(FileRevision::class);
191 
192  $revision->expects($this->once())
193  ->method('getInformation')
194  ->willReturn($this->createMock(FileInformation::class));
195 
196  $stream = Streams::ofString('test');
197 
198  $resource = $this->createMock(StorableResource::class);
199 
200  $this->resource_builder->expects($this->once())
201  ->method('get')
202  ->with($rid_one)
203  ->willReturn($resource);
204 
205  $resource->expects($this->any())
206  ->method('getCurrentRevision')
207  ->willReturn($revision);
208 
209 
210  $this->resource_builder->expects($this->exactly(1))
211  ->method('extractStream')
212  ->with($revision)
213  ->willReturn($stream);
214 
215 
216  // Assertions
217  $flavour = $flavour_builder->get(
218  $rid_one,
219  $flavour_definition
220  );
221  $this->assertInstanceOf(Flavour::class, $flavour);
222  $stream_resolvers = $flavour->getStreamResolvers();
223  $this->assertCount(1, $stream_resolvers);
224  $first_stream_access = $stream_resolvers[0];
225  $this->assertInstanceOf(StreamResolver::class, $first_stream_access);
226  $resolved_stream = $first_stream_access->getStream();
227  $this->assertEquals('empty', (string) $resolved_stream);
228  }
get(ResourceIdentification $rid, FlavourDefinition $definition, bool $force_building=false)
static ofString(string $string)
Creates a new stream with an initial value.
Definition: Streams.php:41
+ Here is the call graph for this function:

Field Documentation

◆ $flavour_repo

FlavourRepository ILIAS\ResourceStorage\Flavours\FlavourTest::$flavour_repo
private

Definition at line 57 of file FlavourTest.php.

◆ $machine_factory

Factory ILIAS\ResourceStorage\Flavours\FlavourTest::$machine_factory
private

Definition at line 51 of file FlavourTest.php.

◆ $resource_builder

ILIAS\ResourceStorage\Flavours\FlavourTest::$resource_builder

Definition at line 49 of file FlavourTest.php.

◆ $storage_handler_factory

ILIAS\ResourceStorage\Flavours\FlavourTest::$storage_handler_factory
protected

Definition at line 56 of file FlavourTest.php.

◆ $storage_handler_mock

StorageHandler ILIAS\ResourceStorage\Flavours\FlavourTest::$storage_handler_mock
private

Definition at line 52 of file FlavourTest.php.

◆ $stream_access

StreamAccess ILIAS\ResourceStorage\Flavours\FlavourTest::$stream_access
private

Definition at line 58 of file FlavourTest.php.

◆ BASE_DIR

const ILIAS\ResourceStorage\Flavours\FlavourTest::BASE_DIR = '/var'
private

Definition at line 50 of file FlavourTest.php.


The documentation for this class was generated from the following file: