1 layout.test LayoutInterfaceTest::testBlockUserCompareConditions()

Tests user account comparison condition.

File

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

Class

LayoutInterfaceTest
Tests the interface for adding, removing, and moving blocks.

Code

function testBlockUserCompareConditions() {
  // Create a new layout overriding user/%.
  $layout_title = $this->randomName();
  $layout_name = strtolower($layout_title);
  $layout_url = 'user/%';
  $edit = array(
    'title' => $layout_title,
    'name' => $layout_name,
    'layout_template' => 'moscone_flipped',
    'path' => $layout_url,
  );
  $this->backdropPost('admin/structure/layouts/add', $edit, t('Create layout'));

  // Add another testing block.
  $this->clickLink(t('Add block'), 3);
  $this->clickLink(t('Layout foo block'));
  $block_title = $this->randomString();
  $edit = array(
    'title_display' => LAYOUT_TITLE_CUSTOM,
    'title' => $block_title,
  );
  $this->backdropPost(NULL, $edit, t('Add visibility condition'));
  $edit = array(
    'condition' => 'user_compare',
  );
  $this->backdropPost(NULL, $edit, t('Load condition'));

  // The user account comparison form has some customizations. Verify the
  // fields show as expected.
  $this->assertOption('edit-contexts-user2', '1', 'User account from path in position 2 selected as second comparison user account.');
  $this->assertNoOption('edit-contexts-user2', 'current_user');

  $edit = array(
    'contexts[user2]' => '1',
    'equality' => '1',
  );
  $this->backdropPost(NULL, $edit, t('Add visibility condition'));
  $this->backdropPost(NULL, array(), t('Update block'));
  $this->backdropPost(NULL, array(), t('Save layout'));

  $this->backdropGet('user/' . $this->admin_user->uid);
  $this->assertText(check_plain($block_title), 'Block shown when user views own profile page.');

  $this->backdropGet('user/' . $this->web_user->uid);
  $this->assertNoText(check_plain($block_title), 'Block not shown when user views profile page of another user.');

  // Get the block UUID.
  layout_reset_caches();
  $layout = layout_load($layout_name);
  $block_uuid = end($layout->positions['sidebar']);

  // Update the condition to do the opposite, where a block is only shown to
  // a user viewing their own profile page.
  $this->backdropGet('admin/structure/layouts/manage/' . $layout_name . '/configure-block/editor/' . $block_uuid);
  $this->backdropPost(NULL, array(), t('Configure'));
  $edit = array(
    'equality' => '0',
  );
  $this->backdropPost(NULL, $edit, t('Save visibility condition'));
  $this->backdropPost(NULL, array(), t('Update block'));
  $this->backdropPost(NULL, array(), t('Save layout'));

  $this->backdropGet('user/' . $this->admin_user->uid);
  $this->assertNoText(check_plain($block_title), 'Block not shown when user views own profile page');

  $this->backdropGet('user/' . $this->web_user->uid);
  $this->assertText(check_plain($block_title), 'Block shown when user views profile page of another user.');
}