You are here

public function NodeReferenceFormTest::runReferenceableNodeTest in References 7.2

Function to run Referenceable Node Test.

2 calls to NodeReferenceFormTest::runReferenceableNodeTest()
NodeReferenceFormTest::testReferenceableNodeTypesAll in node_reference/node_reference.test
Test unlimited referencing.
NodeReferenceFormTest::testReferenceableNodeTypesOne in node_reference/node_reference.test
Test referencing a limited list of node types.

File

node_reference/node_reference.test, line 69
Initial node_reference tests.

Class

NodeReferenceFormTest
Unit tests for referenceability of node types in entity forms.

Code

public function runReferenceableNodeTest($allowed, $group) {
  field_update_field(array(
    'field_name' => $this->field_name,
    'settings' => array(
      'referenceable_types' => array_keys($allowed),
    ),
  ));
  $entity = field_test_create_stub_entity();
  $form = drupal_get_form('field_test_entity_form', $entity);
  $options = $form[$this->field_name][$this->langcode]['#options'];
  $this
    ->assertTrue(isset($options['_none']), t('Empty choice offered for reference'), $group);
  unset($options['_none']);
  foreach ($this->nodes as $node) {
    if (isset($allowed[$node->type])) {
      $this
        ->assertTrue(isset($options[$node->nid]), t('Node of type @type is referenceable', array(
        '@type' => $node->type,
      )), $group);
    }
    else {
      $this
        ->assertFalse(isset($options[$node->nid]), t('Node of type @type is not referenceable', array(
        '@type' => $node->type,
      )), $group);
    }
    unset($options[$node->nid]);
  }
  $this
    ->assertTrue(empty($options), t('No extra choice is referenceable'), $group);
}