'Entity Reference form fields', 'description' => 'Tests assigning an entity reference via form.', 'group' => 'Entity Reference', ); } public function setUp() { parent::setUp(); // Create the article content type. if ($this->profile != 'standard') { $this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article')); } for ($i = 0; $i < 5; $i++) { $node = entity_create('node', array( 'title' => $this->randomName(), 'type' => 'article', 'langcode' => Language::LANGCODE_NOT_SPECIFIED, )); $node->save(); } $settings = array( 'field_name' => 'field_test_node', 'type' => 'entity_reference', 'cardinality' => -1, 'settings' => array( 'target_type' => 'node', ), ); $field = entity_create('field_entity', $settings); $field->save(); $instance = array( 'field_name' => 'field_test_node', 'entity_type' => 'node', 'label' => 'Node test field', 'bundle' => 'article', ); $field_instance = entity_create('field_instance', $instance); $field_instance->save(); // Tell the form system how to behave. entity_get_form_display('node', 'article', 'default') ->setComponent('field_test_node', array( 'type' => 'options_buttons', )) ->save(); } function testEntityReferenceField() { $this->admin_user = $this->drupalCreateUser(array('access content', 'bypass node access', 'create article content', 'edit any article content')); $this->drupalLogin($this->admin_user); $this->drupalGet('node/add/article'); // Try to post a node, assigned to the first two terms. $edit['title'] = 'Test node'; $edit["field_test_node[und][1]"] = TRUE; $edit["field_test_node[und][2]"] = TRUE; $this->drupalPost('node/add/article', $edit, 'Save'); $this->assertResponse(200); $node = node_load(6); $this->assertTrue(count($node->field_test_node['und']) == 2, 'Node saved with two node reference records.'); } }