1 user.test UserBlocksUnitTests::testUserLoginBlock()

Tests the secondary menu.

File

core/modules/user/tests/user.test, line 1843
Tests for user.module.

Class

UserBlocksUnitTests
Test user blocks.

Code

function testUserLoginBlock() {
  // Create a user with some permission that anonymous users lack.
  $user = $this->backdropCreateUser(array('administer permissions'));

  // Add the block to the default layout.
  $layout = layout_load('default');
  $layout->addBlock('user', 'login', 'sidebar');
  $layout->save();

  // Log in using the block.
  $edit = array();
  $edit['name'] = $user->name;
  $edit['pass'] = $user->pass_raw;
  $this->backdropPost('admin/config/people/permissions', $edit, t('Log in'));
  $this->assertNoText(t('User login'), 'Logged in.');

  // Check that we are still on the same page.
  $this->assertEqual(url('admin/config/people/permissions', array('absolute' => TRUE)), $this->getUrl(), 'Still on the same page after login for access denied page');

  // Now, log out and repeat with a non-403 page.
  $this->backdropLogout();
  $this->backdropPost('filter/tips', $edit, t('Log in'));
  $this->assertNoText(t('User login'), 'Logged in.');
  $this->assertPattern('!<title.*?' . t('Compose tips') . '.*?</title>!', 'Still on the same page after login for allowed page');

  // Check that the user login block is not vulnerable to information
  // disclosure to third party sites.
  $this->backdropLogout();
  $this->backdropPost('<front>', $edit, t('Log in'), array('query' => array('destination' => 'http://example.com/')));
  // Check that we remain on the site after login.
  $this->assertEqual(url('node', array('absolute' => TRUE)), $this->getUrl(), 'Redirected to frontpage and not external site after login.');
}