You are here

public function SpacesTestCase::test in Spaces 7.3

Same name and namespace in other branches
  1. 6.3 tests/spaces.test \SpacesTestCase::test()
  2. 7 tests/spaces.test \SpacesTestCase::test()

Test access control and simple feature settings using as example the Simple Blog feature that ships with Spaces.

File

tests/spaces.test, line 233

Class

SpacesTestCase
Tests for basic spaces functionality.

Code

public function test() {

  // Create admin and editor user.
  $admin = $this
    ->drupalCreateUser(array(
    'access content',
    'administer nodes',
    'administer content types',
    'administer site configuration',
    'administer spaces',
  ));
  $editor = $this
    ->drupalCreateUser(array(
    'access content',
    'create features_test content',
    'edit own features_test content',
    'delete own features_test content',
  ));
  $this
    ->drupalLogin($editor);

  // Verify that create story link is not available.
  $this
    ->drupalGet('node/add');
  $this
    ->assertNoRaw('node/add/features-test', 'Create content link not available');

  // Log in as admin user and enable test feature on global space.
  $this
    ->drupalLogin($admin);
  $edit = array(
    'spaces_features[features_test]' => '1',
  );
  $this
    ->drupalPost('features', $edit, t('Save configuration'));
  $this
    ->assertText('The configuration options have been saved.');

  // Log in as editor user and create story post.
  $this
    ->drupalLogin($editor);
  $this
    ->drupalGet('node/add');
  $this
    ->assertRaw('node/add/features-test', 'Create content link is available');
  $edit = array(
    'title' => $this
      ->randomName(10),
    'field_features_test[und][0][value]' => $this
      ->randomName(20),
  );
  $this
    ->drupalPost('node/add/features-test', $edit, 'Save');
  $this
    ->assertText('has been created');

  // For adding new comment, assert that there is no Save link for the comment.
  $this
    ->assertNoText('Save');

  // Shut off blog feature again.
  $this
    ->drupalLogin($admin);
  $edit = array(
    'spaces_features[features_test]' => '0',
  );
  $this
    ->drupalPost('features', $edit, 'Save configuration');
  $this
    ->assertText('The configuration options have been saved.');

  // Now the node/add/features-test path should be denied to editor user, and
  // the previously created node should no longer be editable.
  $this
    ->drupalLogin($editor);
  $this
    ->drupalGet('node/add/features-test');
  $this
    ->assertResponse(403);
  $this
    ->drupalGet('node/1/edit');
  $this
    ->assertResponse(403);

  // Enable feature again and change the comment preview setting to optional,
  // assert.
  $this
    ->drupalLogin($admin);
  $this
    ->drupalPost('features/features_test', array(
    'features_test_setting' => '1',
  ), 'Save configuration');
  $this
    ->assertText('The configuration options have been saved.');
}