You are here

webform_default_fields.test in Webform Default Fields 7.4

Webform Default Fields module tests.

File

tests/webform_default_fields.test
View source
<?php

/**
 * @file
 * Webform Default Fields module tests.
 */

/**
 * Tests the module functionality.
 */
class WebformDefaultFieldsTestCase extends DrupalWebTestCase {
  private $contentType = 'webform';
  private $fieldCounter = 0;

  /**
   * Implements getInfo().
   */
  public static function getInfo() {
    return array(
      'name' => t('Webform Default Fields'),
      'description' => t('Adds a node and check it has default webform fields.'),
      'group' => t('Webform Default Fields'),
    );
  }

  /**
   * Implements setUp().
   */
  public function setUp() {

    // Enable Webform Default Fields.
    parent::setUp('webform_default_fields', 'webform');
    module_enable(array(
      'webform_default_fields',
      'webform',
    ));
    module_load_include('inc', 'webform', 'includes/webform.components');
  }

  /**
   * Add field to node.
   */
  private function addTestComponent() {
    $nid = _webform_default_fields_container_node($this->contentType);
    $component = array(
      'nid' => $nid,
      'pid' => 0,
      'form_key' => $this->fieldCounter . uniqid(),
      'name' => 'Test field ' . $this->fieldCounter,
      'type' => 'textfield',
      'extra' => array(
        'title_display' => 'before',
        'disabled' => 0,
        'unique' => 0,
        'conditional_operator' => '=',
      ),
      'mandatory' => 0,
      'weight' => $this->fieldCounter,
    );
    webform_component_insert($component);
    $this->fieldCounter++;
  }

  /**
   * Implemenation of tearDown().
   */
  public function tearDown() {
    module_disable(array(
      'webform_default_fields',
      'webform',
    ));
    variable_set('webform_default_fields_nid_' . $this->contentType, 0);
    $this->_counter = 0;
    parent::tearDown();
  }

  /**
   * Test adding field to node.
   */
  public function testNodeAdding() {
    $this
      ->addTestComponent();
    $new_node = new stdClass();
    $new_node->type = $this->contentType;
    node_save($new_node);
    $this
      ->assertEqual(1, count($new_node->webform['components']));
  }

  /**
   * Test adding two fields to node.
   */
  public function testNodeAddingWithTwoFields() {
    $this
      ->addTestComponent();
    $this
      ->addTestComponent();
    $new_node = new stdClass();
    $new_node->type = $this->contentType;
    node_save($new_node);
    $this
      ->assertEqual(2, count($new_node->webform['components']));
  }

}

Classes

Namesort descending Description
WebformDefaultFieldsTestCase Tests the module functionality.