You are here

function SpacesOGTestRouter::testRouter in Spaces 7.3

Same name and namespace in other branches
  1. 6.3 spaces_og/tests/spaces_og.test \SpacesOGTestRouter::testRouter()
  2. 7 spaces_og/tests/spaces_og.test \SpacesOGTestRouter::testRouter()

Test router.

File

spaces_og/tests/spaces_og.test, line 720

Class

SpacesOGTestRouter

Code

function testRouter() {

  // Enable features_test feature site wide.
  $this
    ->drupalPost('features', array(
    'spaces_features[features_test]' => '1',
  ), 'Save configuration');

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

  // Log in as simple user, join and post a features_test .
  $this
    ->loginSimpleUser();
  $this
    ->drupalPost('group-a/og/subscribe/1', array(), 'Join');
  $this
    ->drupalPost('group-a/node/add/features-test', array(
    'title' => 'Test post',
  ), 'Save');

  // Router should redirect to group-a/*.
  foreach (array(
    'node/1',
    'node/3',
    'group-b/node/1',
    'group-b/node/3',
  ) as $path) {
    $this
      ->drupalGet($path);
    $this
      ->assertTrue(FALSE !== strpos($this
      ->getUrl(), 'group-a'));
  }

  // Submit a features_test outside of a group.
  $this
    ->drupalGet('node/add/features-test');
  $this
    ->drupalPost('node/add/features-test', array(
    'title' => 'Not in group (accident)',
  ), 'Save');
  $this
    ->assertText('Not in group');
  $this
    ->assertNoText('This content type is supposed to be posted within a group but it is not.');

  // Log in as admin, make audience settings mandatory.
  $this
    ->loginAdminUser();
  $this
    ->drupalPost('admin/og/og', array(
    'og_audience_required' => '1',
  ), 'Save configuration');
  $this
    ->assertText('The configuration options have been saved.');

  // Log in as simple user again, I should get an error message now.
  $this
    ->loginSimpleUser();
  $this
    ->drupalGet('node/4/edit');
  $this
    ->assertText('This content type is supposed to be posted within a group but it is not. You will not be able to save this node. Please contact a site administrator to fix the issue.');

  // Log in as admin, fix error by assigning post to group A.
  $this
    ->loginAdminUser();
  $this
    ->drupalPost('node/4/edit', array(
    'spaces_og_audience' => 1,
  ), 'Save');

  // Log in as simple user again, verify that post is fixed.
  $this
    ->loginSimpleUser();
  $this
    ->drupalGet('node/4/edit');
  $this
    ->assertTrue(FALSE !== strpos($this
    ->getUrl(), 'group-a'));
  $this
    ->assertNoText('This content type is supposed to be posted within a group but it is not.');
}