You are here

WebformTest.php in Little helpers 7.2

Same filename and directory in other branches
  1. 7 tests/Webform/WebformTest.php

File

tests/Webform/WebformTest.php
View source
<?php

namespace Drupal\little_helpers\Test\Webform;

use Drupal\little_helpers\Webform\Webform;
use Upal\DrupalUnitTestCase;

/**
 * Test the webform node wrapper.
 */
class WebformTest extends DrupalUnitTestCase {

  /**
   * Create a node stub.
   */
  public static function nodeStub() {
    $webform['redirect_url'] = 'node/167';
    $webform['components'][1] = array(
      'cid' => '1',
      'form_key' => 'first_name',
      'name' => 'First name',
      'type' => 'textfield',
      'value' => '%get[p3]',
      'extra' => array(),
    );
    $webform['components'][2] = array(
      'cid' => '2',
      'form_key' => 'last_name',
      'name' => 'Last name',
      'type' => 'textfield',
      'value' => '%get[p4]',
      'extra' => array(),
    );
    $webform['components'][3] = array(
      'cid' => '3',
      'pid' => '0',
      'form_key' => 'email',
      'name' => 'Mail ',
      'type' => 'email',
      'value' => '%get[p5]',
      'extra' => array(),
    );
    $webform['components'][4] = array(
      'cid' => '4',
      'pid' => '0',
      'form_key' => 'your_message',
      'name' => 'Your message',
      'type' => 'fieldset',
      'value' => '',
      'extra' => array(),
    );
    $webform['components'][6] = array(
      'cid' => '6',
      'pid' => '4',
      'form_key' => 'email_subject',
      'name' => 'Subject',
      'type' => 'textfield',
      'value' => 'subject default value',
      'extra' => array(),
    );
    $webform['components'][7] = array(
      'cid' => '7',
      'pid' => '4',
      'form_key' => 'email_body',
      'name' => 'Your email',
      'type' => 'textarea',
      'value' => 'body default value',
      'extra' => array(),
    );
    return (object) array(
      'webform' => $webform,
    );
  }

  /**
   * Test getting components by component ID.
   */
  public function testComponentReturnsComponentArray() {
    $node = self::nodeStub();
    $webform = new Webform($node);
    $component = $webform
      ->component(6);
    $this
      ->assertEqual('email_subject', $component['form_key']);
  }

  /**
   * Test getting an unknown component.
   */
  public function testComponentReturnsNullForUnknownComponent() {
    $node = self::nodeStub();
    $webform = new Webform($node);
    $this
      ->assertNull($webform
      ->component(12));
  }

}

Classes

Namesort descending Description
WebformTest Test the webform node wrapper.