Tripal
Public Member Functions | Public Attributes | List of all members
TripalFieldTestHelper Class Reference

Public Member Functions

 __construct ($bundle_name, $machine_names, $entity, $field_info, $instance_info)
 
 getInitializedClass ()
 
 getFieldInfo ($field_name)
 
 getInstanceInfo ($bundle_name, $field_name)
 
 mockElement ($delta=0, $langcode=LANGUAGE_NONE, $required=FALSE)
 
 mockForm ()
 
 mockFormState ($delta=0, $langcode=LANGUAGE_NONE, $values=NULL)
 

Public Attributes

 $initialized_class
 
 $class_name
 
 $field_info
 
 $instance_info
 
 $bundle
 
 $entity
 
 $type
 
 $field_name
 

Detailed Description

This class can be included at the top of your TripalTestCase to facillitate testing fields, widgets and formatters.

Constructor & Destructor Documentation

◆ __construct()

TripalFieldTestHelper::__construct (   $bundle_name,
  $machine_names,
  $entity,
  $field_info,
  $instance_info 
)

Create an instance of TripalFieldTestHelper.

Specifcally, initialize the widget class and save it for further testing.

Parameters
$bundle_nameThe name of the bundle the field should be attached to. This bundle must already exist.
$machine_namesAn array of machine names including:
  • field_name: the name of the field (REQUIRED)
  • widget_name: the name of the widget (Only required for widget testing)
  • formatter_name: the name of the formatter (Only required for formatter testing)
$field_infoThe Drupal information for the field you want to test.
$instance_infoThe Drupal information for the field instance you want to test.

Member Function Documentation

◆ getFieldInfo()

TripalFieldTestHelper::getFieldInfo (   $field_name)

Retrieve the field information for a given field.

See also
https://api.drupal.org/api/drupal/modules%21field%21field.info.inc/function/field_info_field/7.x
Parameters
$field_nameThe name of the field to retrieve. $field_name can only refer to a non-deleted, active field.
Returns
The field array as returned by field_info_field() and used when initializing this class.

◆ getInitializedClass()

TripalFieldTestHelper::getInitializedClass ( )

Retrieve the initialized class for testing!

◆ getInstanceInfo()

TripalFieldTestHelper::getInstanceInfo (   $bundle_name,
  $field_name 
)

Retrieve the field instance information for a given field.

See also
https://api.drupal.org/api/drupal/modules%21field%21field.info.inc/function/field_info_instance/7.x
Parameters
$bundle_nameThe name of the bundle you want the field attached to. For example, bio_data_1.
$field_nameThe name of the field to retrieve the instance of. $field_name can only refer to a non-deleted, active field.
Returns
The field instance array as returned by field_info_instance() and used when initializing this class.

◆ mockElement()

TripalFieldTestHelper::mockElement (   $delta = 0,
  $langcode = LANGUAGE_NONE,
  $required = FALSE 
)

Create a fake version of the $element parameter used in many field methods (e.g. TripalFieldWidget::form).

Parameters
$deltaThe delta for the $element you want to fake.
$langcodeThe language code for the field/widget. This should usually be LANGUAGE_NONE.
$requiredTrue if the widget is required and false otherwise.
Returns
A fake $element variable for use in testing.

◆ mockForm()

TripalFieldTestHelper::mockForm ( )

Create a fake version of the create/edit content form with the current entity attached.

Returns
A fake $form array for use in testing.

◆ mockFormState()

TripalFieldTestHelper::mockFormState (   $delta = 0,
  $langcode = LANGUAGE_NONE,
  $values = NULL 
)

Create a fake version of the create/edit content form_state with the current entity attached.

Parameters
$deltaThe delta for the $element you want to fake.
$langcodeThe language code for the field/widget. This should usually be LANGUAGE_NONE.
$valuesAn array of values where the key is the form element name and the value is the fake user submmitted value.
Returns
A fake $form_state array for use in testing.

The documentation for this class was generated from the following file: