You are here

function SpacesOGTestAutocomplete::testAutocomplete in Spaces 7

Same name and namespace in other branches
  1. 6.3 spaces_og/tests/spaces_og.test \SpacesOGTestAutocomplete::testAutocomplete()
  2. 7.3 spaces_og/tests/spaces_og.test \SpacesOGTestAutocomplete::testAutocomplete()

Test autocomplete.

File

spaces_og/tests/spaces_og.test, line 773

Class

SpacesOGTestAutocomplete

Code

function testAutocomplete() {
  $this
    ->loginAdminUser();

  // Create another test group.
  $edit = array(
    'title' => 'Group B',
    'og_description' => 'Group B.',
    'purl[value]' => 'group-b',
  );
  $this
    ->drupalPost('node/add/group', $edit, 'Save');

  // Enable features_test in both groups.
  $this
    ->drupalPost('group-a/node/1/features', array(
    'spaces_features[features_test]' => '1',
  ), 'Save for Group A');
  $this
    ->drupalPost('group-b/node/2/features', array(
    'spaces_features[features_test]' => '1',
  ), 'Save for Group B');

  // Log in as admin user and post a features_test post in each group with very different tags.
  $this
    ->drupalPost('group-a/node/add/features-test', array(
    'title' => 'Fruit post',
    'taxonomy[tags][1]' => 'bananas, apples, oranges',
  ), 'Save');
  $this
    ->drupalPost('group-b/node/add/features-test', array(
    'title' => 'Veggie post',
    'taxonomy[tags][1]' => 'broccoli, artichoke, oregano',
  ), 'Save');

  // Log in as simple user, join group-a and test taxonomy autocomplete.
  $this
    ->loginSimpleUser();

  // When a member of just group A, we should only get fruits.
  $this
    ->drupalPost('group-a/og/subscribe/1', array(), 'Join');
  $this
    ->drupalGet('taxonomy/autocomplete/1/b');
  $this
    ->assertRaw('bananas');
  $this
    ->assertNoRaw('broccoli');
  $this
    ->drupalGet('taxonomy/autocomplete/1/bananas, a');
  $this
    ->assertRaw('apples');
  $this
    ->assertNoRaw('artichoke');
  $this
    ->drupalGet('taxonomy/autocomplete/1/bananas, apples, or');
  $this
    ->assertRaw('oranges');
  $this
    ->assertNoRaw('oregano');

  // When a member of both groups, we should get all tags.
  $this
    ->drupalPost('group-b/og/subscribe/2', array(), 'Join');
  $this
    ->drupalGet('taxonomy/autocomplete/1/b');
  $this
    ->assertRaw('bananas');
  $this
    ->assertRaw('broccoli');
  $this
    ->drupalGet('taxonomy/autocomplete/1/bananas, a');
  $this
    ->assertRaw('apples');
  $this
    ->assertRaw('artichoke');
  $this
    ->drupalGet('taxonomy/autocomplete/1/bananas, apples, or');
  $this
    ->assertRaw('oranges');
  $this
    ->assertRaw('oregano');

  // When a member of just group B, we should only get veggies.
  $this
    ->drupalPost("group-a/og/unsubscribe/1/{$this->simple_user->uid}", array(), 'Leave');
  $this
    ->drupalGet('taxonomy/autocomplete/1/b');
  $this
    ->assertNoRaw('bananas');
  $this
    ->assertRaw('broccoli');
  $this
    ->drupalGet('taxonomy/autocomplete/1/bananas, a');
  $this
    ->assertNoRaw('apples');
  $this
    ->assertRaw('artichoke');
  $this
    ->drupalGet('taxonomy/autocomplete/1/bananas, apples, or');
  $this
    ->assertNoRaw('oranges');
  $this
    ->assertRaw('oregano');

  // User autocomplete
  // Create joe (group B), joan (group B).
  $joe = $this
    ->createNamedUser($this->simpleUserPerms, 'testjoe');
  $this
    ->drupalLogin($joe);
  $this
    ->drupalPost('group-a/og/subscribe/1', array(), 'Join');
  $joan = $this
    ->createNamedUser($this->simpleUserPerms, 'testjoan');
  $this
    ->drupalLogin($joan);
  $this
    ->drupalPost('group-b/og/subscribe/2', array(), 'Join');
  $this
    ->loginSimpleUser();

  // When a member of just group B, we should only get "testjoan".
  $this
    ->drupalGet('user/autocomplete/testjo');
  $this
    ->assertNoRaw('testjoe');
  $this
    ->assertRaw('testjoan');

  // When a member of both groups, we should get both users.
  $this
    ->drupalPost('group-a/og/subscribe/1', array(), 'Join');
  $this
    ->drupalGet('user/autocomplete/testjo');
  $this
    ->assertRaw('testjoe');
  $this
    ->assertRaw('testjoan');

  // When a member of just group A, we should only get "testjoe".
  $this
    ->drupalPost("group-b/og/unsubscribe/2/{$this->simple_user->uid}", array(), 'Leave');
  $this
    ->drupalGet('user/autocomplete/testjo');
  $this
    ->assertRaw('testjoe');
  $this
    ->assertNoRaw('testjoan');
}