function MessageEntityDelete::testReferencedEntitiesDelete in Message 7
Test deletion of a message after its referenced entities have been deleted.
File
- tests/
message.test, line 799
Class
- MessageEntityDelete
- Test the Message delete on entity delete functionallity.
Code
function testReferencedEntitiesDelete() {
// Test entities reference.
$message = message_create('mt1', array());
$wrapper = entity_metadata_wrapper('message', $message);
$wrapper->field_nodes_ref
->set(array(
1,
2,
));
$wrapper
->save();
node_delete(2);
$message = message_load($message->mid);
$this
->assertTrue($message, 'Message exists after deleting one of two referenced nodes.');
node_delete(1);
$message = message_load($message->mid);
$this
->assertTrue(empty($message), 'Message deleted after deleting all referenced nodes.');
// Test terms reference.
$message = message_create('mt1', array());
$wrapper = entity_metadata_wrapper('message', $message);
$wrapper->field_terms_ref
->set(array(
1,
2,
));
$wrapper
->save();
taxonomy_term_delete(2);
$message = message_load($message->mid);
$this
->assertTrue($message, 'Message exists after deleting one of two referenced terms.');
taxonomy_term_delete(1);
$message = message_load($message->mid);
$this
->assertTrue(empty($message), 'Message deleted after deleting all referenced terms.');
$message = message_create('mt1', array());
$wrapper = entity_metadata_wrapper('message', $message);
$wrapper->field_terms_ref
->set(array(
3,
));
$wrapper
->save();
taxonomy_term_delete(3);
$message = message_load($message->mid);
$this
->assertTrue(empty($message), 'Message deleted after deleting single referenced term.');
$message = message_create('mt1', array());
$wrapper = entity_metadata_wrapper('message', $message);
$wrapper->field_terms_ref
->set(array(
4,
5,
));
$wrapper->field_term_ref
->set(4);
$wrapper
->save();
taxonomy_term_delete(4);
$message = message_load($message->mid);
$this
->assertTrue(empty($message), 'Message deleted after deleting single referenced term while another the message still references other term in another field.');
// Test user reference.
$account = $this
->drupalCreateUser();
$message = message_create('mt1', array());
$wrapper = entity_metadata_wrapper('message', $message);
$wrapper->field_user_ref
->set($account->uid);
$wrapper
->save();
user_delete($account->uid);
$message = message_load($message->mid);
$this
->assertTrue(empty($message), 'Message deleted after deleting single referenced user.');
}