You are here

protected function ServicesEntityBasic::assertFieldPropertyFetching in Services Entity API 7

1 call to ServicesEntityBasic::assertFieldPropertyFetching()
ServicesEntityBasic::testPropertyFetchingFromFields in tests/services_entity.test

File

tests/services_entity.test, line 360

Class

ServicesEntityBasic

Code

protected function assertFieldPropertyFetching(array $cases) {
  foreach ($cases as $case_name => $case) {

    // Create the field.
    $field_info = $case['field'];
    $field_info['field_name'] = $case_name;
    field_create_field($field_info);
    $instance_info = array(
      'entity_type' => 'node',
      'bundle' => 'article',
      'field_name' => $field_info['field_name'],
    );
    field_create_instance($instance_info);

    // Proceed with the test cases.
    foreach ($case['expected'] as $expected) {
      $node = (object) array(
        'title' => 'Test node',
        'type' => 'article',
        'uid' => $this->adminUser->uid,
        'status' => 1,
        $case_name => $expected['content'],
      );
      node_save($node);
      $property = $case_name;
      $fields = _services_entity_transform_fields(array(
        $case_name => $case_name,
      ));
      $wrapper = entity_metadata_wrapper('node', $node);
      $result = services_entity_prepare_structure($wrapper, $fields);
      $path = explode(':', $property);
      $base_element = reset($path);
      $this
        ->verbose("<pre>Expected: " . print_r($expected['result'], TRUE) . "\n\nReturned: " . print_r($result[$base_element], TRUE) . "</pre>");
      $this
        ->assertEqual($expected['result'], $result[$base_element], t('Case @case, property @property returned expected result', array(
        '@case' => $case_name,
        '@property' => $property,
      )));
    }
  }
}