Completed
Push — feature/EVO-8294-fileUpload ( 7382a6...32a770 )
by Narcotic
14:39
created

testIllegalMimeTypeModificationHandling()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 48
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 48
rs 9.125
cc 1
eloc 26
nc 1
nop 0
1
<?php
2
/**
3
 * functional test for /file
4
 */
5
6
namespace Graviton\FileBundle\Tests\Controller;
7
8
use Graviton\TestBundle\Test\RestTestCase;
9
use Symfony\Component\HttpFoundation\File\UploadedFile;
10
use Symfony\Component\HttpFoundation\Response;
11
12
/**
13
 * Basic functional test for /file
14
 *
15
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
16
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
17
 * @link     http://swisscom.ch
18
 */
19
class FileControllerTest extends RestTestCase
20
{
21
    /**
22
     * @const complete content type string expected on a resource
23
     */
24
    const CONTENT_TYPE = 'application/json; charset=UTF-8; profile=http://localhost/schema/file/item';
25
26
    /**
27
     * @const corresponding vendorized schema mime type
28
     */
29
    const COLLECTION_TYPE = 'application/json; charset=UTF-8; profile=http://localhost/schema/file/collection';
30
31
    /**
32
     * setup client and load fixtures
33
     *
34
     * @return void
35
     */
36
    public function setUp()
37
    {
38
        $this->loadFixtures(
39
            array(
40
                'GravitonDyn\FileBundle\DataFixtures\MongoDB\LoadFileData'
41
            ),
42
            null,
43
            'doctrine_mongodb'
44
        );
45
    }
46
47
    /**
48
     * check for empty collections when no fixtures are loaded
49
     *
50
     * @return void
51
     */
52 View Code Duplication
    public function testFindAllEmptyCollection()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
53
    {
54
        // reset fixtures since we already have some from setUp
55
        $this->loadFixtures(array(), null, 'doctrine_mongodb');
56
        $client = static::createRestClient();
57
        $client->request('GET', '/file/');
58
59
        $response = $client->getResponse();
60
        $results = $client->getResults();
61
62
        $this->assertResponseContentType(self::COLLECTION_TYPE, $response);
63
64
        $this->assertEquals(array(), $results);
65
    }
66
67
    /**
68
     * validate that we can post a new file
69
     *
70
     * @return void
71
     */
72
    public function testPostAndUpdateFile()
73
    {
74
        $fixtureData = file_get_contents(__DIR__.'/fixtures/test.txt');
75
        $fileHash = hash('sha256', $fixtureData);
76
        $fileHashCustom = 'some-custom-hash-for-testing';
77
78
        $client = static::createRestClient();
79
        $client->post(
80
            '/file/',
81
            $fixtureData,
82
            [],
83
            [],
84
            ['CONTENT_TYPE' => 'text/plain'],
85
            false
86
        );
87
        $this->assertEmpty($client->getResults());
88
        $response = $client->getResponse();
89
        $this->assertEquals(201, $response->getStatusCode());
90
91
        $fileLocation = $response->headers->get('Location');
92
93
        // update file contents to update mod date
94
        $client = static::createRestClient();
95
        $client->put(
96
            $fileLocation,
97
            $fixtureData,
98
            [],
99
            [],
100
            ['CONTENT_TYPE' => 'text/plain'],
101
            false
102
        );
103
        $this->assertEmpty($client->getResults(), $client->getResponse()->getContent());
104
        $response = $client->getResponse();
105
        $this->assertEquals(204, $response->getStatusCode());
106
107
        $client = static::createRestClient();
108
        $client->request('GET', $fileLocation);
109
        $data = $client->getResults();
110
111
        // check for valid format
112
        $this->assertNotFalse(\DateTime::createFromFormat(\DateTime::RFC3339, $data->metadata->createDate));
113
        $this->assertNotFalse(\DateTime::createFromFormat(\DateTime::RFC3339, $data->metadata->modificationDate));
114
        // Check valid hash encoding if no hash sent
115
        $this->assertEquals($fileHash, $data->metadata->hash);
116
117
        $data->links = [];
118
        $link = new \stdClass;
119
        $link->{'$ref'} = 'http://localhost/core/app/tablet';
120
        $data->links[] = $link;
121
122
        $filename = "test.txt";
123
        $data->metadata->filename = $filename;
124
        $data->metadata->hash = $fileHashCustom;
125
126
        $client = static::createRestClient();
127
        $client->put(sprintf('/file/%s', $data->id), $data);
128
129
        // re-fetch
130
        $client = static::createRestClient();
131
        $client->request('GET', sprintf('/file/%s', $data->id));
132
        $results = $client->getResults();
133
134
        $this->assertEquals($link->{'$ref'}, $results->links[0]->{'$ref'});
135
        $this->assertEquals($filename, $results->metadata->filename);
136
        $this->assertEquals($fileHashCustom, $data->metadata->hash);
137
138
        $client = static::createClient();
139
        $client->request('GET', sprintf('/file/%s', $data->id), [], [], ['HTTP_ACCEPT' => 'text/plain']);
140
141
        $results = $client->getResponse()->getContent();
142
143
        $this->assertEquals($fixtureData, $results);
144
145
        // change link and add second link
146
        $data->links[0]->{'$ref'} = 'http://localhost/core/app/admin';
147
        $link = new \stdClass;
148
        $link->{'$ref'} = 'http://localhost/core/app/web';
149
        $data->links[] = $link;
150
151
        // also add action command
152
        $command = new \stdClass();
153
        $command->command = 'print';
154
        $data->metadata->action = [$command];
155
156
        // also add additionalInformation
157
        $data->metadata->additionalInformation = 'someInfo';
158
159
        $client = static::createRestClient();
160
        $client->put(sprintf('/file/%s', $data->id), $data);
161
162
        // re-fetch
163
        $client = static::createRestClient();
164
        $client->request('GET', sprintf('/file/%s', $data->id));
165
        $results = $client->getResults();
166
167
        $this->assertEquals($data->links[0]->{'$ref'}, $results->links[0]->{'$ref'});
168
        $this->assertEquals($data->links[1]->{'$ref'}, $results->links[1]->{'$ref'});
169
170
        // check metadata
171
        $this->assertEquals(18, $data->metadata->size);
172
        $this->assertEquals('text/plain', $data->metadata->mime);
173
        $this->assertEquals('test.txt', $data->metadata->filename);
174
        $this->assertEquals('print', $data->metadata->action[0]->command);
175
        $this->assertEquals('someInfo', $data->metadata->additionalInformation);
176
        $this->assertNotNull($data->metadata->createDate);
177
        $this->assertNotNull($data->metadata->modificationDate);
178
179
        // remove a link
180
        unset($data->links[1]);
181
182
        $client = static::createRestClient();
183
        $client->put(sprintf('/file/%s', $data->id), $data);
184
        // re-fetch
185
        $client = static::createRestClient();
186
        $client->request('GET', sprintf('/file/%s', $data->id));
187
        $results = $client->getResults();
188
189
        $this->assertEquals($data->links[0]->{'$ref'}, $results->links[0]->{'$ref'});
190
        $this->assertCount(1, $results->links);
191
192
        // remove last link
193
        $data->links = [];
194
        $client = static::createRestClient();
195
        $client->put(sprintf('/file/%s', $data->id), $data);
196
197
        // re-fetch
198
        $client = static::createRestClient();
199
        $client->request('GET', sprintf('/file/%s', $data->id));
200
201
        $results = $client->getResults();
202
203
        $this->assertEmpty($results->links);
204
    }
205
206
    /**
207
     * validate that we can post a new file
208
     *
209
     * @return void
210
     */
211 View Code Duplication
    public function testPostNewFile()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
212
    {
213
        $client = static::createRestClient();
214
215
        $client->post(
216
            '/file',
217
            file_get_contents(__DIR__.'/fixtures/test.txt'),
218
            [],
219
            [],
220
            ['CONTENT_TYPE' => 'text/plain'],
221
            false
222
        );
223
224
        $response = $client->getResponse();
225
        $linkHeader = $response->headers->get('Link');
226
227
        $this->assertEquals(201, $response->getStatusCode());
228
        $this->assertRegExp('@/file/[a-z0-9]{32}>; rel="self"@', $linkHeader);
229
    }
230
231
    /**
232
     * validate that we can put a new file with a custom id
233
     *
234
     * @return void
235
     */
236 View Code Duplication
    public function testPutNewFile()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
237
    {
238
        $client = static::createRestClient();
239
240
        $client->put(
241
            '/file/testPutNewFile',
242
            file_get_contents(__DIR__ . '/fixtures/test.txt'),
243
            [],
244
            [],
245
            ['CONTENT_TYPE' => 'text/plain'],
246
            false
247
        );
248
249
        $response = $client->getResponse();
250
        $linkHeader = $response->headers->get('Link');
251
252
        $this->assertEquals(204, $response->getStatusCode());
253
        $this->assertContains('file/testPutNewFile>; rel="self"', $linkHeader);
254
    }
255
256
    /**
257
     * validate that we can delete a file
258
     *
259
     * @return void
260
     */
261
    public function testDeleteFile()
262
    {
263
        $fixtureData = file_get_contents(__DIR__.'/fixtures/test.txt');
264
        $client = static::createRestClient();
265
        $client->post(
266
            '/file/',
267
            $fixtureData,
268
            [],
269
            [],
270
            ['CONTENT_TYPE' => 'text/plain'],
271
            false
272
        );
273
        $response = $client->getResponse();
274
        $this->assertEquals(201, $response->getStatusCode());
275
276
        // re-fetch
277
        $client = static::createRestClient();
278
        $client->request('GET', $response->headers->get('Location'));
279
        $data = $client->getResults();
280
281
        $client = static::createRestClient();
282
        $client->request('DELETE', sprintf('/file/%s', $data->id));
283
284
        $client = static::createRestClient();
285
        $client->request('GET', sprintf('/file/%s', $data->id));
286
287
        $response = $client->getResponse();
288
        $this->assertEquals(404, $response->getStatusCode());
289
    }
290
291
    /**
292
     * validate that we can update the content from a file
293
     *
294
     * @return void
295
     */
296
    public function testUpdateFileContent()
297
    {
298
        $fixtureData = file_get_contents(__DIR__.'/fixtures/test.txt');
299
        $contentType = 'text/plain';
300
        $newData = "This is a new text!!!";
301
        $client = static::createRestClient();
302
        $client->post(
303
            '/file/',
304
            $fixtureData,
305
            [],
306
            [],
307
            ['CONTENT_TYPE' => $contentType],
308
            false
309
        );
310
        $response = $client->getResponse();
311
        $this->assertEquals(201, $response->getStatusCode());
312
313
        $linkHeader = $response->headers->get('Link');
314
        $this->assertRegExp('@/file/[a-z0-9]{32}>; rel="self"@', $linkHeader);
315
316
        // re-fetch
317
        $client = static::createRestClient();
318
        $client->request('GET', $response->headers->get('Location'));
319
        $retData = $client->getResults();
320
321
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
322
        $this->assertEquals(strlen($fixtureData), $retData->metadata->size);
323
        $this->assertEquals($contentType, $retData->metadata->mime);
324
325
        $this->updateFileContent($retData->id, $newData, $contentType);
326
    }
327
328
    /**
329
     * post a file without any mime type.. check if that mime type is correctly determined.
330
     * fetch content back and compare the contents of the file
331
     *
332
     * @return void
333
     */
334
    public function testPostFileContentMimeDetectionAndContent()
335
    {
336
        $testData = file_get_contents(__DIR__.'/resources/testpicture.jpg');
337
        $contentType = 'image/jpeg';
338
        $client = static::createRestClient();
339
340
        $client->post(
341
            '/file/',
342
            $testData,
343
            [],
344
            [],
345
            [],
346
            false
347
        );
348
        $response = $client->getResponse();
349
        $this->assertEquals(201, $response->getStatusCode());
350
351
        $linkHeader = $response->headers->get('Link');
352
        $this->assertRegExp('@/file/[a-z0-9]{32}>; rel="self"@', $linkHeader);
353
354
        // re-fetch
355
        $client = static::createRestClient();
356
        $client->request('GET', $response->headers->get('Location'));
357
        $retData = $client->getResults();
358
359
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
360
        $this->assertEquals($contentType, $retData->metadata->mime);
361
362
        /** we use the standard client as we don't want to have json forced */
363
        $client = static::createClient();
364
        $client->request(
365
            'GET',
366
            $response->headers->get('Location'),
367
            [],
368
            [],
369
            ['ACCEPT' => $contentType]
370
        );
371
372
        $response = $client->getInternalResponse();
373
374
        $this->assertTrue(($response->getContent() === $testData));
375
    }
376
377
    /**
378
     * here we PUT a file, then try to update the mimetype in the metadata
379
     * to 'something/other' and see if we can still GET it and receive the correct mime type
380
     * (meaning we were not able to modify the mime type)
381
     *
382
     * @return void
383
     */
384
    public function testIllegalMimeTypeModificationHandling()
385
    {
386
        $fileData = "This is a new text!!!";
387
        $contentType = 'text/plain';
388
389
        $client = static::createRestClient();
390
        $client->put(
391
            '/file/mimefile',
392
            $fileData,
393
            [],
394
            [],
395
            [],
396
            [],
0 ignored issues
show
Documentation introduced by
array() is of type array, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
397
            false
0 ignored issues
show
Unused Code introduced by
The call to Client::put() has too many arguments starting with false.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
398
        );
399
        $response = $client->getResponse();
400
        $this->assertEquals(Response::HTTP_NO_CONTENT, $response->getStatusCode());
401
402
        // GET the metadata
403
        $client = static::createRestClient();
404
        $client->request('GET', '/file/mimefile');
405
        $retData = $client->getResults();
406
407
        $this->assertEquals($retData->metadata->mime, $contentType);
408
409
        // change metadata and save
410
        $retData->metadata->mime = 'something/other';
411
412
        $client = static::createRestClient();
413
        $client->put('/file/mimefile', $retData);
414
415
        $client = static::createClient();
416
        $client->request(
417
            'GET',
418
            '/file/mimefile',
419
            [],
420
            [],
421
            ['ACCEPT' => '*/*']
422
        );
423
424
        $response = $client->getInternalResponse();
425
426
        // still the good one?
427
        $this->assertContains($contentType, $response->getHeader('content-type'));
428
429
        $client = static::createRestClient();
430
        $client->request('DELETE', '/file/mimefile');
431
    }
432
433
    /**
434
     * test getting collection schema
435
     *
436
     * @return void
437
     */
438
    public function testGetFileCollectionSchemaInformation()
439
    {
440
        $client = static::createRestClient();
441
442
        $client->request('GET', '/schema/file/collection');
443
444
        $response = $client->getResponse();
445
        $results = $client->getResults();
446
447
        $this->assertResponseContentType('application/schema+json', $response);
448
        $this->assertEquals(200, $response->getStatusCode());
449
450
        $this->assertEquals('Array of file objects', $results->title);
451
        $this->assertEquals('array', $results->type);
452
        $this->assertIsFileSchema($results->items);
453
454
        $this->assertCorsHeaders('GET, POST, PUT, PATCH, DELETE, OPTIONS', $response);
455
        $this->assertContains(
456
            'Link',
457
            explode(',', $response->headers->get('Access-Control-Expose-Headers'))
458
        );
459
460
        $this->assertContains(
461
            '<http://localhost/schema/file/collection>; rel="self"',
462
            explode(',', $response->headers->get('Link'))
463
        );
464
    }
465
466
    /**
467
     * test behavior when data sent was multipart/form-data
468
     *
469
     * @return void
470
     */
471
    public function testPutNewFileViaForm()
472
    {
473
        copy(__DIR__ . '/fixtures/test.txt', sys_get_temp_dir() . '/test.txt');
474
        $file = sys_get_temp_dir() . '/test.txt';
475
        $uploadedFile = new UploadedFile($file, 'test.txt', 'text/plain', 15);
476
477
        $jsonData = '{
478
          "id": "myPersonalFile",
479
          "links": [
480
            {
481
              "$ref": "http://localhost/testcase/readonly/101",
482
              "type": "owner"
483
            },
484
            {
485
              "$ref": "http://localhost/testcase/readonly/102",
486
              "type": "module"
487
            }
488
          ],
489
          "metadata": {
490
            "action":[{"command":"print"},{"command":"archive"}],
491
            "additionalInformation": "someInfo",
492
            "additionalProperties": [
493
                {"name": "testName", "value": "testValue"},
494
                {"name": "testName2", "value": "testValue2"}
495
            ],
496
            "filename": "customFileName"
497
          }
498
        }';
499
500
        $client = static::createRestClient();
501
        $client->put(
502
            '/file/myPersonalFile',
503
            [],
504
            [
505
                'metadata' => $jsonData,
506
            ],
507
            [
508
                'upload' => $uploadedFile,
509
            ],
510
            [],
511
            false
512
        );
513
514
        $response = $client->getResponse();
515
516
        $this->assertEquals(Response::HTTP_NO_CONTENT, $response->getStatusCode());
517
        $this->assertNotContains('location', $response->headers->all());
518
519
        $response = $this->updateFileContent('myPersonalFile', "This is a new text!!!");
520
521
        $metaData = json_decode($jsonData, true);
522
        $returnData = json_decode($response->getContent(), true);
523
524
        $this->assertEquals($metaData['links'], $returnData['links']);
525
        $this->assertEquals($metaData['metadata']['action'], $returnData['metadata']['action']);
526
        $this->assertEquals(
527
            $metaData['metadata']['additionalInformation'],
528
            $returnData['metadata']['additionalInformation']
529
        );
530
        $this->assertEquals(
531
            $metaData['metadata']['additionalProperties'],
532
            $returnData['metadata']['additionalProperties']
533
        );
534
        $this->assertCount(2, $returnData['metadata']['additionalProperties']);
535
        $this->assertEquals($metaData['metadata']['filename'], $returnData['metadata']['filename']);
536
537
        // clean up
538
        $client = $this->createClient();
539
        $client->request(
540
            'DELETE',
541
            '/file/myPersonalFile'
542
        );
543
    }
