You are here

class ContentTaxonomyTestCase in Content Taxonomy 6

Same name and namespace in other branches
  1. 6.2 tests/content_taxonomy.test \ContentTaxonomyTestCase

Base Class for testing Content Taxonomy extends the ContentCrudTestCase Class from CCK, which provides many useful helper functions

Hierarchy

Expanded class hierarchy of ContentTaxonomyTestCase

File

tests/content_taxonomy.test, line 8

View source
class ContentTaxonomyTestCase extends ContentCrudTestCase {
  function setUp() {
    $args = func_get_args();
    $modules = array_merge(array(
      "optionwidgets",
      "content_taxonomy",
      "content_taxonomy_options",
      "content_taxonomy_autocomplete",
    ), $args);
    call_user_func_array(array(
      'parent',
      'setUp',
    ), $modules);
    $this
      ->loginWithPermissions();
    $this
      ->acquireContentTypes(2);
  }

  /**
   * helper function to create a vocabulary and terms
   */
  function createTerms($count = 1) {
    $edit['name'] = $this
      ->randomName(200);
    $edit['hierarchy'] = 2;

    // Hierarchy 0,1,2
    $edit['multiple'] = 1;

    // multiple 0,1
    $edit['required'] = 0;

    // required 0,1
    $edit['relations'] = 0;
    $edit['tags'] = 1;

    // exec save function
    taxonomy_save_vocabulary($edit);
    $vid = $edit['vid'];
    for ($i = 0; $i < $count; $i++) {

      // create term
      $termname = $this
        ->randomName(20);
      $data = array(
        'name' => $termname,
        'vid' => $vid,
      );
      taxonomy_save_term($data);
      $terms[] = taxonomy_get_term($data['tid']);
    }
    return $terms;
  }

  /**
   * helper assertion function, which checks if the node field array is built correctly
   */
  function assertNodeMultiValues($node, $field_name, $terms_in = array(), $terms_out = array()) {
    $tids = array();
    if (is_array($node->{$field_name})) {
      foreach ($node->{$field_name} as $key => $value) {
        $tids[$value['value']] = $value['value'];
      }
    }
    foreach ($terms_in as $term) {
      $this
        ->assertTrue(in_array($term->tid, $tids), 'Term correctly in node field');
    }
    foreach ($terms_out as $term) {
      $this
        ->assertTrue(!in_array($term->tid, $tids), 'Term correctly in node field');
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ContentTaxonomyTestCase::assertNodeMultiValues function helper assertion function, which checks if the node field array is built correctly
ContentTaxonomyTestCase::createTerms function helper function to create a vocabulary and terms
ContentTaxonomyTestCase::setUp function 3