| Conditions | 1 |
| Paths | 1 |
| Total Lines | 217 |
| Code Lines | 169 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 83 | public function testDocumentItemThumbnail() { |
||
| 84 | // Test thumbnail of PDF file. |
||
| 85 | $file = drupal_get_path('module', 'media') . '/files/Test.pdf'; |
||
| 86 | $this->drupalGet('media/add/document'); |
||
| 87 | $edit = [ |
||
| 88 | 'files[field_document_0]' => $file, |
||
| 89 | ]; |
||
| 90 | $this->drupalPostAjaxForm(NULL, $edit, "field_document_0_upload_button"); |
||
| 91 | $fid = (string) current($this->xpath('//input[@data-drupal-selector="edit-field-document-0-fids"]/@value')); |
||
| 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, |
||
| 97 | ]; |
||
| 98 | $this->drupalPostForm(NULL, $edit, t('Save and publish')); |
||
| 99 | $thumbnail = $this->getMostRecentThumbnail(); |
||
| 100 | $this->assertEqual('public://media-icons/generic/application-pdf.png', $thumbnail, "Correct thumbnail detected for PDF File."); |
||
| 101 | |||
| 102 | // Test thumbnail of DOC file. |
||
| 103 | $file = drupal_get_path('module', 'media') . '/files/Test.doc'; |
||
| 104 | $this->drupalGet('media/add/document'); |
||
| 105 | $edit = [ |
||
| 106 | 'files[field_document_0]' => $file, |
||
| 107 | ]; |
||
| 108 | $this->drupalPostAjaxForm(NULL, $edit, "field_document_0_upload_button"); |
||
| 109 | $fid = (string) current($this->xpath('//input[@data-drupal-selector="edit-field-document-0-fids"]/@value')); |
||
| 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, |
||
| 115 | ]; |
||
| 116 | $this->drupalPostForm(NULL, $edit, t('Save and publish')); |
||
| 117 | $thumbnail = $this->getMostRecentThumbnail(); |
||
| 118 | $this->assertEqual('public://media-icons/generic/application-msword.png', $thumbnail, "Correct thumbnail detected for DOC File."); |
||
| 119 | |||
| 120 | // Test thumbnail of DOCX file. |
||
| 121 | $file = drupal_get_path('module', 'media') . '/files/Test.docx'; |
||
| 122 | $this->drupalGet('media/add/document'); |
||
| 123 | $edit = [ |
||
| 124 | 'files[field_document_0]' => $file, |
||
| 125 | ]; |
||
| 126 | $this->drupalPostAjaxForm(NULL, $edit, "field_document_0_upload_button"); |
||
| 127 | $fid = (string) current($this->xpath('//input[@data-drupal-selector="edit-field-document-0-fids"]/@value')); |
||
| 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, |
||
| 133 | ]; |
||
| 134 | $this->drupalPostForm(NULL, $edit, t('Save and publish')); |
||
| 135 | $thumbnail = $this->getMostRecentThumbnail(); |
||
| 136 | $this->assertEqual('public://media-icons/generic/application-vnd.openxmlformats-officedocument.wordprocessingml.document.png', $thumbnail, "Correct thumbnail detected for DOCX File."); |
||
| 137 | |||
| 138 | // Test thumbnail of ODS file. |
||
| 139 | $file = drupal_get_path('module', 'media') . '/files/Test.ods'; |
||
| 140 | $this->drupalGet('media/add/document'); |
||
| 141 | $edit = [ |
||
| 142 | 'files[field_document_0]' => $file, |
||
| 143 | ]; |
||
| 144 | $this->drupalPostAjaxForm(NULL, $edit, "field_document_0_upload_button"); |
||
| 145 | $fid = (string) current($this->xpath('//input[@data-drupal-selector="edit-field-document-0-fids"]/@value')); |
||
| 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, |
||
| 151 | ]; |
||
| 152 | $this->drupalPostForm(NULL, $edit, t('Save and publish')); |
||
| 153 | $thumbnail = $this->getMostRecentThumbnail(); |
||
| 154 | $this->assertEqual('public://media-icons/generic/application-vnd.oasis.opendocument.spreadsheet.png', $thumbnail, "Correct thumbnail detected for ODS File."); |
||
| 155 | |||
| 156 | // Test thumbnail of ODT file. |
||
| 157 | $file = drupal_get_path('module', 'media') . '/files/Test.odt'; |
||
| 158 | $this->drupalGet('media/add/document'); |
||
| 159 | $edit = [ |
||
| 160 | 'files[field_document_0]' => $file, |
||
| 161 | ]; |
||
| 162 | $this->drupalPostAjaxForm(NULL, $edit, "field_document_0_upload_button"); |
||
| 163 | $fid = (string) current($this->xpath('//input[@data-drupal-selector="edit-field-document-0-fids"]/@value')); |
||
| 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, |
||
| 169 | ]; |
||
| 170 | $this->drupalPostForm(NULL, $edit, t('Save and publish')); |
||
| 171 | $thumbnail = $this->getMostRecentThumbnail(); |
||
| 172 | $this->assertEqual('public://media-icons/generic/application-vnd.oasis.opendocument.text.png', $thumbnail, "Correct thumbnail detected for ODT File."); |
||
| 173 | |||
| 174 | // Test thumbnail of OTT file. |
||
| 175 | $file = drupal_get_path('module', 'media') . '/files/Test.ott'; |
||
| 176 | $this->drupalGet('media/add/document'); |
||
| 177 | $edit = [ |
||
| 178 | 'files[field_document_0]' => $file, |
||
| 179 | ]; |
||
| 180 | $this->drupalPostAjaxForm(NULL, $edit, "field_document_0_upload_button"); |
||
| 181 | $fid = (string) current($this->xpath('//input[@data-drupal-selector="edit-field-document-0-fids"]/@value')); |
||
| 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, |
||
| 187 | ]; |
||
| 188 | $this->drupalPostForm(NULL, $edit, t('Save and publish')); |
||
| 189 | $thumbnail = $this->getMostRecentThumbnail(); |
||
| 190 | $this->assertEqual('public://media-icons/generic/application-vnd.oasis.opendocument.text-template.png', $thumbnail, "Correct thumbnail detected for OTT File."); |
||
| 191 | |||
| 192 | // Test thumbnail of PPT file. |
||
| 193 | $file = drupal_get_path('module', 'media') . '/files/Test.ppt'; |
||
| 194 | $this->drupalGet('media/add/document'); |
||
| 195 | $edit = [ |
||
| 196 | 'files[field_document_0]' => $file, |
||
| 197 | ]; |
||
| 198 | $this->drupalPostAjaxForm(NULL, $edit, "field_document_0_upload_button"); |
||
| 199 | $fid = (string) current($this->xpath('//input[@data-drupal-selector="edit-field-document-0-fids"]/@value')); |
||
| 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, |
||
| 205 | ]; |
||
| 206 | $this->drupalPostForm(NULL, $edit, t('Save and publish')); |
||
| 207 | $thumbnail = $this->getMostRecentThumbnail(); |
||
| 208 | $this->assertEqual('public://media-icons/generic/application-vnd.ms-powerpoint.png', $thumbnail, "Correct thumbnail detected for PPT File."); |
||
| 209 | |||
| 210 | // Test thumbnail of PPTX file. |
||
| 211 | $file = drupal_get_path('module', 'media') . '/files/Test.pptx'; |
||
| 212 | $this->drupalGet('media/add/document'); |
||
| 213 | $edit = [ |
||
| 214 | 'files[field_document_0]' => $file, |
||
| 215 | ]; |
||
| 216 | $this->drupalPostAjaxForm(NULL, $edit, "field_document_0_upload_button"); |
||
| 217 | $fid = (string) current($this->xpath('//input[@data-drupal-selector="edit-field-document-0-fids"]/@value')); |
||
| 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, |
||
| 223 | ]; |
||
| 224 | $this->drupalPostForm(NULL, $edit, t('Save and publish')); |
||
| 225 | $thumbnail = $this->getMostRecentThumbnail(); |
||
| 226 | $this->assertEqual('public://media-icons/generic/application-vnd.openxmlformats-officedocument.presentationml.presentation.png', $thumbnail, "Correct thumbnail detected for PPTX File."); |
||
| 227 | |||
| 228 | // Test thumbnail of RTF file. |
||
| 229 | $file = drupal_get_path('module', 'media') . '/files/Test.rtf'; |
||
| 230 | $this->drupalGet('media/add/document'); |
||
| 231 | $edit = [ |
||
| 232 | 'files[field_document_0]' => $file, |
||
| 233 | ]; |
||
| 234 | $this->drupalPostAjaxForm(NULL, $edit, "field_document_0_upload_button"); |
||
| 235 | $fid = (string) current($this->xpath('//input[@data-drupal-selector="edit-field-document-0-fids"]/@value')); |
||
| 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, |
||
| 241 | ]; |
||
| 242 | $this->drupalPostForm(NULL, $edit, t('Save and publish')); |
||
| 243 | $thumbnail = $this->getMostRecentThumbnail(); |
||
| 244 | $this->assertEqual('public://media-icons/generic/application-rtf.png', $thumbnail, "Correct thumbnail detected for RTF File."); |
||
| 245 | |||
| 246 | // Test thumbnail of TXT file. |
||
| 247 | $file = drupal_get_path('module', 'media') . '/files/Test.txt'; |
||
| 248 | $this->drupalGet('media/add/document'); |
||
| 249 | $edit = [ |
||
| 250 | 'files[field_document_0]' => $file, |
||
| 251 | ]; |
||
| 252 | $this->drupalPostAjaxForm(NULL, $edit, "field_document_0_upload_button"); |
||
| 253 | $fid = (string) current($this->xpath('//input[@data-drupal-selector="edit-field-document-0-fids"]/@value')); |
||
| 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, |
||
| 259 | ]; |
||
| 260 | $this->drupalPostForm(NULL, $edit, t('Save and publish')); |
||
| 261 | $thumbnail = $this->getMostRecentThumbnail(); |
||
| 262 | $this->assertEqual('public://media-icons/generic/text-plain.png', $thumbnail, "Correct thumbnail detected for TXT File."); |
||
| 263 | |||
| 264 | // Test thumbnail of XLS file. |
||
| 265 | $file = drupal_get_path('module', 'media') . '/files/Test.xls'; |
||
| 266 | $this->drupalGet('media/add/document'); |
||
| 267 | $edit = [ |
||
| 268 | 'files[field_document_0]' => $file, |
||
| 269 | ]; |
||
| 270 | $this->drupalPostAjaxForm(NULL, $edit, "field_document_0_upload_button"); |
||
| 271 | $fid = (string) current($this->xpath('//input[@data-drupal-selector="edit-field-document-0-fids"]/@value')); |
||
| 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, |
||
| 277 | ]; |
||
| 278 | $this->drupalPostForm(NULL, $edit, t('Save and publish')); |
||
| 279 | $thumbnail = $this->getMostRecentThumbnail(); |
||
| 280 | $this->assertEqual('public://media-icons/generic/application-vnd.ms-excel.png', $thumbnail, "Correct thumbnail detected for XLS File."); |
||
| 281 | |||
| 282 | // Test thumbnail of XLSX file. |
||
| 283 | $file = drupal_get_path('module', 'media') . '/files/Test.xlsx'; |
||
| 284 | $this->drupalGet('media/add/document'); |
||
| 285 | $edit = [ |
||
| 286 | 'files[field_document_0]' => $file, |
||
| 287 | ]; |
||
| 288 | $this->drupalPostAjaxForm(NULL, $edit, "field_document_0_upload_button"); |
||
| 289 | $fid = (string) current($this->xpath('//input[@data-drupal-selector="edit-field-document-0-fids"]/@value')); |
||
| 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, |
||
| 295 | ]; |
||
| 296 | $this->drupalPostForm(NULL, $edit, t('Save and publish')); |
||
| 297 | $thumbnail = $this->getMostRecentThumbnail(); |
||
| 298 | $this->assertEqual('public://media-icons/generic/application-vnd.openxmlformats-officedocument.spreadsheetml.sheet.png', $thumbnail, "Correct thumbnail detected for XLSX File."); |
||
| 299 | } |
||
| 300 | |||
| 316 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.