You are here

public function ServicesResourceWebformTests::testEndpointWebformUpdate in Webform Service 7.4

Testing webform Update.

File

tests/ServicesResourceWebformTests.test, line 312

Class

ServicesResourceWebformTests
Run test cases for the endpoint with no authentication turned on.

Code

public function testEndpointWebformUpdate() {

  // Create and log in our privileged user.
  $this->privilegedUser = $this
    ->drupalCreateUser(array(
    'administer services',
    'bypass node access',
  ));
  $this
    ->drupalLogin($this->privilegedUser);

  // Create the form.
  $components = $this->form_components;
  $form = $this
    ->createForm($components);
  $webform = webform_service_resource_load($form->uuid);

  // Make sure we start with 3 components.
  $this
    ->assertTrue(count($webform->webform['components']) == 3);

  // Add a new component.
  $webform->webform['components'][] = array(
    'form_key' => 'middle_name',
    'type' => 'textfield',
    'name' => 'Middle Name',
  );

  // Get the endpoint.
  $endpoint = $this->endpoint->path . '/' . $webform->type . '/' . $webform->uuid;
  $responseArray = $this
    ->servicesPut($endpoint, (array) $webform);
  $response = $responseArray['body'];

  // Make sure we have 4 comonents now.
  $this
    ->assertTrue(count($response->webform['components']) == 4);
  $this
    ->assertTrue(!empty($response->webform['components'][4]['cid']));
  $this
    ->assertTrue($response->webform['components'][4]['form_key'] == 'middle_name');
  $this
    ->assertTrue($response->webform['components'][4]['name'] == 'Middle Name');
  $this
    ->assertTrue($response->webform['components'][4]['type'] == 'textfield');

  // Now edit the name of an existing field.
  $webform = webform_service_resource_load($form->uuid, TRUE);
  $webform->webform['components'][2]['name'] = 'Testing';
  $responseArray = $this
    ->servicesPut($endpoint, (array) $webform);
  $response = $responseArray['body'];

  // Make sure the name updates.
  $this
    ->assertTrue($response->webform['components'][2]['name'] == 'Testing');
}