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