You are here

public function EntityReferenceTaxonomyTestCase::testNodeIndex in Entity reference 7

Test referencing a term using entity reference field.

File

tests/entityreference.taxonomy.test, line 83

Class

EntityReferenceTaxonomyTestCase
Test for Entity Reference taxonomy integration.

Code

public function testNodeIndex() {

  // Asert node insert with reference to term.
  $settings = array();
  $settings['type'] = 'article';
  $settings['field_entityreference_term'][LANGUAGE_NONE][0]['target_id'] = 1;
  $node = $this
    ->drupalCreateNode($settings);
  $this
    ->assertEqual(taxonomy_select_nodes(1), array(
    $node->nid,
  ));

  // Asert node update with reference to term.
  node_save($node);
  $this
    ->assertEqual(taxonomy_select_nodes(1), array(
    $node->nid,
  ));

  // Assert node update with reference to term and taxonomy reference to
  // another term.
  $wrapper = entity_metadata_wrapper('node', $node);
  $wrapper->field_taxonomy_term
    ->set(2);
  $wrapper
    ->save();
  $this
    ->assertEqual(taxonomy_select_nodes(1), array(
    $node->nid,
  ));
  $this
    ->assertEqual(taxonomy_select_nodes(2), array(
    $node->nid,
  ));

  // Assert node update with reference to term and taxonomy reference to
  // same term.
  $wrapper->field_taxonomy_term
    ->set(1);
  $wrapper
    ->save();
  $this
    ->assertEqual(taxonomy_select_nodes(1), array(
    $node->nid,
  ));
  $wrapper
    ->delete();
  $this
    ->assertFalse(taxonomy_select_nodes(1));
}