You are here

function TaxonomyAccessTestCase::createField in Taxonomy Access Control 7

Creates a taxonomy field and adds it to the page content type.

Parameters

string $machine_name: The machine name of the vocabulary to use.

string $widget: (optional) The name of the widget to use. Defaults to 'options_select'.

int $count: (optional) The allowed number of values. Defaults to unlimited.

Return value

array Array of instance data.

3 calls to TaxonomyAccessTestCase::createField()
TaxonomyAccessConfigTest::setUp in ./taxonomy_access.test
Sets up a Drupal site for running functional and integration tests.
TaxonomyAccessNodeGrantTest::setUp in ./taxonomy_access.test
Sets up a Drupal site for running functional and integration tests.
TaxonomyAccessTermGrantTest::setUp in ./taxonomy_access.test
Sets up a Drupal site for running functional and integration tests.

File

./taxonomy_access.test, line 147
Automated tests for the Taxonomy Access Control module.

Class

TaxonomyAccessTestCase
Provides a base test class and helper methods for automated tests.

Code

function createField($machine_name, $widget = 'options_select', $count = FIELD_CARDINALITY_UNLIMITED) {
  $field = array(
    'field_name' => $machine_name,
    'type' => 'taxonomy_term_reference',
    'cardinality' => $count,
    'settings' => array(
      'allowed_values' => array(
        array(
          'vocabulary' => $machine_name,
          'parent' => 0,
        ),
      ),
    ),
  );
  $field = field_create_field($field);
  $instance = array(
    'field_name' => $machine_name,
    'bundle' => 'page',
    'entity_type' => 'node',
    'widget' => array(
      'type' => $widget,
    ),
    'display' => array(
      'default' => array(
        'type' => 'taxonomy_term_reference_link',
      ),
    ),
  );
  return field_create_instance($instance);
}