You are here

public function ServicesResourceWebformTests::testEndpointWebformCreate in Webform Service 7.4

Testing webform Create.

File

tests/ServicesResourceWebformTests.test, line 280

Class

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

Code

public function testEndpointWebformCreate() {

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

  // Create the form.
  $form = $this
    ->createForm($components);
  $this
    ->assertTrue(isset($form->uuid), t('Webform was successfully created'), 'Webform: Create');
  $webform = webform_service_resource_load($form->uuid);
  $this
    ->assertTrue($webform->title = 'testing', t('Title was the same'), 'Webform: Create');
  $this
    ->assertTrue($webform->body = 'testing body', t('Body was the same'), 'Webform: Create');

  // Now make sure the webform was created.
  $this
    ->assertTrue(!empty($webform->webform), t('Webform created.'), 'Webform: Create');
  $this
    ->assertTrue(!empty($webform->webform['components']), t('Components created.'), 'Webform: Create');
  $this
    ->assertTrue(count($webform->webform['components']) === 3, t('Number of components created.'), 'Webform: Create');
  foreach ($components as $cid => $component) {
    $this
      ->assertTrue(!empty($webform->webform['components'][$cid]), 'Component was created', 'Webform: Create');
    $this
      ->assertTrue($webform->webform['components'][$cid]['form_key'] == $component['form_key'], t('Components match.'), 'Webform: Create');
  }
}