Logging in and out
==================

A very simple and underdocumented testbrowser test.  This is all about
logging in and out.

    >>> from Products.Five.testbrowser import Browser
    >>> browser = Browser()

Using the Login Form
--------------------

First we try to log in with bad credentials:

    >>> browser.open('http://nohost/plone/')
    >>> browser.getLink('Log in').click()
    >>> browser.url
    'http://nohost/plone/login_form'
    >>> browser.getControl('Login Name').value = 'test_user_1_'
    >>> browser.getControl('Password').value = 'wrongpassword'
    >>> browser.getControl('Log in').click()
    >>> "You are not currently logged in" in browser.contents
    True
    >>> browser.url
    'http://nohost/plone/login_form'

And then we try again with the right credentials:

    >>> browser.getLink('Log in').click()
    >>> browser.url
    'http://nohost/plone/login_form'
    >>> browser.getControl('Login Name').value = 'test_user_1_'
    >>> browser.getControl('Password').value = 'secret'
    >>> browser.getControl('Log in').click()
    >>> "You are now logged in" in browser.contents
    True
    >>> browser.url
    'http://nohost/plone/login_form'
    >>> browser.getLink('Log out').click()
    >>> browser.url
    'http://nohost/plone/logged_out'

Using the Login Portlet
-----------------------

First we try to log in with bad credentials:

    >>> browser.getLink('Home').click()
    >>> browser.url
    'http://nohost/plone'
    >>> browser.getControl('Login Name').value = 'test_user_1_'
    >>> browser.getControl('Password').value = 'wrongpassword'
    >>> browser.getControl('Log in').click()
    >>> 'You are not currently logged in.' in browser.contents
    True
    >>> browser.url
    'http://nohost/plone/login_form'

And then we try again with the right credentials:

    >>> browser.getLink('Home').click()
    >>> browser.url
    'http://nohost/plone'
    >>> browser.getControl('Login Name').value = 'test_user_1_'
    >>> browser.getControl('Password').value = 'secret'
    >>> browser.getControl('Log in').click()
    >>> 'You are now logged in' in browser.contents
    True
    >>> browser.url
    'http://nohost/plone/login_form'

We landed in ``login_form`` because we don't have JavaScript enabled
and therefore Plone thinks we don't have cookies and displays a
warning.  We're logged in however even on the next page load:

    >>> browser.reload()
    >>> browser.getLink('Log out').click()
    >>> 'You are now logged out' in browser.contents
    True

Login with user defined in root user folder
-------------------------------------------

A user defined in the root user folder should be able to log in into
the site:

    >>> self.app.acl_users.userFolderAddUser('rootuser', 'secret', [], [])
    >>> browser.getControl('Login Name').value = 'rootuser'
    >>> browser.getControl('Password').value = 'secret'
    >>> browser.getControl('Log in').click()
    >>> 'You are now logged in' in browser.contents
    True
