def test_browse_polls(self):
        """A minimal functional test for polls."""
        setRoles(self.portal, TEST_USER_ID, ('Manager',))

        # create, publish and join a workspace:
        ws = helpers.create_workspace(self.portal, 'ws1', title=u"Workspace 1")
        ws.addMember(SITE_MEMBER)

        import transaction
        transaction.commit()

        browser = Browser(self.app)
        browser.handleErrors = False

        # Log in as a user
        browser.addHeader(
            'Authorization',
            'Basic %s:%s' % (SITE_MEMBER, PASSWORD,))

        # go to conversation:
        browser.open("%s/conversation" % ws.absolute_url())

        # create poll:
        options = ['The first option', 'Another option', 'The final option']
        browser.getLink(text='Poll').click()
        title = browser.getControl(name='form.widgets.title')
        title.value = "The Poll"
        text = browser.getControl(name='form.widgets.text')
        text.value = "<p>Blah, blah, test.</p>"
        optWidget = browser.getControl(name='form.widgets.options')
        optWidget.value = "\n".join(options)
        browser.getControl(name='form.buttons.save').click()

        self.assertIn('the-poll', ws)
        poll = ws['the-poll']

        # publish the poll:
        # TODO: we cheat because there is no publishing interface availible to
        #       normal users.
        pw = getToolByName(self.portal, 'portal_workflow')
        pw.doActionFor(poll, "publish")

        transaction.commit()

        # the poll should be published:
        self.assertEqual(pw.getInfoFor(poll, 'review_state'), 'published')

        # we should be send to the polls view now:
        self.assertTrue("The Poll" in browser.contents)
        self.assertTrue("Blah, blah, test." in browser.contents)
        option = helpers.try_get_control(browser, name='option')

        self.assertTrue(option is not None)
        self.assertEqual(sorted(option.displayOptions), sorted(options))
        voteButton = helpers.try_get_control(browser, name='form.button.Vote')
        self.assertTrue(voteButton is not None)

        # edit- and delete-buttons are still there:
        editButton = helpers.try_get_link(browser, text='Edit')
        self.assertTrue(editButton is not None)
        deleteButton = helpers.try_get_link(browser, text='Delete')
        self.assertTrue(deleteButton is not None)

        # vote for something:
        option.displayValue = options[1:2]
        voteButton.click()

        # the polls state should be 'active' now:
        self.assertEqual(pw.getInfoFor(poll, 'review_state'), 'active')

        # edit-buttons is still there for the owner:
        editButton = helpers.try_get_link(browser, text='Edit')
        self.assertNotEqual(editButton, None)
        # no delete-button anymore:
        deleteButton = helpers.try_get_link(browser, text='Delete')
        self.assertEqual(deleteButton, None)

        # poll results should be shown:
        for option in options:
            markup = '<span class="poll-option-label">%s</span>' % option
            self.assertTrue(markup in browser.contents)

        # no vote-interface anymore:
        voteButton = helpers.try_get_control(browser, name='form.button.Vote')
        self.assertTrue(voteButton is None)

        # let's edit the poll:
        editButton.click()

        # we can change the title and text:
        title = browser.getControl(name='form.widgets.title')
        title.value = "The edited Poll"
        text = browser.getControl(name='form.widgets.text')
        text.value = "<p>This is a much better text.</p>"

        # we can not change the options or poll type:
        optWidget = helpers.try_get_control(browser, name='form.widgets.options')
        self.assertEqual(optWidget, None)
        pollOrRating = helpers.try_get_control(browser, name='form.widgets.pollOrRating:list')
        self.assertEqual(pollOrRating, None)

        # ok, save:
        browser.getControl(name='form.buttons.save').click()

        # we're be send to the polls view again:
        self.assertTrue("The edited Poll" in browser.contents)
        self.assertTrue("This is a much better text." in browser.contents)

        # we still see the polls results:
        for option in options:
            markup = '<span class="poll-option-label">%s</span>' % option
            self.assertTrue(markup in browser.contents,
                '"%s" doesn\'t seem to be displayed' % option)
    def test_browse_rating(self):
        """A minimal functional test for ratings."""
        setRoles(self.portal, TEST_USER_ID, ('Manager',))

        # create, publish and join a workspace:
        ws = helpers.create_workspace(self.portal, 'ws1', title=u"Workspace 1")
        ws.addMember(SITE_MEMBER)

        import transaction
        transaction.commit()

        browser = Browser(self.app)
        browser.handleErrors = False

        # Log in as a user
        browser.addHeader(
            'Authorization',
            'Basic %s:%s' % (SITE_MEMBER, PASSWORD,))

        # go to conversation:
        browser.open("%s/conversation" % ws.absolute_url())

        # create a rating:
        browser.getLink(text='Poll').click()
        title = browser.getControl(name='form.widgets.title')
        title.value = "The Rating"
        text = browser.getControl(name='form.widgets.text')
        text.value = "<p>Rate this.</p>"
        pollOrRating = \
            browser.getControl(name='form.widgets.pollOrRating:list')
        pollOrRating.value = ["rating"]
        browser.getControl(name='form.buttons.save').click()

        self.assertIn('the-rating', ws)
        rating = ws['the-rating']

        # publish the rating:
        # TODO: we cheat because there is no publishing interface availible to
        #       normal users.
        pw = getToolByName(self.portal, 'portal_workflow')
        pw.doActionFor(rating, "publish")

        transaction.commit()

        # the rating should be published:
        self.assertEqual(pw.getInfoFor(rating, 'review_state'), 'published')

        # on the view:
        option = helpers.try_get_control(browser, name='option')
        self.assertEqual(option.options, [str(x) for x in range(0, 6)])
        voteButton = helpers.try_get_control(browser, name='form.button.Vote')
        self.assertTrue(voteButton is not None)

        # vote for something:
        option.value = ['3']
        voteButton.click()

        # rating results should be shown:
        # TODO: don't know yet what the markup is going to look like.
        # markup = '???'
        # self.assertTrue(markup in browser.contents)

        # no vote-interface anymore:
        voteButton = helpers.try_get_control(browser, name='form.button.Vote')
        self.assertTrue(voteButton is None)