You are here

public function CerCrudTest::testReferencedEntityDeletion in Corresponding Entity References 7.2

File

tests/crud.test, line 144

Class

CerCrudTest

Code

public function testReferencedEntityDeletion() {
  $uid = $this
    ->drupalCreateUser()->uid;
  $referrers = array();
  for ($i = 0; $i < 5; $i++) {
    $referrers[] = $this
      ->drupalCreateNode(array(
      'type' => 'page',
      'field_user' => array(
        'und' => array(
          array(
            'target_id' => $uid,
          ),
        ),
      ),
    ))->nid;
  }
  user_delete($uid);
  $cleared = 0;
  foreach ($referrers as $nid) {
    $node = node_load($nid, NULL, TRUE);
    $cleared += (int) empty($node->field_user);
  }
  $this
    ->assertEqual($cleared, sizeof($referrers), 'Deleting a referenced entity clears all references to it.', 'CER');
}