You are here

function EntityDependencyTestCase::testNodeUserComment in Entity Dependency API 7

Test basic scenario with node & author & comment & commentor.

File

./entity_dependency.test, line 128
Entity Dependency tests.

Class

EntityDependencyTestCase
Tests the entity dependency iterator.

Code

function testNodeUserComment() {
  $author = $this
    ->drupalCreateUser();
  $node = $this
    ->drupalCreateNode(array(
    'type' => 'article',
    'uid' => $author->uid,
  ));
  $commentor = $this
    ->drupalCreateUser();
  $comment = new stdClass();
  $comment->cid = 0;
  $comment->pid = 0;
  $comment->nid = $node->nid;
  $comment->uid = $commentor->uid;
  comment_save($comment);
  $this->entities = array(
    array(
      'id' => $comment->cid,
      'type' => 'comment',
    ),
  );
  $i = 0;
  foreach ($this
    ->getIterator() as $entity) {
    switch ($i) {
      case 0:
        $this
          ->assertCorrectEntityOrder($entity, 'user', 'uid', $commentor->uid);
        break;
      case 1:
        $this
          ->assertCorrectEntityOrder($entity, 'user', 'uid', $author->uid);
        break;
      case 2:
        $this
          ->assertCorrectEntityOrder($entity, 'node', 'nid', $node->nid);
        break;
      case 3:
        $this
          ->assertCorrectEntityOrder($entity, 'comment', 'cid', $comment->cid);
        break;
    }
    $i++;
  }
  $this
    ->assertEqual($i, 4, 'Correct number of entities was iterated over.');
}