544
545
    /**
546
     * check if a schema is of the file type
547
     *
548
     * @param \stdClass $schema schema from service to validate
549
     *
550
     * @return void
551
     */
552
    private function assertIsFileSchema(\stdClass $schema)
553
    {
554
        $this->assertEquals('File', $schema->title);
555
        $this->assertEquals('File storage service', $schema->description);
556
        $this->assertEquals('object', $schema->type);
557
558
        $this->assertEquals('string', $schema->properties->id->type);
559
        $this->assertEquals('ID', $schema->properties->id->title);
560
        $this->assertEquals('Unique identifier', $schema->properties->id->description);
561
        $this->assertObjectNotHasAttribute('readOnly', $schema->properties->id);
562
563
        // Metadata
564
        $this->assertEquals('object', $schema->properties->metadata->type);
565
        $this->assertEquals('Metadata', $schema->properties->metadata->title);
566
        $this->assertObjectNotHasAttribute('readOnly', $schema->properties->metadata);
567
568
        // Metadata size
569
        $this->assertEquals('integer', $schema->properties->metadata->properties->size->type);
570
        $this->assertEquals('File size', $schema->properties->metadata->properties->size->title);
571
        $this->assertEquals('Size of file.', $schema->properties->metadata->properties->size->description);
572
573
        // Metadata mime
574
        $this->assertContains('string', $schema->properties->metadata->properties->mime->type);
575
        $this->assertEquals('MIME Type', $schema->properties->metadata->properties->mime->title);
576
        $this->assertEquals('MIME-Type of file.', $schema->properties->metadata->properties->mime->description);
577
578
        // Metadata createDate
579
        $this->assertEquals(['string', 'null'], $schema->properties->metadata->properties->createDate->type);
580
        $this->assertEquals('date-time', $schema->properties->metadata->properties->createDate->format);
581
        $this->assertEquals('Creation date', $schema->properties->metadata->properties->createDate->title);
582
        $this->assertEquals(
583
            'Timestamp of file upload.',
584
            $schema->properties->metadata->properties->createDate->description
585
        );
586
587
        // Metadata modificationDate
588
        $this->assertEquals(['string', 'null'], $schema->properties->metadata->properties->modificationDate->type);
589
        $this->assertEquals('date-time', $schema->properties->metadata->properties->modificationDate->format);
590
        $this->assertEquals('Modification date', $schema->properties->metadata->properties->modificationDate->title);
591
        $this->assertEquals(
592
            'Timestamp of the last file change.',
593
            $schema->properties->metadata->properties->modificationDate->description
594
        );
595
596
        // Metadata filename
597
        $this->assertContains('string', $schema->properties->metadata->properties->filename->type);
598
        $this->assertEquals('File name', $schema->properties->metadata->properties->filename->title);
599
        $this->assertEquals(
600
            'Name of the file as it should get displayed to the user.',
601
            $schema->properties->metadata->properties->filename->description
602
        );
603
        $this->assertObjectNotHasAttribute('readOnly', $schema->properties->metadata->properties->filename);
604
605
        // metadata action.command array
606
        $this->assertContains(
607
            'string',
608
            $schema->properties->metadata->properties->action->items->properties->command->type
609
        );
610
        $this->assertEquals(
611
            'Action command array',
612
            $schema->properties->metadata->properties->action->items->properties->command->title
613
        );
614
        $this->assertObjectNotHasAttribute(
615
            'readOnly',
616
            $schema->properties->metadata->properties->action->items->properties->command
617
        );
618
619
        // metadata additionalInformation
620
        $this->assertContains(
621
            'string',
622
            $schema->properties->metadata->properties->additionalInformation->type
623
        );
624
        $this->assertEquals(
625
            'Additional Information',
626
            $schema->properties->metadata->properties->additionalInformation->title
627
        );
628
        $this->assertObjectNotHasAttribute(
629
            'readOnly',
630
            $schema->properties->metadata->properties->additionalInformation
631
        );
632
633
        // metadata additionalProperties
634
        $additionalPropertiesSchema = $schema->properties->metadata->properties->additionalProperties;
635
        $this->assertEquals('array', $additionalPropertiesSchema->type);
636
        $this->assertEquals('object', $additionalPropertiesSchema->items->type);
637
        $this->assertEquals('string', $additionalPropertiesSchema->items->properties->name->type);
638
        $this->assertEquals('property name', $additionalPropertiesSchema->items->properties->name->title);
639
        $this->assertEquals('string', $additionalPropertiesSchema->items->properties->value->type);
640
        $this->assertEquals('property value', $additionalPropertiesSchema->items->properties->value->title);
641
642
        // Links
643
        $this->assertEquals('array', $schema->properties->links->type);
644
        $this->assertEquals('many', $schema->properties->links->format);
645
        $this->assertEquals('links', $schema->properties->links->title);
646
        $this->assertEquals('@todo replace me', $schema->properties->links->description);
647
        $this->assertObjectNotHasAttribute('readOnly', $schema->properties->links);
648
649
650
        // Links items
651
        $this->assertEquals('object', $schema->properties->links->items->type);
652
        $this->assertEquals('Links', $schema->properties->links->items->title);
653
        $this->assertObjectNotHasAttribute('readOnly', $schema->properties->links->items);
654
655
656
        // Links item type
657
        $this->assertContains('string', $schema->properties->links->items->properties->type->type);
658
        $this->assertEquals('Type', $schema->properties->links->items->properties->type->title);
659
        $this->assertEquals('Type of the link.', $schema->properties->links->items->properties->type->description);
660
        $this->assertObjectNotHasAttribute('readOnly', $schema->properties->links->items->properties->type);
661
662
        // Links item $ref
663
        $this->assertEquals(['string', 'null'], $schema->properties->links->items->properties->{'$ref'}->type);
664
        $this->assertEquals('extref', $schema->properties->links->items->properties->{'$ref'}->format);
665
        $this->assertEquals('Link', $schema->properties->links->items->properties->{'$ref'}->title);
666
        $this->assertEquals(
667
            'Link to any document.',
668
            $schema->properties->links->items->properties->{'$ref'}->description
669
        );
670
        $this->assertEquals(
671
            ['*'],
672
            $schema->properties->links->items->properties->{'$ref'}->{'x-collection'}
673
        );
674
675
        $this->assertEquals(
676
            [
677
                'document.file.file.update',
678
                'document.file.file.create',
679
                'document.file.file.delete'
680
            ],
681
            $schema->{'x-events'}
682
        );
683
684
        $this->assertObjectNotHasAttribute('readOnly', $schema->properties->links->items->properties->{'$ref'});
685
    }
686
687
    /**
688
     * Verifies the update of a file content.
689
     *
690
     * @param string $fileId      identifier of the file to be updated
691
     * @param string $newContent  new content to be stored in the file
692
     * @param string $contentType Content-Type of the file
693
     *
694
     * @return null|Response
0 ignored issues
show
Documentation introduced by
Should the return type not be object|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
695
     */
696
    private function updateFileContent($fileId, $newContent, $contentType = 'text/plain')
697
    {
698
        $client = static::createRestClient();
699
        $client->put(
700
            sprintf('/file/%s', $fileId),
701
            $newContent,
702
            [],
703
            [],
704
            ['CONTENT_TYPE' => $contentType],
705
            false
706
        );
707
708
        $client = static::createRestClient();
709
        $client->request('GET', sprintf('/file/%s', $fileId));
710
711
        $retData = $client->getResults();
712
        $response = $client->getResponse();
713
        $this->assertEquals(200, $response->getStatusCode());
714
        $this->assertEquals($contentType, $retData->metadata->mime);
715
716
        return $response;
717
    }
718
}
719