Chris@0: drupalCreateContentType(); Chris@0: $this->referencingType = $referencing->id(); Chris@0: Chris@0: $referenced = $this->drupalCreateContentType(); Chris@0: $this->referencedType = $referenced->id(); Chris@0: $this->nodeId = $this->drupalCreateNode(['type' => $referenced->id()])->id(); Chris@0: Chris@0: FieldStorageConfig::create([ Chris@0: 'field_name' => 'test_field', Chris@0: 'entity_type' => 'node', Chris@0: 'translatable' => FALSE, Chris@0: 'entity_types' => [], Chris@0: 'settings' => [ Chris@0: 'target_type' => 'node', Chris@0: ], Chris@0: 'type' => 'entity_reference', Chris@0: 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, Chris@0: ])->save(); Chris@0: Chris@0: FieldConfig::create([ Chris@0: 'label' => 'Entity reference field', Chris@0: 'field_name' => 'test_field', Chris@0: 'entity_type' => 'node', Chris@0: 'required' => TRUE, Chris@0: 'bundle' => $referencing->id(), Chris@0: 'settings' => [ Chris@0: 'handler' => 'default', Chris@0: 'handler_settings' => [ Chris@0: // Reference a single vocabulary. Chris@0: 'target_bundles' => [ Chris@0: $referenced->id(), Chris@0: ], Chris@0: ], Chris@0: ], Chris@0: ])->save(); Chris@0: Chris@0: Chris@0: // Create a file field. Chris@0: $file_field_name = 'file_field'; Chris@0: $field_storage = FieldStorageConfig::create([ Chris@0: 'field_name' => $file_field_name, Chris@0: 'entity_type' => 'node', Chris@0: 'type' => 'file' Chris@0: ]); Chris@0: $field_storage->save(); Chris@0: FieldConfig::create([ Chris@0: 'entity_type' => 'node', Chris@0: 'field_storage' => $field_storage, Chris@0: 'bundle' => $referencing->id(), Chris@0: 'label' => $this->randomMachineName() . '_label', Chris@0: ])->save(); Chris@0: Chris@0: entity_get_display('node', $referencing->id(), 'default') Chris@0: ->setComponent('test_field') Chris@0: ->setComponent($file_field_name) Chris@0: ->save(); Chris@0: entity_get_form_display('node', $referencing->id(), 'default') Chris@0: ->setComponent('test_field', [ Chris@0: 'type' => 'entity_reference_autocomplete', Chris@0: ]) Chris@0: ->setComponent($file_field_name, [ Chris@0: 'type' => 'file_generic', Chris@0: ]) Chris@0: ->save(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests that the autocomplete input element does not cause ajax fatal. Chris@0: */ Chris@0: public function testFileUpload() { Chris@0: $user1 = $this->drupalCreateUser(['access content', "create $this->referencingType content"]); Chris@0: $this->drupalLogin($user1); Chris@0: Chris@0: $test_file = current($this->drupalGetTestFiles('text')); Chris@0: $edit['files[file_field_0]'] = drupal_realpath($test_file->uri); Chris@0: $this->drupalPostForm('node/add/' . $this->referencingType, $edit, 'Upload'); Chris@0: $this->assertResponse(200); Chris@0: $edit = [ Chris@0: 'title[0][value]' => $this->randomMachineName(), Chris@0: 'test_field[0][target_id]' => $this->nodeId, Chris@0: ]; Chris@0: $this->drupalPostForm(NULL, $edit, 'Save'); Chris@0: $this->assertResponse(200); Chris@0: } Chris@0: Chris@0: }