diff -u b/restws.formats.inc b/restws.formats.inc --- b/restws.formats.inc +++ b/restws.formats.inc @@ -275,6 +275,9 @@ else { $list_type = entity_property_list_extract_type($info['type']); foreach ($property_value as &$list_value) { + if (!(is_array($list_value))) { + continue; + } $list_value = $this->getResourceReferenceValue($list_type, $list_value); } } @@ -285,6 +288,9 @@ $this->getPropertyValues($property_value, $info['property info']); } else { + if (!(is_array($property_value))) { + continue; + } $property_value = $this->getResourceReferenceValue($info['type'], $property_value); } } @@ -331,10 +337,6 @@ } return reset($ids); } - else - { - return $reference; - } throw new RestWSException('Invalid value for resource reference given.', 406); } diff -u b/restws.test b/restws.test --- b/restws.test +++ b/restws.test @@ -16,32 +16,58 @@ } public function setUp() { - parent::setUp('restws', 'entity', 'entity_test', 'locale'); + parent::setUp('restws'); - // Create a field having 4 values for testing multiple value support. - $this->field_name = drupal_strtolower($this->randomName() . '_field_name'); - $this->field = array('field_name' => $this->field_name, 'type' => 'text', 'cardinality' => 4); - $this->field = field_create_field($this->field); - $this->field_id = $this->field['id']; - $this->instance = array( - 'field_name' => $this->field_name, + // Create a text field having 2 values, and a list_text field having + // unlimited values for testing multiple value support. + field_create_field(array( + 'field_name' => 'field_text_test', + 'type' => 'text', + 'cardinality' => 2, + )); + field_create_instance(array( + 'field_name' => 'field_text_test', 'entity_type' => 'node', 'bundle' => 'page', - 'label' => $this->randomName() . '_label', - 'description' => $this->randomName() . '_description', - 'weight' => mt_rand(0, 127), + 'label' => 'Test text field', + 'description' => '', + 'weight' => 0, 'settings' => array( 'text_processing' => FALSE, ), 'widget' => array( 'type' => 'text_textfield', - 'label' => 'Test Field', + 'label' => 'Test text field', 'settings' => array( 'size' => 64, ) ) - ); - field_create_instance($this->instance); + )); + field_create_field(array( + 'field_name' => 'field_list_text_test', + 'type' => 'list_text', + 'cardinality' => -1, + 'settings' => array( + 'allowed_values' => array( + 'test1' => 'Test 1', + 'test2' => 'Test 2', + ), + ), + )); + field_create_instance(array( + 'field_name' => 'field_list_text_test', + 'entity_type' => 'node', + 'bundle' => 'page', + 'label' => 'Test list text field', + 'description' => '', + 'weight' => 0, + 'settings' => array(), + 'widget' => array( + 'module' => 'options', + 'settings' => array(), + 'type' => 'options_buttons', + ) + )); } /** @@ -78,22 +104,26 @@ $this->assertResponse('201', 'HTTP response code is correct.'); $this->assertEqual(curl_getinfo($this->curlHandle, CURLINFO_CONTENT_TYPE), 'application/json', 'HTTP content type is correct.'); - // Test Create node with multi value field. - $multivaluefield = array(array('value' => $this->randomName(8),), array('value' => $this->randomName(8),), array('value' => $this->randomName(8),), array('value' => $this->randomName(8),)); + // Test Create node with multi value fields. + $field_text_test_values = array('test1', 'test2'); + $field_list_text_test_values = array('test1', 'test2'); $new_node = array( 'body' => array(LANGUAGE_NONE => array(array())), 'title' => $title, 'type' => 'page', 'author' => $account->uid, - $this->field_name => $multivaluefield, + 'field_text_test' => $field_text_test_values, + 'field_list_text_test' => $field_list_text_test_values, ); $json = drupal_json_encode($new_node); $result = $this->httpRequest('node', 'POST', $account, $json); $result_array = drupal_json_decode($result); $nid = $result_array['id']; $node2 = node_load($nid); - $this->assertEqual($multivaluefield[0]['value'], $node2->{$this->field_name}['und'][0]['value'], 'Multi-value field from DB is equal to the new multi-value field. Value 1.'); - $this->assertEqual($multivaluefield[1]['value'], $node2->{$this->field_name}['und'][1]['value'], 'Multi-value field from DB is equal to the new multi-value field. Value 2.'); + $this->assertEqual($field_text_test_values[0], $node2->field_text_test['und'][0]['value'], 'Multi-value text field from DB is equal to the posted JSON value. Value 1.'); + $this->assertEqual($field_text_test_values[1], $node2->field_text_test['und'][1]['value'], 'Multi-value text field from DB is equal to the posted JSON value. Value 2.'); + $this->assertEqual($field_list_text_test_values[0], $node2->field_list_text_test['und'][0]['value'], 'Multi-value list_text field from DB is equal to the posted JSON value. Value 1.'); + $this->assertEqual($field_list_text_test_values[1], $node2->field_list_text_test['und'][1]['value'], 'Multi-value list_text field from DB is equal to the posted JSON value. Value 2.'); $this->assertResponse('201', 'HTTP response code is correct.'); $this->assertEqual(curl_getinfo($this->curlHandle, CURLINFO_CONTENT_TYPE), 'application/json', 'HTTP content type is correct.');