You are here

public function AckNodeAccessTest::setUpTaxonomy in Access Control Kit 7

Utility function to prepare a taxonomy-based access test.

Parameters

string $scheme_machine_name: The access scheme machine name.

string $class: The handler class name.

2 calls to AckNodeAccessTest::setUpTaxonomy()
AckNodeAccessTest::testFieldAccess in ack_node/ack_node.test
Test controlling access by a field value.
AckNodeAccessTest::testTaxonomyAccess in ack_node/ack_node.test
Test controlling access with the taxonomy index.

File

ack_node/ack_node.test, line 112
Tests for the ACK node module.

Class

AckNodeAccessTest
Tests the node access functions.

Code

public function setUpTaxonomy($scheme_machine_name, $class) {

  // Create two tags to use as realms.
  $vocabulary = taxonomy_vocabulary_machine_name_load('tags');
  for ($i = 0; $i < 2; $i++) {
    $term = new stdClass();
    $term->vid = $vocabulary->vid;
    $term->name = $this
      ->randomName();
    taxonomy_term_save($term);
  }

  // Switch the tags field from the tagging widget to checkboxes.
  $instance = field_info_instance('node', 'field_tags', 'article');
  $instance['widget'] = array(
    'type' => 'options_buttons',
    'module' => 'options',
  );
  field_update_instance($instance);

  // Tag the node.
  $edit = array(
    'field_tags[und][1]' => TRUE,
  );
  $this
    ->drupalPost('node/' . $this->node->nid . '/edit', $edit, 'Save');
  $this->node = node_load($this->node->nid, NULL, TRUE);

  // Prepare the access scheme.
  $name = $this
    ->randomName();
  $edit = array(
    'name' => $name,
    'machine_name' => $scheme_machine_name,
    'settings[vocabulary]' => 'tags',
    'roles[' . $this->ackRoleOwn->rid . ']' => TRUE,
    'roles[' . $this->ackRoleAny->rid . ']' => TRUE,
  );
  $this
    ->drupalPost('admin/structure/access/add/taxonomy-term', $edit, 'Save access scheme and continue');
  $edit = array(
    'handlers[node][handler]' => $class,
  );
  $this
    ->drupalPost(NULL, $edit, 'Save access scheme');
  $this
    ->assertText('Updated access scheme ' . $name, 'Access scheme configured.');
}