ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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\AbstractBaseTest
 getDummyStream ()
 

Data Fields

 $resource_builder
 

Protected Member Functions

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

Protected Attributes

 $storage_handler_factory
 
- Protected Attributes inherited from ILIAS\ResourceStorage\AbstractBaseTest
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  }
Class ChatMainBarProvider .
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  $this->flavour_repo->expects($this->exactly(2))
131  ->method('has')
132  ->withConsecutive([$rid_one, 0, $flavour_definition], [$rid_two, 0, $flavour_definition])
133  ->willReturnOnConsecutiveCalls(false, true);
134 
135 
136  // Assertions
137  $this->assertFalse(
139  $rid_one,
140  $flavour_definition
141  )
142  );
143  $this->assertTrue(
145  $rid_two,
146  $flavour_definition
147  )
148  );
149  }
has(ResourceIdentification $identification, FlavourDefinition $definition)
+ Here is the call graph for this function:

◆ testNewFlavour()

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

Definition at line 151 of file FlavourTest.php.

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

151  : void
152  {
153  // Data
154  $rid_one = new ResourceIdentification('1');
155  $flavour_builder = new FlavourBuilder(
156  $this->flavour_repo,
157  $this->machine_factory,
158  $this->resource_builder,
159  $this->storage_handler_factory,
160  $this->stream_access,
161  new Subject()
162  );
163 
164  // Expectations
165  $flavour_definition = $this->createMock(FlavourDefinition::class);
166  $flavour_definition->expects($this->any())
167  ->method('getVariantName')
168  ->willReturn('short');
169 
170  $this->flavour_repo->expects($this->once())
171  ->method('has')
172  ->with($rid_one, 0, $flavour_definition)
173  ->willReturn(false);
174 
175  $this->resource_builder->expects($this->exactly(1))
176  ->method('has')
177  ->with($rid_one)
178  ->willReturn(true);
179 
180  $revision = $this->createMock(FileRevision::class);
181 
182  $revision->expects($this->once())
183  ->method('getInformation')
184  ->willReturn($this->createMock(FileInformation::class));
185 
186  $stream = Streams::ofString('test');
187 
188  $resource = $this->createMock(StorableResource::class);
189 
190  $this->resource_builder->expects($this->once())
191  ->method('get')
192  ->with($rid_one)
193  ->willReturn($resource);
194 
195  $resource->expects($this->any())
196  ->method('getCurrentRevision')
197  ->willReturn($revision);
198 
199 
200  $this->resource_builder->expects($this->exactly(1))
201  ->method('extractStream')
202  ->with($revision)
203  ->willReturn($stream);
204 
205 
206  // Assertions
207  $flavour = $flavour_builder->get(
208  $rid_one,
209  $flavour_definition
210  );
211  $this->assertInstanceOf(Flavour::class, $flavour);
212  $stream_resolvers = $flavour->getStreamResolvers();
213  $this->assertCount(1, $stream_resolvers);
214  $first_stream_access = $stream_resolvers[0];
215  $this->assertInstanceOf(StreamResolver::class, $first_stream_access);
216  $resolved_stream = $first_stream_access->getStream();
217  $this->assertEquals('empty', (string) $resolved_stream);
218  }
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: