You are here

phonefield.test in Phone Field 7

Phonefield base test file. Common functions for testing phonefields.

File

tests/phonefield.test
View source
<?php

/**
 * @file
 * Phonefield base test file. Common functions for testing phonefields.
 */

/**
 * Base Test Class.
 */
class PhonefieldBaseTestClass extends DrupalWebTestCase {
  protected $permissions = array(
    'access content',
    'administer content types',
    'administer fields',
    'administer nodes',
    'administer filters',
    'access comments',
    'post comments',
    'access administration pages',
    'create page content',
  );

  /**
   * Setup.
   */
  public function setUp() {
    $modules = func_get_args();
    $modules = isset($modules[0]) && is_array($modules[0]) ? $modules[0] : $modules;
    $modules[] = 'field';
    $modules[] = 'phonefield';
    parent::setUp($modules);
    $this->web_user = $this
      ->drupalCreateUser($this->permissions);
    $this
      ->drupalLogin($this->web_user);
  }

  /**
   * Create phonefield Field.
   */
  protected function createPhonefieldField($node_type = 'page', $settings = array()) {
    $name = strtolower($this
      ->randomName());
    $edit = array(
      'fields[_add_new_field][label]' => $name,
      'fields[_add_new_field][field_name]' => $name,
      'fields[_add_new_field][type]' => 'phonefield_field',
      'fields[_add_new_field][widget_type]' => 'phonefield_field',
    );
    $field_name = 'field_' . $name;
    $this
      ->drupalPost('admin/structure/types/manage/' . $node_type . '/fields', $edit, t('Save'));
    $this
      ->drupalPost(NULL, array(), t('Save field settings'));
    $this
      ->drupalPost(NULL, $settings, t('Save settings'));

    // Is field created?
    $this
      ->assertRaw(t('Saved %label configuration', array(
      '%label' => $name,
    )), 'Field added');
    node_types_rebuild();
    menu_rebuild();
    return $field_name;
  }

}

Classes

Namesort descending Description
PhonefieldBaseTestClass Base Test Class.