Admin locks board
====================

Test starting conversations, replying and modifying comments in a default
members-posting forum.

First, some set-up:

    >>> from Zope2.App import zcml
    >>> import Products
    >>> zcml.load_config('configure.zcml', package=Products.Ploneboard)

    >>> from Products.Ploneboard.tests import utils
    >>> utils.setUpDefaultMembersBoardAndForum(self)

    >>> from Testing.testbrowser import Browser
    >>> browser = Browser()
    >>> browser.handleErrors = False

Let us log all exceptions, which is useful for debugging. Also, clear portlet
slots, to make the test browser less confused by things like the recent portlet
and the navtree.

    >>> self.portal.error_log._ignored_exceptions = ()
    >>> self.portal.left_slots = self.portal.right_slots = []
    >>> workflow = self.portal.portal_workflow

    >>> utils.logoutThenLoginAs(self, browser, 'member1')

View forum
----------

The forum created behind the scenes should now be shown here.

    >>> browser.open(self.board.absolute_url())
    >>> browser.contents
    '...Forum 1...'

If we go to the forum, there are no conversations shown.

    >>> browser.getLink('Forum 1').click()
    >>> browser.contents
    '...No conversations in this forum yet...'

Add a new conversation
----------------------

Now we can add a new conversation. We set a title and some body text. The body
text can contain HTML as well.

    >>> browser.getControl('Start a new Conversation').click()
    >>> browser.url
    '.../add_conversation_form...'
    >>> browser.getControl('Title').value = 'New title'
    >>> browser.getControl(name='text').value = 'Some <b>body</b> text'

We have attachment buttons, although we won't upload anything now.
INFO: This test fails (LookupError: name 'files:list') if SimpleAttachment is not installed.

    >>> browser.getControl(name='files:list', index=0)
    <Control name='files:list' type='file'>

Submit the form, and we should be returned to the forum view. The conversation
should exist, and we should be able to view it.

    >>> browser.getControl(name='form.button.Post').click()
    >>> browser.url.startswith(self.forum.absolute_url())
    True
    >>> conversation = self.forum.getConversations()[0]

    >>> import re
    >>> browser.getLink(url=re.compile('\/%s$' % conversation.getId())).click()


Lock the board
----------------

    >>> workflow.getInfoFor(self.board, 'review_state')
    'published'

    >>> utils.lockBoard(self, 'lock')

    >>> workflow.getInfoFor(self.board, 'review_state')
    'locked'

Now navigate to the forum. You will not be able to add a new conversation.

    >>> browser.open(self.forum.absolute_url())
    >>> browser.getControl('Start a new Conversation')
    Traceback (most recent call last):
    ...
    LookupError: label 'Start a new Conversation'

Navigate to a conversation. You will not be able to add a reply.

    >>> conversation = self.forum.getConversations()[0]

    >>> import re
    >>> browser.getLink(url=re.compile('\/%s$' % conversation.getId())).click()
    >>> browser.getControl(name='text')
    Traceback (most recent call last):
    ...
    LookupError: name 'text'

Unlock the board
----------------

    >>> utils.lockBoard(self, 'unlock')

    >>> workflow.getInfoFor(self.board, 'review_state')
    'published'

Now navigate to the forum. You should be able to add a new conversation.

    >>> browser.open(self.forum.absolute_url())
    >>> browser.getControl('Start a new Conversation').click()
    >>> browser.url
    '.../add_conversation_form...'
    >>> browser.getControl('Title').value = 'Unlocked'
    >>> browser.getControl(name='text').value = 'Some <b>unlocked</b> text'

Submit the form, and we should be returned to the forum view. The conversation
should exist, and we should be able to view it.

    >>> browser.getControl(name='form.button.Post').click()
    >>> browser.url.startswith(self.forum.absolute_url())
    True

Navigate to a conversation. You should be able to add a reply.

    >>> conversation = self.forum.getConversations()[0]

    >>> import re
    >>> browser.getLink(url=re.compile('\/%s$' % conversation.getId())).click()

Add a comment to our own comment. Use the quick-reply field first.

    >>> browser.getControl(name='text').value = 'An unlocked reply'
    >>> browser.getControl(name='form.button.Post').click()
    >>> browser.url.startswith(conversation.absolute_url())
    True
    >>> browser.contents
    '...An unlocked reply...'

