Using a member-posting forum
============================

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

First, some set-up:

    >>> from Products.Five import zcml
    >>> import Products
    >>> zcml.load_config('configure.zcml', package=Products.PloneboardSubscription)
    >>> import Products.PloneboardSubscription
    >>> zcml.load_config('configure.zcml', package=Products.PloneboardSubscription.browser)

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


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.

    >>> workflow = self.portal.portal_workflow

Verify that the forum is indeed a member-posting one by default and log in:

    >>> workflow.getInfoFor(self.forum, 'review_state')
    'memberposting'

Using a member-posting forum
============================

    >>> browser = self.browser
    >>> 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...'

Check the tool
--------------

    >>> len(self.portal.portal_pbnotification.subscribers.keys())
    0

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('Body text').value = 'Some <b>body</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
    >>> conversation = self.forum.getConversations()[0]

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

Login as member2
----------------

    >>> utils.logoutThenLoginAs(self, browser, 'member2')
    >>> browser.open(self.board.absolute_url())
    >>> browser.getLink('Forum 1').click()
    >>> browser.getLink(url=re.compile('\/%s$' % conversation.getId())).click()

Subscribe to this conversation
------------------------------

    >>> browser.getLink('Subscribe').click()

Check the tool
--------------

    >>> len(self.portal.portal_pbnotification.subscribers.keys())
    1

Go back as member1 and add a reply
-----------------------------------

    >>> utils.logoutThenLoginAs(self, browser, 'member1')
    >>> browser.open(self.board.absolute_url())
    >>> browser.getLink('Forum 1').click()
    >>> browser.getLink(url=re.compile('\/%s$' % conversation.getId())).click()

Add comment to own comment
--------------------------

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

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

Force the tool
--------------

    >>> self.portal.portal_pbnotification.process_pending()

This should have triggered a notification. Check the MockMailHost
------------------------------------------------------------------

    >>> len(self.portal.MailHost.messages)
    1

    >>> self.portal.MailHost.messages[0]
    'To: member2@example.com...'

    >>> conversation.absolute_url() in self.portal.MailHost.messages[0]
    True

    >>> self.portal.MailHost.reset()

    >>> len(self.portal.MailHost.messages)
    0
