You are here

public function RestfulDiscoveryTestCase::testFieldDiscoveryAllowedValues in RESTful 7

Same name and namespace in other branches
  1. 7.2 tests/RestfulDiscoveryTestCase.test \RestfulDiscoveryTestCase::testFieldDiscoveryAllowedValues()

Field discovery allowed values.

File

tests/RestfulDiscoveryTestCase.test, line 143
Contains RestfulDiscoveryTestCase

Class

RestfulDiscoveryTestCase
@file Contains RestfulDiscoveryTestCase

Code

public function testFieldDiscoveryAllowedValues() {
  $handler = restful_get_restful_handler('test_articles', 1, 2);

  // Add entity reference fields.
  restful_test_add_fields('node', 'article');

  // Create 3 nodes.
  $expected_result = array();
  foreach (array(
    1,
    2,
    3,
  ) as $id) {
    $title = 'article' . '/' . $id;
    $settings = array(
      'title' => $title,
      'type' => 'article',
    );
    $node = $this
      ->drupalCreateNode($settings);
    $expected_result[$node->nid] = $title;
  }

  // Set widget to select list.
  $instance = field_info_instance('node', 'entity_reference_single', 'article');
  $instance['widget']['type'] = 'options_select';
  field_update_instance($instance);
  $result = $handler
    ->options();
  $this
    ->assertEqual($result['entity_reference_single']['form_element']['allowed_values'], $expected_result);

  // Set widget to autocomplete.
  $instance['widget']['type'] = 'entityreference_autocomplete';
  field_update_instance($instance);

  // Invalidate public fields cache.
  $handler
    ->setPublicFields(array());
  $result = $handler
    ->options();
  $this
    ->assertNull($result['entity_reference_single']['form_element']['allowed_values']);
}