Completed
Pull Request — 8.x-1.x (#10)
by Vijay
02:15
created
src/Tests/VideoBundleTest.php 1 patch
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -10,65 +10,65 @@  discard block
 block discarded – undo
10 10
  * @group media
11 11
  */
12 12
 class VideoBundleTest extends WebTestBase {
13
-  /**
14
-   * Exempt from strict schema checking.
15
-   *
16
-   * @see \Drupal\Core\Config\Testing\ConfigSchemaChecker
17
-   *
18
-   * @var bool
19
-   */
20
-  protected $strictConfigSchema = FALSE;
13
+    /**
14
+     * Exempt from strict schema checking.
15
+     *
16
+     * @see \Drupal\Core\Config\Testing\ConfigSchemaChecker
17
+     *
18
+     * @var bool
19
+     */
20
+    protected $strictConfigSchema = FALSE;
21 21
 
22
-  /**
23
-   * Modules to enable.
24
-   *
25
-   * @var array
26
-   */
27
-  public static $modules = [
22
+    /**
23
+     * Modules to enable.
24
+     *
25
+     * @var array
26
+     */
27
+    public static $modules = [
28 28
     'media',
29 29
     'media_entity',
30 30
     'video_embed_field',
31 31
     'video_embed_media',
32 32
     'node',
33
-  ];
33
+    ];
34 34
 
35
-  /**
36
-   * The test media bundle.
37
-   *
38
-   * @var \Drupal\media_entity\MediaBundleInterface
39
-   */
40
-  protected $testBundle;
35
+    /**
36
+     * The test media bundle.
37
+     *
38
+     * @var \Drupal\media_entity\MediaBundleInterface
39
+     */
40
+    protected $testBundle;
41 41
 
42
-  /**
43
-   * {@inheritdoc}
44
-   */
45
-  protected function setUp() {
42
+    /**
43
+     * {@inheritdoc}
44
+     */
45
+    protected function setUp() {
46 46
     parent::setUp();
47 47
     $this->testBundle = $this->container->get('entity.manager')->getStorage('media_bundle')->load('video');
48 48
 
49 49
     $adminUser = $this->drupalCreateUser([
50
-      'view media',
51
-      'create media',
52
-      'update media',
53
-      'update any media',
54
-      'delete media',
55
-      'delete any media',
56
-      'access media overview',
50
+        'view media',
51
+        'create media',
52
+        'update media',
53
+        'update any media',
54
+        'delete media',
55
+        'delete any media',
56
+        'access media overview',
57 57
     ]);
58 58
     $this->drupalLogin($adminUser);
59
-  }
59
+    }
60 60
 
61
-  /**
62
-   * Tests video media bundle creation from config files.
63
-   */
64
-  public function testMediaBundleCreationFromModule() {
61
+    /**
62
+     * Tests video media bundle creation from config files.
63
+     */
64
+    public function testMediaBundleCreationFromModule() {
65 65
     $type_configuration = [
66
-      'source_field' => 'field_video',
66
+        'source_field' => 'field_video',
67 67
     ];
68 68
 
69 69
     $field_map = [
70
-      'id' => 'field_id',
71
-      'source_name' => 'field_source',
70
+        'id' => 'field_id',
71
+        'source_name' => 'field_source',
72 72
     ];
73 73
 
74 74
     $this->assertTrue((bool) $this->testBundle, 'The media bundle from default configuration has been created in the database.');
@@ -77,15 +77,15 @@  discard block
 block discarded – undo
77 77
     $this->assertEqual($this->testBundle->get('type'), 'video_embed_field', 'Correct plugin ID detected.');
78 78
     $this->assertEqual($this->testBundle->get('type_configuration'), $type_configuration, 'Type configuration correct.');
79 79
     $this->assertEqual($this->testBundle->get('field_map'), $field_map, 'Correct field map detected.');
80
-  }
80
+    }
81 81
 
82
-  /**
83
-   * Tests video media bundle field maps.
84
-   */
85
-  public function testBundleFieldMap() {
82
+    /**
83
+     * Tests video media bundle field maps.
84
+     */
85
+    public function testBundleFieldMap() {
86 86
     $edit = [
87
-      'name[0][value]' => 'Drupal video!',
88
-      'field_video[0][value]' => 'https://www.youtube.com/watch?v=XgYu7-DQjDQ',
87
+        'name[0][value]' => 'Drupal video!',
88
+        'field_video[0][value]' => 'https://www.youtube.com/watch?v=XgYu7-DQjDQ',
89 89
     ];
90 90
     $this->drupalPostForm('media/add/' . $this->testBundle->id(), $edit, t('Save and publish'));
91 91
 
@@ -94,11 +94,11 @@  discard block
 block discarded – undo
94 94
     $media_id = reset($media_id);
95 95
     /** @var \Drupal\media_entity\MediaInterface $media */
96 96
     $media = $this->container->get('entity_type.manager')
97
-      ->getStorage('media')
98
-      ->loadUnchanged($media_id);
97
+        ->getStorage('media')
98
+        ->loadUnchanged($media_id);
99 99
     $properties = $media->toArray();
100 100
     $this->assertEqual($properties['field_id'][0]['value'], 'XgYu7-DQjDQ', 'Correct video ID detected.');
101 101
     $this->assertEqual($properties['field_source'][0]['value'], 'youtube', 'Correct video source detected.');
102
-  }
102
+    }
103 103
 
104 104
 }
Please login to merge, or discard this patch.
src/Tests/ImageBundleTest.php 1 patch
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -10,61 +10,61 @@  discard block
 block discarded – undo
10 10
  * @group media
11 11
  */
12 12
 class ImageBundleTest extends WebTestBase {
13
-  /**
14
-   * Exempt from strict schema checking.
15
-   *
16
-   * @see \Drupal\Core\Config\Testing\ConfigSchemaChecker
17
-   *
18
-   * @var bool
19
-   */
20
-  protected $strictConfigSchema = FALSE;
13
+    /**
14
+     * Exempt from strict schema checking.
15
+     *
16
+     * @see \Drupal\Core\Config\Testing\ConfigSchemaChecker
17
+     *
18
+     * @var bool
19
+     */
20
+    protected $strictConfigSchema = FALSE;
21 21
 
22
-  /**
23
-   * Modules to enable.
24
-   *
25
-   * @var array
26
-   */
27
-  public static $modules = [
22
+    /**
23
+     * Modules to enable.
24
+     *
25
+     * @var array
26
+     */
27
+    public static $modules = [
28 28
     'media',
29 29
     'media_entity',
30 30
     'media_entity_image',
31 31
     'image',
32 32
     'node',
33
-  ];
33
+    ];
34 34
 
35
-  /**
36
-   * The test media bundle.
37
-   *
38
-   * @var \Drupal\media_entity\MediaBundleInterface
39
-   */
40
-  protected $testBundle;
35
+    /**
36
+     * The test media bundle.
37
+     *
38
+     * @var \Drupal\media_entity\MediaBundleInterface
39
+     */
40
+    protected $testBundle;
41 41
 
42
-  /**
43
-   * {@inheritdoc}
44
-   */
45
-  protected function setUp() {
42
+    /**
43
+     * {@inheritdoc}
44
+     */
45
+    protected function setUp() {
46 46
     parent::setUp();
47 47
     $this->testBundle = $this->container->get('entity.manager')->getStorage('media_bundle')->load('image');
48 48
 
49 49
     $adminUser = $this->drupalCreateUser([
50
-      'view media',
51
-      'create media',
52
-      'update media',
53
-      'update any media',
54
-      'delete media',
55
-      'delete any media',
56
-      'access media overview',
50
+        'view media',
51
+        'create media',
52
+        'update media',
53
+        'update any media',
54
+        'delete media',
55
+        'delete any media',
56
+        'access media overview',
57 57
     ]);
58 58
     $this->drupalLogin($adminUser);
59
-  }
59
+    }
60 60
 
61
-  /**
62
-   * Tests image media bundle creation from config files.
63
-   */
64
-  public function testMediaBundleCreationFromModule() {
61
+    /**
62
+     * Tests image media bundle creation from config files.
63
+     */
64
+    public function testMediaBundleCreationFromModule() {
65 65
     $type_configuration = [
66
-      'source_field' => 'field_image',
67
-      'gather_exif' => FALSE,
66
+        'source_field' => 'field_image',
67
+        'gather_exif' => FALSE,
68 68
     ];
69 69
 
70 70
     $this->assertTrue((bool) $this->testBundle, 'The media bundle from default configuration has been created in the database.');
@@ -73,20 +73,20 @@  discard block
 block discarded – undo
73 73
     $this->assertEqual($this->testBundle->get('type'), 'image', 'Correct plugin ID detected.');
74 74
     $this->assertEqual($this->testBundle->get('type_configuration'), $type_configuration, 'Type configuration correct.');
75 75
     $this->assertEqual($this->testBundle->get('field_map'), [], 'Correct field map detected.');
76
-  }
76
+    }
77 77
 
78
-  /**
79
-   * Tests item creation and thumbnail.
80
-   */
81
-  public function testMediaBundleItemCreation() {
78
+    /**
79
+     * Tests item creation and thumbnail.
80
+     */
81
+    public function testMediaBundleItemCreation() {
82 82
     // Define the media item name.
83 83
     $name = $this->randomMachineName();
84 84
     $image_files = $this->drupalGetTestFiles('image');
85 85
     $testImage = current($image_files);
86 86
     $file_path = $this->container->get('file_system')->realpath($testImage->uri);
87 87
     $edit = [
88
-      'name[0][value]' => $name,
89
-      'files[field_image_0]' => $file_path,
88
+        'name[0][value]' => $name,
89
+        'files[field_image_0]' => $file_path,
90 90
     ];
91 91
 
92 92
     // Save the image.
@@ -105,6 +105,6 @@  discard block
 block discarded – undo
105 105
     $thumbnail = $image->thumbnail($media);
106 106
     $default_thumbnail = $image->getDefaultThumbnail();
107 107
     $this->assertNotEqual($thumbnail, $default_thumbnail, "The thumbnail generated is different from the default thumbnail.");
108
-  }
108
+    }
109 109
 
110 110
 }
Please login to merge, or discard this patch.
src/Tests/GalleryBundleTest.php 1 patch
Indentation   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -10,59 +10,59 @@  discard block
 block discarded – undo
10 10
  * @group media
11 11
  */
12 12
 class GalleryBundleTest extends WebTestBase {
13
-  /**
14
-   * Exempt from strict schema checking.
15
-   *
16
-   * @see \Drupal\Core\Config\Testing\ConfigSchemaChecker
17
-   *
18
-   * @var bool
19
-   */
20
-  protected $strictConfigSchema = FALSE;
21
-
22
-  /**
23
-   * Modules to enable.
24
-   *
25
-   * @var array
26
-   */
27
-  public static $modules = [
13
+    /**
14
+     * Exempt from strict schema checking.
15
+     *
16
+     * @see \Drupal\Core\Config\Testing\ConfigSchemaChecker
17
+     *
18
+     * @var bool
19
+     */
20
+    protected $strictConfigSchema = FALSE;
21
+
22
+    /**
23
+     * Modules to enable.
24
+     *
25
+     * @var array
26
+     */
27
+    public static $modules = [
28 28
     'media',
29 29
     'media_entity',
30 30
     'media_entity_slideshow',
31 31
     'node',
32
-  ];
33
-
34
-  /**
35
-   * The test media bundle.
36
-   *
37
-   * @var \Drupal\media_entity\MediaBundleInterface
38
-   */
39
-  protected $testBundle;
40
-
41
-  /**
42
-   * {@inheritdoc}
43
-   */
44
-  protected function setUp() {
32
+    ];
33
+
34
+    /**
35
+     * The test media bundle.
36
+     *
37
+     * @var \Drupal\media_entity\MediaBundleInterface
38
+     */
39
+    protected $testBundle;
40
+
41
+    /**
42
+     * {@inheritdoc}
43
+     */
44
+    protected function setUp() {
45 45
     parent::setUp();
46 46
     $this->testBundle = $this->container->get('entity_type.manager')->getStorage('media_bundle')->load('gallery');
47 47
 
48 48
     $adminUser = $this->drupalCreateUser([
49
-      'view media',
50
-      'create media',
51
-      'update media',
52
-      'update any media',
53
-      'delete media',
54
-      'delete any media',
55
-      'access media overview',
49
+        'view media',
50
+        'create media',
51
+        'update media',
52
+        'update any media',
53
+        'delete media',
54
+        'delete any media',
55
+        'access media overview',
56 56
     ]);
57 57
     $this->drupalLogin($adminUser);
58
-  }
58
+    }
59 59
 
60
-  /**
61
-   * Tests gallery media bundle creation from config files.
62
-   */
63
-  public function testMediaBundleCreationFromModule() {
60
+    /**
61
+     * Tests gallery media bundle creation from config files.
62
+     */
63
+    public function testMediaBundleCreationFromModule() {
64 64
     $type_configuration = [
65
-      'source_field' => 'field_slide',
65
+        'source_field' => 'field_slide',
66 66
     ];
67 67
 
68 68
     $this->assertTrue((bool) $this->testBundle, 'The media bundle from default configuration has been created in the database.');
@@ -71,21 +71,21 @@  discard block
 block discarded – undo
71 71
     $this->assertEqual($this->testBundle->get('type'), 'slideshow', 'Correct plugin ID detected.');
72 72
     $this->assertEqual($this->testBundle->get('type_configuration'), $type_configuration, 'Type configuration correct.');
73 73
     $this->assertEqual($this->testBundle->get('field_map'), [], 'Correct field map detected.');
74
-  }
74
+    }
75 75
 
76
-  /**
77
-   * Tests thumbnail of the gallery item.
78
-   */
79
-  public function testGalleryItemThumbnail() {
76
+    /**
77
+     * Tests thumbnail of the gallery item.
78
+     */
79
+    public function testGalleryItemThumbnail() {
80 80
     // Let's add one image and one video.
81 81
     $imageItem = $this->addImageItem();
82 82
     $videoItem = $this->addVideoItem();
83 83
     $this->drupalGet('media/add/gallery');
84 84
     $pathValue = (string) current($this->xpath('//input[@data-drupal-selector="edit-field-slide-entity-browser-path"]/@value'));
85 85
     $edit = [
86
-      'name[0][value]' => 'Gallery item',
87
-      'field_slide[target_id]' => $imageItem['id'] . ' ' . $videoItem['id'],
88
-      'field_slide[entity_browser][path]' => $pathValue,
86
+        'name[0][value]' => 'Gallery item',
87
+        'field_slide[target_id]' => $imageItem['id'] . ' ' . $videoItem['id'],
88
+        'field_slide[entity_browser][path]' => $pathValue,
89 89
     ];
90 90
     $this->drupalPostForm(NULL, $edit, t('Save and publish'));
91 91
 
@@ -102,9 +102,9 @@  discard block
 block discarded – undo
102 102
 
103 103
     $this->drupalGet('media/add/gallery');
104 104
     $edit = [
105
-      'name[0][value]' => 'Gallery item 2',
106
-      'field_slide[target_id]' => $videoItem['id'] . ' ' . $imageItem['id'] ,
107
-      'field_slide[entity_browser][path]' => $pathValue,
105
+        'name[0][value]' => 'Gallery item 2',
106
+        'field_slide[target_id]' => $videoItem['id'] . ' ' . $imageItem['id'] ,
107
+        'field_slide[entity_browser][path]' => $pathValue,
108 108
     ];
109 109
     $this->drupalPostForm(NULL, $edit, t('Save and publish'));
110 110
 
@@ -113,19 +113,19 @@  discard block
 block discarded – undo
113 113
     $gallery = $this->loadMediaItem(reset($gallery_id));
114 114
     $gallery_thumbnail = $gallery->getType()->thumbnail($gallery);
115 115
     $this->assertEqual($gallery_thumbnail, $video_thumbnail, "Correct thumbnail detected.");
116
-  }
116
+    }
117 117
 
118
-  /**
119
-   * Adds image type item.
120
-   */
121
-  public function addImageItem() {
118
+    /**
119
+     * Adds image type item.
120
+     */
121
+    public function addImageItem() {
122 122
     // Let's add image first.
123 123
     $name = $this->randomMachineName();
124 124
     $testImage = current($this->drupalGetTestFiles('image'));
125 125
     $file_path = $this->container->get('file_system')->realpath($testImage->uri);
126 126
     $edit = [
127
-      'name[0][value]' => $name,
128
-      'files[field_image_0]' => $file_path,
127
+        'name[0][value]' => $name,
128
+        'files[field_image_0]' => $file_path,
129 129
     ];
130 130
     // Save the image.
131 131
     $this->drupalPostForm('media/add/image', $edit, t('Save and publish'));
@@ -136,15 +136,15 @@  discard block
 block discarded – undo
136 136
     $edit['id'] = $media_id;
137 137
 
138 138
     return $edit;
139
-  }
139
+    }
140 140
 
141
-  /**
142
-   * Adds video type item.
143
-   */
144
-  public function addVideoItem() {
141
+    /**
142
+     * Adds video type item.
143
+     */
144
+    public function addVideoItem() {
145 145
     $edit = [
146
-      'name[0][value]' => 'Drupal video!',
147
-      'field_video[0][value]' => 'https://www.youtube.com/watch?v=XgYu7-DQjDQ',
146
+        'name[0][value]' => 'Drupal video!',
147
+        'field_video[0][value]' => 'https://www.youtube.com/watch?v=XgYu7-DQjDQ',
148 148
     ];
149 149
     $this->drupalPostForm('media/add/video', $edit, t('Save and publish'));
150 150
     // Obtain the video id.
@@ -153,22 +153,22 @@  discard block
 block discarded – undo
153 153
     $edit['id'] = $media_id;
154 154
 
155 155
     return $edit;
156
-  }
157
-
158
-  /**
159
-   * Loads the media entity item.
160
-   *
161
-   * @param int $id
162
-   *   The id of the item.
163
-   *
164
-   * @return \Drupal\media_entity\MediaInterface
165
-   *   The media entity item.
166
-   */
167
-  public function loadMediaItem($id) {
156
+    }
157
+
158
+    /**
159
+     * Loads the media entity item.
160
+     *
161
+     * @param int $id
162
+     *   The id of the item.
163
+     *
164
+     * @return \Drupal\media_entity\MediaInterface
165
+     *   The media entity item.
166
+     */
167
+    public function loadMediaItem($id) {
168 168
     $item = $this->container->get('entity_type.manager')
169
-      ->getStorage('media')
170
-      ->loadUnchanged($id);
169
+        ->getStorage('media')
170
+        ->loadUnchanged($id);
171 171
     return $item;
172
-  }
172
+    }
173 173
 
174 174
 }
Please login to merge, or discard this patch.
media.module 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -13,13 +13,13 @@  discard block
 block discarded – undo
13 13
  * Implements hook_help().
14 14
  */
15 15
 function media_help($route_name, RouteMatchInterface $route_match) {
16
-  switch ($route_name) {
16
+    switch ($route_name) {
17 17
     // Main module help for the media module.
18 18
     case 'help.page.media':
19 19
       $output = '';
20
-      $output .= '<h3>' . t('About') . '</h3>';
21
-      $output .= '<p>' . t('Media module for Drupal 8') . '</p>';
22
-      return $output;
20
+        $output .= '<h3>' . t('About') . '</h3>';
21
+        $output .= '<p>' . t('Media module for Drupal 8') . '</p>';
22
+        return $output;
23 23
 
24 24
     default:
25 25
   }
@@ -29,25 +29,25 @@  discard block
 block discarded – undo
29 29
  * Implements hook_form_alter().
30 30
  */
31 31
 function media_form_alter(&$form, FormStateInterface &$form_state) {
32
-  if ($form['#form_id'] == 'entity_browser_media_library_form') {
32
+    if ($form['#form_id'] == 'entity_browser_media_library_form') {
33 33
     // Style the submit button.
34 34
     $form['actions']['submit']['#attributes']['class'][] = 'button--primary';
35 35
     $form['actions']['submit']['#attributes']['class'][] = 'entity-browser-modal-target';
36
-  }
36
+    }
37 37
 }
38 38
 
39 39
 /**
40 40
  * Implements hook_library_info_alter().
41 41
  */
42 42
 function media_library_info_alter(&$libraries, $extension) {
43
-  // Optionally use the Libraries module to determine our library paths.
44
-  if ($extension == 'media' && \Drupal::moduleHandler()->moduleExists('libraries')) {
43
+    // Optionally use the Libraries module to determine our library paths.
44
+    if ($extension == 'media' && \Drupal::moduleHandler()->moduleExists('libraries')) {
45 45
     $imagesloaded_path = libraries_get_path('imagesloaded') . '/imagesloaded.pkgd.min.js';
46 46
     $masonry_path = libraries_get_path('masonry') . '/dist/masonry.pkgd.min.js';
47 47
 
48 48
     $libraries['imagesloaded']['js'] = ['/' . $imagesloaded_path => ['minified' => 'true']];
49 49
     $libraries['masonry']['js'] = ['/' . $masonry_path => ['minified' => 'true']];
50
-  }
50
+    }
51 51
 }
52 52
 
53 53
 /**
@@ -56,9 +56,9 @@  discard block
 block discarded – undo
56 56
  * Adds the media.view library to the media views.
57 57
  */
58 58
 function media_views_pre_render(ViewExecutable $view) {
59
-  if (isset($view) && ($view->storage->id() == 'media_library' || $view->storage->id() == 'global_media_library')) {
59
+    if (isset($view) && ($view->storage->id() == 'media_library' || $view->storage->id() == 'global_media_library')) {
60 60
     $view->element['#attached']['library'][] = 'media/view';
61
-  }
61
+    }
62 62
 }
63 63
 
64 64
 /**
@@ -67,14 +67,14 @@  discard block
 block discarded – undo
67 67
  * Adds the add media button from media_entity on library pages.
68 68
  */
69 69
 function media_menu_local_actions_alter(&$local_actions) {
70
-  $local_actions['media.add']['appears_on'][] = 'view.media_library.user_media_library';
71
-  $local_actions['media.add']['appears_on'][] = 'view.media_library.global_media_library_page';
70
+    $local_actions['media.add']['appears_on'][] = 'view.media_library.user_media_library';
71
+    $local_actions['media.add']['appears_on'][] = 'view.media_library.global_media_library_page';
72 72
 }
73 73
 
74 74
 /**
75 75
  * Implements hook_entity_type_alter().
76 76
  */
77 77
 function media_entity_type_alter(array &$entity_types) {
78
-  $field_name = \Drupal::config('media_entity.bundle.gallery')->get('type_configuration.source_field');
79
-  $entity_types['media']->addConstraint('GalleryMediaBundle', array('sourceFieldName' => $field_name));
78
+    $field_name = \Drupal::config('media_entity.bundle.gallery')->get('type_configuration.source_field');
79
+    $entity_types['media']->addConstraint('GalleryMediaBundle', array('sourceFieldName' => $field_name));
80 80
 }
Please login to merge, or discard this patch.
src/Plugin/Validation/Constraint/GalleryMediaBundleConstraintValidator.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -10,22 +10,22 @@
 block discarded – undo
10 10
  */
11 11
 class GalleryMediaBundleConstraintValidator extends ConstraintValidator {
12 12
 
13
-  /**
14
-   * {@inheritdoc}
15
-   */
16
-  public function validate($value, Constraint $constraint) {
13
+    /**
14
+     * {@inheritdoc}
15
+     */
16
+    public function validate($value, Constraint $constraint) {
17 17
     if (!isset($value)) {
18
-      return;
18
+        return;
19 19
     }
20 20
     if ($value->hasField($constraint->sourceFieldName)) {
21
-      $slideshowItems = $value->get($constraint->sourceFieldName);
22
-      foreach ($slideshowItems as $item) {
21
+        $slideshowItems = $value->get($constraint->sourceFieldName);
22
+        foreach ($slideshowItems as $item) {
23 23
         $itemBundle = \Drupal::entityTypeManager()->getStorage('media')->load($item->target_id)->bundle();
24 24
         if ($itemBundle == "gallery") {
25
-          $this->context->addViolation($constraint->message);
25
+            $this->context->addViolation($constraint->message);
26 26
         }
27
-      }
27
+        }
28
+    }
28 29
     }
29
-  }
30 30
 
31 31
 }
Please login to merge, or discard this patch.
src/Plugin/Validation/Constraint/GalleryMediaBundleConstraint.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -14,17 +14,17 @@
 block discarded – undo
14 14
  */
15 15
 class GalleryMediaBundleConstraint extends Constraint {
16 16
 
17
-  /**
18
-   * Name of the source field for slideshow bundle.
19
-   *
20
-   * @var string
21
-   */
22
-  public $sourceFieldName;
17
+    /**
18
+     * Name of the source field for slideshow bundle.
19
+     *
20
+     * @var string
21
+     */
22
+    public $sourceFieldName;
23 23
 
24
-  /**
25
-   * The default violation message.
26
-   *
27
-   * @var string
28
-   */
29
-  public $message = 'Gallery cannot contain gallery type item.';
24
+    /**
25
+     * The default violation message.
26
+     *
27
+     * @var string
28
+     */
29
+    public $message = 'Gallery cannot contain gallery type item.';
30 30
 }
Please login to merge, or discard this patch.
src/Tests/DocumentBundleTest.php 1 patch
Indentation   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -10,63 +10,63 @@  discard block
 block discarded – undo
10 10
  * @group media
11 11
  */
12 12
 class DocumentBundleTest extends WebTestBase {
13
-  /**
14
-   * Exempt from strict schema checking.
15
-   *
16
-   * @see \Drupal\Core\Config\Testing\ConfigSchemaChecker
17
-   *
18
-   * @var bool
19
-   */
20
-  protected $strictConfigSchema = FALSE;
13
+    /**
14
+     * Exempt from strict schema checking.
15
+     *
16
+     * @see \Drupal\Core\Config\Testing\ConfigSchemaChecker
17
+     *
18
+     * @var bool
19
+     */
20
+    protected $strictConfigSchema = FALSE;
21 21
 
22
-  /**
23
-   * Modules to enable.
24
-   *
25
-   * @var array
26
-   */
27
-  public static $modules = [
22
+    /**
23
+     * Modules to enable.
24
+     *
25
+     * @var array
26
+     */
27
+    public static $modules = [
28 28
     'media',
29 29
     'media_entity',
30 30
     'media_entity_document',
31 31
     'node',
32
-  ];
32
+    ];
33 33
 
34
-  /**
35
-   * The test media bundle.
36
-   *
37
-   * @var \Drupal\media_entity\MediaBundleInterface
38
-   */
39
-  protected $testBundle;
34
+    /**
35
+     * The test media bundle.
36
+     *
37
+     * @var \Drupal\media_entity\MediaBundleInterface
38
+     */
39
+    protected $testBundle;
40 40
 
41
-  /**
42
-   * {@inheritdoc}
43
-   */
44
-  protected function setUp() {
41
+    /**
42
+     * {@inheritdoc}
43
+     */
44
+    protected function setUp() {
45 45
     parent::setUp();
46 46
     $this->testBundle = $this->container->get('entity_type.manager')->getStorage('media_bundle')->load('document');
47 47
 
48 48
     $adminUser = $this->drupalCreateUser([
49
-      'view media',
50
-      'create media',
51
-      'update media',
52
-      'update any media',
53
-      'delete media',
54
-      'delete any media',
55
-      'access media overview',
49
+        'view media',
50
+        'create media',
51
+        'update media',
52
+        'update any media',
53
+        'delete media',
54
+        'delete any media',
55
+        'access media overview',
56 56
     ]);
57 57
     $this->drupalLogin($adminUser);
58
-  }
58
+    }
59 59
 
60
-  /**
61
-   * Tests document media bundle creation from config files.
62
-   */
63
-  public function testMediaBundleCreationFromModule() {
60
+    /**
61
+     * Tests document media bundle creation from config files.
62
+     */
63
+    public function testMediaBundleCreationFromModule() {
64 64
     $type_configuration = [
65
-      'source_field' => 'field_document',
65
+        'source_field' => 'field_document',
66 66
     ];
67 67
     $field_map = [
68
-      'mime' => 'field_mime_type',
69
-      'size' => 'field_document_size',
68
+        'mime' => 'field_mime_type',
69
+        'size' => 'field_document_size',
70 70
     ];
71 71
 
72 72
     $this->assertTrue((bool) $this->testBundle, 'The media bundle from default configuration has been created in the database.');
@@ -75,25 +75,25 @@  discard block
 block discarded – undo
75 75
     $this->assertEqual($this->testBundle->get('type'), 'document', 'Correct plugin ID detected.');
76 76
     $this->assertEqual($this->testBundle->get('type_configuration'), $type_configuration, 'Type configuration correct.');
77 77
     $this->assertEqual($this->testBundle->get('field_map'), $field_map, 'Correct field map detected.');
78
-  }
78
+    }
79 79
 
80
-  /**
81
-   * Tests thumbnails of the document items.
82
-   */
83
-  public function testDocumentItemThumbnail() {
80
+    /**
81
+     * Tests thumbnails of the document items.
82
+     */
83
+    public function testDocumentItemThumbnail() {
84 84
     // Test thumbnail of PDF file.
85 85
     $file = drupal_get_path('module', 'media') . '/files/Test.pdf';
86 86
     $this->drupalGet('media/add/document');
87 87
     $edit = [
88
-      'files[field_document_0]' => $file,
88
+        'files[field_document_0]' => $file,
89 89
     ];
90 90
     $this->drupalPostAjaxForm(NULL, $edit, "field_document_0_upload_button");
91 91
     $fid = (string) current($this->xpath('//input[@data-drupal-selector="edit-field-document-0-fids"]/@value'));
92 92
     $edit = [
93
-      'name[0][value]' => 'PDF file',
94
-      'form_id' => 'media_document_form',
95
-      'field_document[0][fids]' => $fid,
96
-      'field_document[0][display]' => 1,
93
+        'name[0][value]' => 'PDF file',
94
+        'form_id' => 'media_document_form',
95
+        'field_document[0][fids]' => $fid,
96
+        'field_document[0][display]' => 1,
97 97
     ];
98 98
     $this->drupalPostForm(NULL, $edit, t('Save and publish'));
99 99
     $thumbnail = $this->getMostRecentThumbnail();
@@ -103,15 +103,15 @@  discard block
 block discarded – undo
103 103
     $file = drupal_get_path('module', 'media') . '/files/Test.doc';
104 104
     $this->drupalGet('media/add/document');
105 105
     $edit = [
106
-      'files[field_document_0]' => $file,
106
+        'files[field_document_0]' => $file,
107 107
     ];
108 108
     $this->drupalPostAjaxForm(NULL, $edit, "field_document_0_upload_button");
109 109
     $fid = (string) current($this->xpath('//input[@data-drupal-selector="edit-field-document-0-fids"]/@value'));
110 110
     $edit = [
111
-      'name[0][value]' => 'DOC file',
112
-      'form_id' => 'media_document_form',
113
-      'field_document[0][fids]' => $fid,
114
-      'field_document[0][display]' => 1,
111
+        'name[0][value]' => 'DOC file',
112
+        'form_id' => 'media_document_form',
113
+        'field_document[0][fids]' => $fid,
114
+        'field_document[0][display]' => 1,
115 115
     ];
116 116
     $this->drupalPostForm(NULL, $edit, t('Save and publish'));
117 117
     $thumbnail = $this->getMostRecentThumbnail();
@@ -121,15 +121,15 @@  discard block
 block discarded – undo
121 121
     $file = drupal_get_path('module', 'media') . '/files/Test.docx';
122 122
     $this->drupalGet('media/add/document');
123 123
     $edit = [
124
-      'files[field_document_0]' => $file,
124
+        'files[field_document_0]' => $file,
125 125
     ];
126 126
     $this->drupalPostAjaxForm(NULL, $edit, "field_document_0_upload_button");
127 127
     $fid = (string) current($this->xpath('//input[@data-drupal-selector="edit-field-document-0-fids"]/@value'));
128 128
     $edit = [
129
-      'name[0][value]' => 'DOCX file',
130
-      'form_id' => 'media_document_form',
131
-      'field_document[0][fids]' => $fid,
132
-      'field_document[0][display]' => 1,
129
+        'name[0][value]' => 'DOCX file',
130
+        'form_id' => 'media_document_form',
131
+        'field_document[0][fids]' => $fid,
132
+        'field_document[0][display]' => 1,
133 133
     ];
134 134
     $this->drupalPostForm(NULL, $edit, t('Save and publish'));
135 135
     $thumbnail = $this->getMostRecentThumbnail();
@@ -139,15 +139,15 @@  discard block
 block discarded – undo
139 139
     $file = drupal_get_path('module', 'media') . '/files/Test.ods';
140 140
     $this->drupalGet('media/add/document');
141 141
     $edit = [
142
-      'files[field_document_0]' => $file,
142
+        'files[field_document_0]' => $file,
143 143
     ];
144 144
     $this->drupalPostAjaxForm(NULL, $edit, "field_document_0_upload_button");
145 145
     $fid = (string) current($this->xpath('//input[@data-drupal-selector="edit-field-document-0-fids"]/@value'));
146 146
     $edit = [
147
-      'name[0][value]' => 'ODS file',
148
-      'form_id' => 'media_document_form',
149
-      'field_document[0][fids]' => $fid,
150
-      'field_document[0][display]' => 1,
147
+        'name[0][value]' => 'ODS file',
148
+        'form_id' => 'media_document_form',
149
+        'field_document[0][fids]' => $fid,
150
+        'field_document[0][display]' => 1,
151 151
     ];
152 152
     $this->drupalPostForm(NULL, $edit, t('Save and publish'));
153 153
     $thumbnail = $this->getMostRecentThumbnail();
@@ -157,15 +157,15 @@  discard block
 block discarded – undo
157 157
     $file = drupal_get_path('module', 'media') . '/files/Test.odt';
158 158
     $this->drupalGet('media/add/document');
159 159
     $edit = [
160
-      'files[field_document_0]' => $file,
160
+        'files[field_document_0]' => $file,
161 161
     ];
162 162
     $this->drupalPostAjaxForm(NULL, $edit, "field_document_0_upload_button");
163 163
     $fid = (string) current($this->xpath('//input[@data-drupal-selector="edit-field-document-0-fids"]/@value'));
164 164
     $edit = [
165
-      'name[0][value]' => 'ODT file',
166
-      'form_id' => 'media_document_form',
167
-      'field_document[0][fids]' => $fid,
168
-      'field_document[0][display]' => 1,
165
+        'name[0][value]' => 'ODT file',
166
+        'form_id' => 'media_document_form',
167
+        'field_document[0][fids]' => $fid,
168
+        'field_document[0][display]' => 1,
169 169
     ];
170 170
     $this->drupalPostForm(NULL, $edit, t('Save and publish'));
171 171
     $thumbnail = $this->getMostRecentThumbnail();
@@ -175,15 +175,15 @@  discard block
 block discarded – undo
175 175
     $file = drupal_get_path('module', 'media') . '/files/Test.ott';
176 176
     $this->drupalGet('media/add/document');
177 177
     $edit = [
178
-      'files[field_document_0]' => $file,
178
+        'files[field_document_0]' => $file,
179 179
     ];
180 180
     $this->drupalPostAjaxForm(NULL, $edit, "field_document_0_upload_button");
181 181
     $fid = (string) current($this->xpath('//input[@data-drupal-selector="edit-field-document-0-fids"]/@value'));
182 182
     $edit = [
183
-      'name[0][value]' => 'OTT file',
184
-      'form_id' => 'media_document_form',
185
-      'field_document[0][fids]' => $fid,
186
-      'field_document[0][display]' => 1,
183
+        'name[0][value]' => 'OTT file',
184
+        'form_id' => 'media_document_form',
185
+        'field_document[0][fids]' => $fid,
186
+        'field_document[0][display]' => 1,
187 187
     ];
188 188
     $this->drupalPostForm(NULL, $edit, t('Save and publish'));
189 189
     $thumbnail = $this->getMostRecentThumbnail();
@@ -193,15 +193,15 @@  discard block
 block discarded – undo
193 193
     $file = drupal_get_path('module', 'media') . '/files/Test.ppt';
194 194
     $this->drupalGet('media/add/document');
195 195
     $edit = [
196
-      'files[field_document_0]' => $file,
196
+        'files[field_document_0]' => $file,
197 197
     ];
198 198
     $this->drupalPostAjaxForm(NULL, $edit, "field_document_0_upload_button");
199 199
     $fid = (string) current($this->xpath('//input[@data-drupal-selector="edit-field-document-0-fids"]/@value'));
200 200
     $edit = [
201
-      'name[0][value]' => 'PPT file',
202
-      'form_id' => 'media_document_form',
203
-      'field_document[0][fids]' => $fid,
204
-      'field_document[0][display]' => 1,
201
+        'name[0][value]' => 'PPT file',
202
+        'form_id' => 'media_document_form',
203
+        'field_document[0][fids]' => $fid,
204
+        'field_document[0][display]' => 1,
205 205
     ];
206 206
     $this->drupalPostForm(NULL, $edit, t('Save and publish'));
207 207
     $thumbnail = $this->getMostRecentThumbnail();
@@ -211,15 +211,15 @@  discard block
 block discarded – undo
211 211
     $file = drupal_get_path('module', 'media') . '/files/Test.pptx';
212 212
     $this->drupalGet('media/add/document');
213 213
     $edit = [
214
-      'files[field_document_0]' => $file,
214
+        'files[field_document_0]' => $file,
215 215
     ];
216 216
     $this->drupalPostAjaxForm(NULL, $edit, "field_document_0_upload_button");
217 217
     $fid = (string) current($this->xpath('//input[@data-drupal-selector="edit-field-document-0-fids"]/@value'));
218 218
     $edit = [
219
-      'name[0][value]' => 'PPTX file',
220
-      'form_id' => 'media_document_form',
221
-      'field_document[0][fids]' => $fid,
222
-      'field_document[0][display]' => 1,
219
+        'name[0][value]' => 'PPTX file',
220
+        'form_id' => 'media_document_form',
221
+        'field_document[0][fids]' => $fid,
222
+        'field_document[0][display]' => 1,
223 223
     ];
224 224
     $this->drupalPostForm(NULL, $edit, t('Save and publish'));
225 225
     $thumbnail = $this->getMostRecentThumbnail();
@@ -229,15 +229,15 @@  discard block
 block discarded – undo
229 229
     $file = drupal_get_path('module', 'media') . '/files/Test.rtf';
230 230
     $this->drupalGet('media/add/document');
231 231
     $edit = [
232
-      'files[field_document_0]' => $file,
232
+        'files[field_document_0]' => $file,
233 233
     ];
234 234
     $this->drupalPostAjaxForm(NULL, $edit, "field_document_0_upload_button");
235 235
     $fid = (string) current($this->xpath('//input[@data-drupal-selector="edit-field-document-0-fids"]/@value'));
236 236
     $edit = [
237
-      'name[0][value]' => 'RTF file',
238
-      'form_id' => 'media_document_form',
239
-      'field_document[0][fids]' => $fid,
240
-      'field_document[0][display]' => 1,
237
+        'name[0][value]' => 'RTF file',
238
+        'form_id' => 'media_document_form',
239
+        'field_document[0][fids]' => $fid,
240
+        'field_document[0][display]' => 1,
241 241
     ];
242 242
     $this->drupalPostForm(NULL, $edit, t('Save and publish'));
243 243
     $thumbnail = $this->getMostRecentThumbnail();
@@ -247,15 +247,15 @@  discard block
 block discarded – undo
247 247
     $file = drupal_get_path('module', 'media') . '/files/Test.txt';
248 248
     $this->drupalGet('media/add/document');
249 249
     $edit = [
250
-      'files[field_document_0]' => $file,
250
+        'files[field_document_0]' => $file,
251 251
     ];
252 252
     $this->drupalPostAjaxForm(NULL, $edit, "field_document_0_upload_button");
253 253
     $fid = (string) current($this->xpath('//input[@data-drupal-selector="edit-field-document-0-fids"]/@value'));
254 254
     $edit = [
255
-      'name[0][value]' => 'TXT file',
256
-      'form_id' => 'media_document_form',
257
-      'field_document[0][fids]' => $fid,
258
-      'field_document[0][display]' => 1,
255
+        'name[0][value]' => 'TXT file',
256
+        'form_id' => 'media_document_form',
257
+        'field_document[0][fids]' => $fid,
258
+        'field_document[0][display]' => 1,
259 259
     ];
260 260
     $this->drupalPostForm(NULL, $edit, t('Save and publish'));
261 261
     $thumbnail = $this->getMostRecentThumbnail();
@@ -265,15 +265,15 @@  discard block
 block discarded – undo
265 265
     $file = drupal_get_path('module', 'media') . '/files/Test.xls';
266 266
     $this->drupalGet('media/add/document');
267 267
     $edit = [
268
-      'files[field_document_0]' => $file,
268
+        'files[field_document_0]' => $file,
269 269
     ];
270 270
     $this->drupalPostAjaxForm(NULL, $edit, "field_document_0_upload_button");
271 271
     $fid = (string) current($this->xpath('//input[@data-drupal-selector="edit-field-document-0-fids"]/@value'));
272 272
     $edit = [
273
-      'name[0][value]' => 'XLS file',
274
-      'form_id' => 'media_document_form',
275
-      'field_document[0][fids]' => $fid,
276
-      'field_document[0][display]' => 1,
273
+        'name[0][value]' => 'XLS file',
274
+        'form_id' => 'media_document_form',
275
+        'field_document[0][fids]' => $fid,
276
+        'field_document[0][display]' => 1,
277 277
     ];
278 278
     $this->drupalPostForm(NULL, $edit, t('Save and publish'));
279 279
     $thumbnail = $this->getMostRecentThumbnail();
@@ -283,33 +283,33 @@  discard block
 block discarded – undo
283 283
     $file = drupal_get_path('module', 'media') . '/files/Test.xlsx';
284 284
     $this->drupalGet('media/add/document');
285 285
     $edit = [
286
-      'files[field_document_0]' => $file,
286
+        'files[field_document_0]' => $file,
287 287
     ];
288 288
     $this->drupalPostAjaxForm(NULL, $edit, "field_document_0_upload_button");
289 289
     $fid = (string) current($this->xpath('//input[@data-drupal-selector="edit-field-document-0-fids"]/@value'));
290 290
     $edit = [
291
-      'name[0][value]' => 'XLSX file',
292
-      'form_id' => 'media_document_form',
293
-      'field_document[0][fids]' => $fid,
294
-      'field_document[0][display]' => 1,
291
+        'name[0][value]' => 'XLSX file',
292
+        'form_id' => 'media_document_form',
293
+        'field_document[0][fids]' => $fid,
294
+        'field_document[0][display]' => 1,
295 295
     ];
296 296
     $this->drupalPostForm(NULL, $edit, t('Save and publish'));
297 297
     $thumbnail = $this->getMostRecentThumbnail();
298 298
     $this->assertEqual('public://media-icons/generic/application-vnd.openxmlformats-officedocument.spreadsheetml.sheet.png', $thumbnail, "Correct thumbnail detected for XLSX File.");
299
-  }
299
+    }
300 300
 
301
-  /**
302
-   * Returns the thumbnail of the most recent document.
303
-   *
304
-   * @return string
305
-   *   Path of the thumbnail.
306
-   */
307
-  public function getMostRecentThumbnail() {
301
+    /**
302
+     * Returns the thumbnail of the most recent document.
303
+     *
304
+     * @return string
305
+     *   Path of the thumbnail.
306
+     */
307
+    public function getMostRecentThumbnail() {
308 308
     $document_id = $this->container->get('entity.query')->get('media')->condition('bundle', 'document')->sort('created', 'DESC')->execute();
309 309
     $item = $this->container->get('entity_type.manager')
310
-      ->getStorage('media')
311
-      ->loadUnchanged(reset($document_id));
310
+        ->getStorage('media')
311
+        ->loadUnchanged(reset($document_id));
312 312
     return $item->getType()->thumbnail($item);
313
-  }
313
+    }
314 314
 
315 315
 }
Please login to merge, or discard this patch.