@@ -10,63 +10,63 @@ discard block |
||
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,60 +75,60 @@ discard block |
||
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 | $files = [ |
85 | - 'Test.pdf' => 'public://media-icons/generic/application-pdf.png', |
|
86 | - 'Test.doc' => 'public://media-icons/generic/application-msword.png', |
|
87 | - 'Test.docx' => 'public://media-icons/generic/application-vnd.openxmlformats-officedocument.wordprocessingml.document.png', |
|
88 | - 'Test.ods' => 'public://media-icons/generic/application-vnd.oasis.opendocument.spreadsheet.png', |
|
89 | - 'Test.odt' => 'public://media-icons/generic/application-vnd.oasis.opendocument.text.png', |
|
90 | - 'Test.ott' => 'public://media-icons/generic/application-vnd.oasis.opendocument.text-template.png', |
|
91 | - 'Test.ppt' => 'public://media-icons/generic/application-vnd.ms-powerpoint.png', |
|
92 | - 'Test.pptx' => 'public://media-icons/generic/application-vnd.openxmlformats-officedocument.presentationml.presentation.png', |
|
93 | - 'Test.rtf' => 'public://media-icons/generic/application-rtf.png', |
|
94 | - 'Test.txt' => 'public://media-icons/generic/text-plain.png', |
|
95 | - 'Test.xls' => 'public://media-icons/generic/application-vnd.ms-excel.png', |
|
96 | - 'Test.xlsx' => 'public://media-icons/generic/application-vnd.openxmlformats-officedocument.spreadsheetml.sheet.png', |
|
85 | + 'Test.pdf' => 'public://media-icons/generic/application-pdf.png', |
|
86 | + 'Test.doc' => 'public://media-icons/generic/application-msword.png', |
|
87 | + 'Test.docx' => 'public://media-icons/generic/application-vnd.openxmlformats-officedocument.wordprocessingml.document.png', |
|
88 | + 'Test.ods' => 'public://media-icons/generic/application-vnd.oasis.opendocument.spreadsheet.png', |
|
89 | + 'Test.odt' => 'public://media-icons/generic/application-vnd.oasis.opendocument.text.png', |
|
90 | + 'Test.ott' => 'public://media-icons/generic/application-vnd.oasis.opendocument.text-template.png', |
|
91 | + 'Test.ppt' => 'public://media-icons/generic/application-vnd.ms-powerpoint.png', |
|
92 | + 'Test.pptx' => 'public://media-icons/generic/application-vnd.openxmlformats-officedocument.presentationml.presentation.png', |
|
93 | + 'Test.rtf' => 'public://media-icons/generic/application-rtf.png', |
|
94 | + 'Test.txt' => 'public://media-icons/generic/text-plain.png', |
|
95 | + 'Test.xls' => 'public://media-icons/generic/application-vnd.ms-excel.png', |
|
96 | + 'Test.xlsx' => 'public://media-icons/generic/application-vnd.openxmlformats-officedocument.spreadsheetml.sheet.png', |
|
97 | 97 | ]; |
98 | 98 | |
99 | 99 | foreach ($files as $fileName => $thumbnail) { |
100 | - $file = drupal_get_path('module', 'media') . '/files/' . $fileName; |
|
101 | - $name = $this->randomMachineName(); |
|
102 | - $this->drupalGet('media/add/document'); |
|
103 | - $edit = [ |
|
100 | + $file = drupal_get_path('module', 'media') . '/files/' . $fileName; |
|
101 | + $name = $this->randomMachineName(); |
|
102 | + $this->drupalGet('media/add/document'); |
|
103 | + $edit = [ |
|
104 | 104 | 'files[field_document_0]' => $file, |
105 | - ]; |
|
106 | - $this->drupalPostAjaxForm(NULL, $edit, "field_document_0_upload_button"); |
|
107 | - $fid = (string) current($this->xpath('//input[@data-drupal-selector="edit-field-document-0-fids"]/@value')); |
|
108 | - $edit = [ |
|
105 | + ]; |
|
106 | + $this->drupalPostAjaxForm(NULL, $edit, "field_document_0_upload_button"); |
|
107 | + $fid = (string) current($this->xpath('//input[@data-drupal-selector="edit-field-document-0-fids"]/@value')); |
|
108 | + $edit = [ |
|
109 | 109 | 'name[0][value]' => $name, |
110 | 110 | 'form_id' => 'media_document_form', |
111 | 111 | 'field_document[0][fids]' => $fid, |
112 | 112 | 'field_document[0][display]' => 1, |
113 | - ]; |
|
114 | - $this->drupalPostForm(NULL, $edit, t('Save and publish')); |
|
115 | - $recentThumbnail = $this->getMostRecentThumbnail(); |
|
116 | - $this->assertEqual($thumbnail, $recentThumbnail, "Correct thumbnail detected for " . $fileName); |
|
113 | + ]; |
|
114 | + $this->drupalPostForm(NULL, $edit, t('Save and publish')); |
|
115 | + $recentThumbnail = $this->getMostRecentThumbnail(); |
|
116 | + $this->assertEqual($thumbnail, $recentThumbnail, "Correct thumbnail detected for " . $fileName); |
|
117 | + } |
|
117 | 118 | } |
118 | - } |
|
119 | 119 | |
120 | - /** |
|
121 | - * Returns the thumbnail of the most recent document. |
|
122 | - * |
|
123 | - * @return string |
|
124 | - * Path of the thumbnail. |
|
125 | - */ |
|
126 | - public function getMostRecentThumbnail() { |
|
120 | + /** |
|
121 | + * Returns the thumbnail of the most recent document. |
|
122 | + * |
|
123 | + * @return string |
|
124 | + * Path of the thumbnail. |
|
125 | + */ |
|
126 | + public function getMostRecentThumbnail() { |
|
127 | 127 | $document_id = $this->container->get('entity.query')->get('media')->condition('bundle', 'document')->sort('created', 'DESC')->execute(); |
128 | 128 | $item = $this->container->get('entity_type.manager') |
129 | - ->getStorage('media') |
|
130 | - ->loadUnchanged(reset($document_id)); |
|
129 | + ->getStorage('media') |
|
130 | + ->loadUnchanged(reset($document_id)); |
|
131 | 131 | return $item->getType()->thumbnail($item); |
132 | - } |
|
132 | + } |
|
133 | 133 | |
134 | 134 | } |