Mercurial > hg > isophonics-drupal-site
comparison core/modules/media/tests/src/FunctionalJavascript/MediaSourceImageTest.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\FunctionalJavascript; | |
4 | |
5 use Drupal\media\Entity\Media; | |
6 use Drupal\media\Entity\MediaType; | |
7 use Drupal\media\Plugin\media\Source\Image; | |
8 | |
9 /** | |
10 * Tests the image media source. | |
11 * | |
12 * @group media | |
13 */ | |
14 class MediaSourceImageTest extends MediaSourceTestBase { | |
15 | |
16 /** | |
17 * {@inheritdoc} | |
18 */ | |
19 protected function setUp() { | |
20 parent::setUp(); | |
21 | |
22 // We need to test without any default configuration in place. | |
23 // @TODO: Remove this as part of https://www.drupal.org/node/2883813. | |
24 MediaType::load('file')->delete(); | |
25 MediaType::load('image')->delete(); | |
26 } | |
27 | |
28 /** | |
29 * Tests the image media source. | |
30 */ | |
31 public function testMediaImageSource() { | |
32 $media_type_id = 'test_media_image_type'; | |
33 $source_field_id = 'field_media_image'; | |
34 $provided_fields = [ | |
35 Image::METADATA_ATTRIBUTE_WIDTH, | |
36 Image::METADATA_ATTRIBUTE_HEIGHT, | |
37 ]; | |
38 | |
39 $session = $this->getSession(); | |
40 $page = $session->getPage(); | |
41 $assert_session = $this->assertSession(); | |
42 | |
43 $this->doTestCreateMediaType($media_type_id, 'image', $provided_fields); | |
44 | |
45 // Create custom fields for the media type to store metadata attributes. | |
46 $fields = [ | |
47 'field_string_width' => 'string', | |
48 'field_string_height' => 'string', | |
49 ]; | |
50 $this->createMediaTypeFields($fields, $media_type_id); | |
51 | |
52 // Hide the name field widget to test default name generation. | |
53 $this->hideMediaTypeFieldWidget('name', $media_type_id); | |
54 | |
55 $this->drupalGet("admin/structure/media/manage/{$media_type_id}"); | |
56 $page->selectFieldOption("field_map[" . Image::METADATA_ATTRIBUTE_WIDTH . "]", 'field_string_width'); | |
57 $page->selectFieldOption("field_map[" . Image::METADATA_ATTRIBUTE_HEIGHT . "]", 'field_string_height'); | |
58 $page->pressButton('Save'); | |
59 | |
60 // Create a media item. | |
61 $this->drupalGet("media/add/{$media_type_id}"); | |
62 $page->attachFileToField("files[{$source_field_id}_0]", \Drupal::root() . '/core/modules/media/tests/fixtures/example_1.jpeg'); | |
63 $result = $assert_session->waitForButton('Remove'); | |
64 $this->assertNotEmpty($result); | |
65 $page->fillField("{$source_field_id}[0][alt]", 'Image Alt Text 1'); | |
66 $page->pressButton('Save'); | |
67 | |
68 $assert_session->addressEquals('media/1'); | |
69 | |
70 // Make sure the thumbnail is displayed from uploaded image. | |
71 $assert_session->elementAttributeContains('css', '.image-style-thumbnail', 'src', 'example_1.jpeg'); | |
72 | |
73 // Load the media and check that all fields are properly populated. | |
74 $media = Media::load(1); | |
75 $this->assertEquals('example_1.jpeg', $media->getName()); | |
76 $this->assertEquals('200', $media->get('field_string_width')->value); | |
77 $this->assertEquals('89', $media->get('field_string_height')->value); | |
78 } | |
79 | |
80 } |