You are here

function WebformGeneralTestCase::testWebformCreateNewType in Webform 6.3

Same name and namespace in other branches
  1. 7.4 tests/WebformGeneralTestCase.test \WebformGeneralTestCase::testWebformCreateNewType()
  2. 7.3 tests/webform.test \WebformGeneralTestCase::testWebformCreateNewType()

Test webform-enabling a different node type and testing behavior.

File

tests/webform.test, line 763
Webform module tests.

Class

WebformGeneralTestCase
Test general functionality of Webform.

Code

function testWebformCreateNewType() {

  // Enable webforms on the page content type.
  variable_set('webform_node_types', array(
    'webform',
    'page',
  ));
  $settings = array(
    'title' => 'Test webform-enabled page',
    'type' => 'page',
  );
  $node = $this
    ->drupalCreateNode($settings);

  // Because this is a webform-enabled type node but does not yet have any
  // components, it should not have an entry in the database because it is
  // using the default settings.
  $this
    ->assertFalse($this
    ->webformRecordExists($node->nid), t('Webform record not in the database for the new page node.'));

  // Make a change to the node, ensure that the record stays empty.
  $node->title .= '!';
  node_save($node);
  $this
    ->assertFalse($this
    ->webformRecordExists($node->nid), t('Webform record still not in the database after modifying page node.'));

  // Add a new component to the node and check that a record is made in the
  // webform table.
  $components = $this
    ->testWebformComponents();
  $textarea = $components['textarea'];
  $textarea['type'] = 'textarea';
  $textarea['form_key'] = 'textarea';
  $textarea['cid'] = 1;
  $textarea['pid'] = 0;
  $textarea = array_merge(webform_component_invoke('textarea', 'defaults'), $textarea);
  $node->webform['components'][1] = $textarea;
  node_save($node);
  $this
    ->assertTrue($this
    ->webformRecordExists($node->nid), t('Webform record now exists after adding a new component.'));

  // Remove the new component and ensure that the record is deleted.
  $node->webform['components'] = array();
  node_save($node);
  $this
    ->assertFalse($this
    ->webformRecordExists($node->nid), t('Webform record deleted after deleting last component.'));
}