1 layout.test LayoutSelectionTest::testRoleSelection()

Test role-based selection of layouts.


core/modules/layout/tests/layout.test, line 1901
Tests for the Layout module.


Tests that the correct layout is used in various situations.


function testRoleSelection() {
  // Create and login admin user.
  $admin_user = $this->backdropCreateUser(array(
    'access administration pages',
    'administer site configuration',
    'administer modules',
    'administer layouts',
    'administer nodes',

  // Create a web user.
  $web_user = $this->backdropCreateUser(array('access user profiles', 'access content'));

  // Create a layout at a custom path.
  $layout_name = strtolower($this->randomName());
  $layout_path = $layout_name;
  $edit = array(
    'name' => $layout_name,
    'title' => $layout_name,
    'path' => $layout_path,
    'layout_template' => 'moscone_flipped',

  // Note that this adds a condition, not saving the layout yet.
  $this->backdropPost('admin/structure/layouts/add', $edit, t('Add visibility condition'));

  // Select the condition to add.
  $edit = array(
    'condition' => 'user_role',
  $this->backdropPost(NULL, $edit, t('Load condition'));

  // Allow authenticated users to see the layout only.
  $edit = array(
    'roles[authenticated]' => TRUE,
  $this->backdropPost(NULL, $edit, t('Add visibility condition'));

  // Save the layout.
  $this->backdropPost(NULL, array(), t('Create layout'));

  // View as an administrator.

  // View as a basic user.

  // View as anonymous, where they should get a 404.