You are here

relation_entity_collector.test in Relation 7

Tests for Relation Entity Collector module.

File

relation_entity_collector/tests/relation_entity_collector.test
View source
<?php

/**
 * @file
 * Tests for Relation Entity Collector module.
 */

/**
 * Functional test of Relation's integration with the Entity Collector.
 */
class RelationEntityCollectorTestCase extends RelationTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Relation Entity Collector test',
      'description' => 'Tests the Relation Entity Collector.',
      'group' => 'Relation',
    );
  }
  function setUp() {
    parent::setUp('relation', 'relation_ui', 'relation_entity_collector');
    $this
      ->drupalLogin($this->web_user);
  }

  /**
   * Add relations to Node 1 and to Node 3 and then check that they are related.
   */
  function testEntityCollector() {
    $node1key = 'node:' . $this->node1->nid;
    $node3key = 'node:' . $this->node3->nid;
    $relation_type = $this->relation_types['symmetric']['relation_type'];
    $edit = array(
      "relation_type" => $relation_type,
      "entity_key" => $node1key,
    );
    $this
      ->drupalPost('node', $edit, t('Pick'));
    $edit = array(
      //"relation_type" => $relation_type, // First pick will disable this field
      "entity_key" => $node3key,
    );
    $this
      ->drupalPost('node', $edit, t('Pick'));
    $this
      ->drupalPost('node', array(), t('Save relation'));

    // Now figure out the new rid.
    $result = array_keys(relation_query('node', $this->node3->nid)
      ->propertyCondition('relation_type', $relation_type)
      ->execute());
    $path = 'relation/' . $result[0];
    $link = l($relation_type, $path);

    // Rebuild the message using the known bundle and entity labels to make sure
    // the message contains those.
    $node1_label = _relation_get_bundle_label('node', 'article') . ': ' . entity_label('node', $this->node1);
    $node3_label = _relation_get_bundle_label('node', 'page') . ': ' . entity_label('node', $this->node3);
    $items = array(
      $node1_label,
      $node3_label,
    );
    $item_list = array(
      '#theme' => 'item_list',
      '#items' => $items,
    );
    $list = drupal_render($item_list);
    $message = t('Created new !link from !list', array(
      '!link' => $link,
      '!list' => $list,
    ));
    $this
      ->assertRaw($message, 'Created a new relation.');
    $this
      ->drupalGet($path);
    $node1_uri = entity_uri('node', $this->node1);
    $node3_uri = entity_uri('node', $this->node3);
    $this
      ->assertRaw(l(entity_label('node', $this->node1), $node1_uri['path'], $node1_uri['options']), 'Node1 link found');
    $this
      ->assertRaw(l(entity_label('node', $this->node3), $node3_uri['path'], $node3_uri['options']), 'Node1 link found');
  }

}

Classes

Namesort descending Description
RelationEntityCollectorTestCase Functional test of Relation's integration with the Entity Collector.