You are here

public function ViewsAccessTestCase::setUp in Spaces 7.3

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

Set up test.

Overrides DrupalWebTestCase::setUp

File

tests/spaces.test, line 398

Class

ViewsAccessTestCase
Test for the Views acces plugin

Code

public function setUp() {
  parent::setUp('php', 'ctools', 'features', 'features_test', 'spaces', 'spaces_test', 'views', 'views_ui');

  // Create basic user
  $this->basic_user = $this
    ->drupalCreateUser(array(
    'access content',
  ));

  // Create and login admin user
  $this->admin_user = $this
    ->drupalCreateUser(array(
    'administer site configuration',
    'administer blocks',
    'administer menu',
    'administer views',
    'use PHP for settings',
  ));
  $this
    ->drupalLogin($this->admin_user);
  $this
    ->drupalGet('admin/structure/views/view/comments_recent/export');
  $elems = $this
    ->xpath('//textarea[@id="edit-code"]');

  // Within the exported view locate the page display and change the access
  // plugin.
  $view_code = explode("\n", (string) $elems[0]);
  foreach ($view_code as $n => $line) {
    if (strpos($line, '$handler = $view->new_display(\'page\'') === 0) {
      $mark = $n + 1;
      break;
    }
  }
  $insert = '$handler->display->display_options["defaults"]["access"] = FALSE;
               $handler->display->display_options["access"]["type"] = "spaces_feature";
               $handler->display->display_options["access"]["spaces_feature"] = "spaces_test";
               $handler->display->display_options["access"]["perm"] = "administer site configuration";';
  array_splice($view_code, $mark, 0, $insert);
  $edit = array(
    'name' => 'comments_recent_spaces',
    'view' => implode("\n", $view_code),
  );
  $this
    ->drupalPost('admin/structure/views/import', $edit, t('Import'));
  $this
    ->drupalPost(null, array(), t('Save'));
}