public function realistic_dummy_content_DatabaseTestCase::assertTag in Realistic Dummy Content 7
Assert that a node has a specified tag in its field_tags
This will make sure the tag exists as the taxonomy term, and that it is referenced in $node's field_tags
Parameters
$tag_name: A string
$node: A node object
1 call to realistic_dummy_content_DatabaseTestCase::assertTag()
File
- api/
tests/ realistic_dummy_content_api.db.test, line 141 - This file contains the testing code which requires the database. These tests are slower than the unit tests so we want to limit them.
Class
- realistic_dummy_content_DatabaseTestCase
- The test case
Code
public function assertTag($tag_name, $node) {
$term = taxonomy_get_term_by_name($tag_name);
$this
->assertTrue($term, 'Term ' . $tag_name . ' exists');
$referenced_term = taxonomy_term_load($node->field_tags[LANGUAGE_NONE][0]['tid']);
if (isset($referenced_term->name)) {
$referenced_term = $referenced_term->name;
}
else {
$referenced_term = '[unknown term]';
}
$this
->assertTrue(array_key_exists($node->field_tags[LANGUAGE_NONE][0]['tid'], $term), 'Term is referenced in node ' . $node->nid . ' (' . $referenced_term . ' == ' . $tag_name . ')');
}