ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
FlavourTest.php
Go to the documentation of this file.
1 <?php
2 
20 
40 
45 require_once __DIR__ . '/../AbstractBaseTest.php';
46 
48 {
50  private const BASE_DIR = '/var';
59 
60  protected function setUp(): 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  }
72 
73 
74  public function testDefinitionVariantNameLengths(): void
75  {
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  }
109 
110  public function testHasFlavour(): void
111  {
112  // Data
113  $rid_one = new ResourceIdentification('1');
114  $rid_two = new ResourceIdentification('2');
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  }
150 
151  public function testNewFlavour(): void
152  {
153  // Data
154  $rid_one = new ResourceIdentification('1');
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  }
219 }
Token
The string representation of these tokens must not occur in the names of metadata elements...
Definition: Token.php:27
get(ResourceIdentification $rid, FlavourDefinition $definition, bool $force_building=false)
Class ChatMainBarProvider .
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
has(ResourceIdentification $identification, FlavourDefinition $definition)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static ofString(string $string)
Creates a new stream with an initial value.
Definition: Streams.php:41