comparison core/modules/file/src/Tests/FileFieldWidgetTest.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents 4c8ae668cc8c
children 129ea1e6d783
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
158 // does not yet emulate jQuery's file upload. 158 // does not yet emulate jQuery's file upload.
159 // 159 //
160 $this->drupalGet("node/add/$type_name"); 160 $this->drupalGet("node/add/$type_name");
161 foreach ([$field_name2, $field_name] as $each_field_name) { 161 foreach ([$field_name2, $field_name] as $each_field_name) {
162 for ($delta = 0; $delta < 3; $delta++) { 162 for ($delta = 0; $delta < 3; $delta++) {
163 $edit = ['files[' . $each_field_name . '_' . $delta . '][]' => drupal_realpath($test_file->getFileUri())]; 163 $edit = ['files[' . $each_field_name . '_' . $delta . '][]' => \Drupal::service('file_system')->realpath($test_file->getFileUri())];
164 // If the Upload button doesn't exist, drupalPostForm() will automatically 164 // If the Upload button doesn't exist, drupalPostForm() will automatically
165 // fail with an assertion message. 165 // fail with an assertion message.
166 $this->drupalPostForm(NULL, $edit, t('Upload')); 166 $this->drupalPostForm(NULL, $edit, t('Upload'));
167 } 167 }
168 } 168 }
371 $node = $this->drupalGetNodeByTitle($edit['title[0][value]']); 371 $node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
372 372
373 // Add a comment with a file. 373 // Add a comment with a file.
374 $text_file = $this->getTestFile('text'); 374 $text_file = $this->getTestFile('text');
375 $edit = [ 375 $edit = [
376 'files[field_' . $name . '_' . 0 . ']' => drupal_realpath($text_file->getFileUri()), 376 'files[field_' . $name . '_' . 0 . ']' => \Drupal::service('file_system')->realpath($text_file->getFileUri()),
377 'comment_body[0][value]' => $comment_body = $this->randomMachineName(), 377 'comment_body[0][value]' => $comment_body = $this->randomMachineName(),
378 ]; 378 ];
379 $this->drupalPostForm('node/' . $node->id(), $edit, t('Save')); 379 $this->drupalPostForm('node/' . $node->id(), $edit, t('Save'));
380 380
381 // Get the comment ID. 381 // Get the comment ID.
427 $test_file_text = $this->getTestFile('text'); 427 $test_file_text = $this->getTestFile('text');
428 $test_file_image = $this->getTestFile('image'); 428 $test_file_image = $this->getTestFile('image');
429 $name = 'files[' . $field_name . '_0]'; 429 $name = 'files[' . $field_name . '_0]';
430 430
431 // Upload file with incorrect extension, check for validation error. 431 // Upload file with incorrect extension, check for validation error.
432 $edit[$name] = drupal_realpath($test_file_image->getFileUri()); 432 $edit[$name] = \Drupal::service('file_system')->realpath($test_file_image->getFileUri());
433 switch ($type) { 433 switch ($type) {
434 case 'nojs': 434 case 'nojs':
435 $this->drupalPostForm(NULL, $edit, t('Upload')); 435 $this->drupalPostForm(NULL, $edit, t('Upload'));
436 break; 436 break;
437 case 'js': 437 case 'js':
441 } 441 }
442 $error_message = t('Only files with the following extensions are allowed: %files-allowed.', ['%files-allowed' => 'txt']); 442 $error_message = t('Only files with the following extensions are allowed: %files-allowed.', ['%files-allowed' => 'txt']);
443 $this->assertRaw($error_message, t('Validation error when file with wrong extension uploaded (JSMode=%type).', ['%type' => $type])); 443 $this->assertRaw($error_message, t('Validation error when file with wrong extension uploaded (JSMode=%type).', ['%type' => $type]));
444 444
445 // Upload file with correct extension, check that error message is removed. 445 // Upload file with correct extension, check that error message is removed.
446 $edit[$name] = drupal_realpath($test_file_text->getFileUri()); 446 $edit[$name] = \Drupal::service('file_system')->realpath($test_file_text->getFileUri());
447 switch ($type) { 447 switch ($type) {
448 case 'nojs': 448 case 'nojs':
449 $this->drupalPostForm(NULL, $edit, t('Upload')); 449 $this->drupalPostForm(NULL, $edit, t('Upload'));
450 break; 450 break;
451 case 'js': 451 case 'js':