You are here

function OgVocabComplexWidgetTestCase::testContext in OG Vocabulary 7

Test Showing widget by context.

File

./og_vocab.test, line 204
Test organic groups vocabulary module.

Class

OgVocabComplexWidgetTestCase

Code

function testContext() {
  module_enable(array(
    'og_context',
    'og_vocab_test',
  ));

  // Subscribe user to user2's group.
  og_group('node', 3, array(
    'entity' => $this->user1,
  ));
  $field = field_info_field(OG_VOCAB_FIELD);
  $field['settings']['handler_settings']['behaviors']['og_vocab']['use_context'] = 'force';
  field_update_field($field);
  $this
    ->drupalGet('node/add/post');
  $names = array(
    'og_vocabulary[und][0][2][]' => FALSE,
    'og_vocabulary[und][0][3]' => FALSE,
    'og_vocabulary[und][0][4][0][target_id]' => FALSE,
    // Belongs to another group.
    'og_vocabulary[und][0][5][]' => FALSE,
  );
  $this
    ->assertSubWidgets($names);

  // Set og-context, by passing it in the URL, and the test-module
  // will make sure to set the context.
  variable_set('og_vocab_test_context_nid', 3);
  $this
    ->drupalGet('node/add/post');
  $names = array(
    'og_vocabulary[und][0][2][]' => FALSE,
    'og_vocabulary[und][0][3]' => FALSE,
    'og_vocabulary[und][0][4][0][target_id]' => FALSE,
    // Belongs to another group.
    'og_vocabulary[und][0][5][]' => TRUE,
  );
  $this
    ->assertSubWidgets($names);
  $field['settings']['handler_settings']['behaviors']['og_vocab']['use_context'] = 'yes';
  field_update_field($field);
  variable_set('og_vocab_test_context_nid', 3);
  $this
    ->drupalGet('node/add/post');
  $names = array(
    'og_vocabulary[und][0][2][]' => FALSE,
    'og_vocabulary[und][0][3]' => FALSE,
    'og_vocabulary[und][0][4][0][target_id]' => FALSE,
    // Belongs to another group.
    'og_vocabulary[und][0][5][]' => TRUE,
  );
  $this
    ->assertSubWidgets($names);
  variable_set('og_vocab_test_context_nid', FALSE);
  $this
    ->drupalGet('node/add/post');
  $names = array(
    'og_vocabulary[und][0][2][]' => TRUE,
    'og_vocabulary[und][0][3]' => TRUE,
    'og_vocabulary[und][0][4][0][target_id]' => TRUE,
    // Belongs to another group.
    'og_vocabulary[und][0][5][]' => TRUE,
  );
  $this
    ->assertSubWidgets($names);
  $field['settings']['handler_settings']['behaviors']['og_vocab']['use_context'] = 'no';
  field_update_field($field);
  variable_set('og_vocab_test_context_nid', 3);
  $this
    ->drupalGet('node/add/post');
  $names = array(
    'og_vocabulary[und][0][2][]' => TRUE,
    'og_vocabulary[und][0][3]' => TRUE,
    'og_vocabulary[und][0][4][0][target_id]' => TRUE,
    // Belongs to another group.
    'og_vocabulary[und][0][5][]' => TRUE,
  );
  $this
    ->assertSubWidgets($names);
}