Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Tests\media\Kernel;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\media\Entity\MediaType;
|
Chris@0
|
6
|
Chris@0
|
7 /**
|
Chris@0
|
8 * Tests the file media source.
|
Chris@0
|
9 *
|
Chris@0
|
10 * @group media
|
Chris@0
|
11 */
|
Chris@0
|
12 class MediaSourceFileTest extends MediaKernelTestBase {
|
Chris@0
|
13
|
Chris@0
|
14 /**
|
Chris@0
|
15 * {@inheritdoc}
|
Chris@0
|
16 */
|
Chris@0
|
17 protected function setUp() {
|
Chris@0
|
18 parent::setUp();
|
Chris@0
|
19
|
Chris@0
|
20 // We need to test without any default configuration in place.
|
Chris@0
|
21 // @TODO: Remove this as part of https://www.drupal.org/node/2883813.
|
Chris@0
|
22 MediaType::load('file')->delete();
|
Chris@0
|
23 MediaType::load('image')->delete();
|
Chris@0
|
24 }
|
Chris@0
|
25
|
Chris@0
|
26 /**
|
Chris@0
|
27 * Tests the file extension constraint.
|
Chris@0
|
28 */
|
Chris@0
|
29 public function testFileExtensionConstraint() {
|
Chris@0
|
30 $mediaType = $this->createMediaType('file');
|
Chris@0
|
31 // Create a random file that should fail.
|
Chris@0
|
32 $media = $this->generateMedia('test.patch', $mediaType);
|
Chris@0
|
33 $result = $media->validate();
|
Chris@0
|
34 $this->assertCount(1, $result);
|
Chris@0
|
35 $this->assertEquals('field_media_file.0', $result->get(0)->getPropertyPath());
|
Chris@0
|
36 $this->assertContains('Only files with the following extensions are allowed:', (string) $result->get(0)->getMessage());
|
Chris@0
|
37
|
Chris@0
|
38 // Create a random file that should pass.
|
Chris@0
|
39 $media = $this->generateMedia('test.txt', $mediaType);
|
Chris@0
|
40 $result = $media->validate();
|
Chris@0
|
41 $this->assertCount(0, $result);
|
Chris@0
|
42 }
|
Chris@0
|
43
|
Chris@0
|
44 }
|