diff --git a/restws.test b/restws.test index 3069f5d..42c14bb 100644 --- a/restws.test +++ b/restws.test @@ -17,6 +17,57 @@ class RestWSTestCase extends DrupalWebTestCase { public function setUp() { parent::setUp('restws'); + + // 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' => 'Test text field', + 'description' => '', + 'weight' => 0, + 'settings' => array( + 'text_processing' => FALSE, + ), + 'widget' => array( + 'type' => 'text_textfield', + 'label' => 'Test text field', + 'settings' => array( + 'size' => 64, + ) + ) + )); + 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', + ) + )); } /** @@ -53,6 +104,29 @@ class RestWSTestCase extends DrupalWebTestCase { $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 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, + '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($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.'); + // Test Update. $new_title = $this->randomName(8); $json = drupal_json_encode(array('title' => $new_title));