You are here

class ContentTaxonomyAutocompletePermissionsTest in Content Taxonomy 6

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

Test Cases for Content Taxonomy Autocomplete

Hierarchy

Expanded class hierarchy of ContentTaxonomyAutocompletePermissionsTest

File

tests/content_taxonomy.test, line 569

View source
class ContentTaxonomyAutocompletePermissionsTest extends ContentTaxonomyTestCase {
  function getInfo() {
    return array(
      'name' => t('Content Taxonomy - Autocomplete with Permissions'),
      'description' => t('Tests freetagging widget with content permissions'),
      'group' => t('Content Taxonomy'),
    );
  }
  function setUp() {
    parent::setUp("content_permissions");
  }
  function testAutocomplete() {
    $type = $this->content_types[1];
    $type_url = str_replace('_', '-', $type->type);
    $terms = $this
      ->createTerms(4);

    //single field
    $settings = array(
      'type' => 'content_taxonomy',
      'widget_type' => 'content_taxonomy_autocomplete',
      'vid' => $terms[0]->vid,
      'parent' => 0,
      'parent_php_code' => '',
      'show_depth' => 0,
      'save_term_node' => FALSE,
      'depth' => NULL,
      'hide_taxonomy_fields' => TRUE,
    );
    $field = $this
      ->createField($settings, 1);
    $field_name = $field['field_name'];
    $permissions = array(
      'edit ' . $field_name,
      'view ' . $field_name,
    );
    $rids = db_query("SELECT rid FROM {role}");
    while ($obj = db_fetch_object($rids)) {
      db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $obj->rid, implode(', ', $permissions));
    }

    // Create a node with one value with edit permissions
    $edit = array();
    $edit['title'] = $this
      ->randomName(20);
    $edit['body'] = $this
      ->randomName(20);
    $edit[$field_name . '[value]'] = $terms[0]->name;
    $this
      ->drupalPost('node/add/' . $type_url, $edit, 'Save');
    $node = node_load(array(
      'title' => $edit['title'],
    ));
    $this
      ->assertEqual($node->{$field_name}[0]['value'], $terms[0]->tid, 'Terms saved');
    $this
      ->drupalGet('node/' . $node->nid);
    $this
      ->assertText($terms[0]->name, 'Terms displayed');
    $this
      ->assertNoText($terms[1]->name, 'Term not displayed');

    //delete edit field perm
    $permissions_old = array(
      'edit ' . $field_name,
      'view ' . $field_name,
    );
    $permissions_new = array(
      'view ' . $field_name,
    );
    $rids = db_query("SELECT rid FROM {role}");
    while ($obj = db_fetch_object($rids)) {
      db_query("DELETE FROM {permission WHERE rid = %d AND perm = '%s'", $obj->rid, implode(', ', $permissions_old));
      db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $obj->rid, implode(', ', $permissions_new));
    }

    //Edit the node, but without perm
    $edit = array();
    $this
      ->drupalPost('node/' . $node->nid . '/edit', $edit, 'Save');
    $this
      ->drupalGet('node/' . $node->nid . '/edit');
    $this
      ->assertNoRaw($field_name, "Field hidden");
    $node = node_load($node->nid, NULL, TRUE);
    $this
      ->assertIdentical($node->{$field_name}[0]['value'], $terms[0]->tid, 'Terms saved');
    $this
      ->drupalGet('node/' . $node->nid);
    $this
      ->assertText($terms[0]->name, 'Terms displayed');
  }

}

Members