Completed
Pull Request — 8.x-1.x (#10)
by Vijay
02:15
created
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.