==============================================================================
Doctest generated Sun Ago 10 2008 17:09:17 GMT-0300 (ART)
==============================================================================

Create the browser object we'll be using.

    >>> from Products.Five.testbrowser import Browser
    >>> from Products.PloneTestCase.setup import portal_owner, default_user, default_password
    >>> browser = Browser()
    >>> portal_url = self.portal.absolute_url()

First we login

    >>> login_url = portal_url + '/login_form'
    >>> browser.open(login_url)

We have the login portlet, so let's use that.

    >>> browser.getControl(name='__ac_name').value = portal_owner
    >>> browser.getControl(name='__ac_password').value = default_password
    >>> browser.getControl(name='submit').click()
    >>> self.setRoles(['Manager'])

Now we create a folder were we're able to create success stories

    >>> browser.open(portal_url)
    >>> browser.getLink('Add new').click()
    >>> browser.getControl('Success Story Folder').click()
    >>> browser.getControl('Add').click()
    >>> browser.getControl('Title').value="Success Stories"
    >>> browser.getControl('Save').click()

Now we add the Success Story portlet and check that is not showing.

    >>> add_portlet = portal_url + "/++contextportlets++plone.rightcolumn/+/atss.rotating.portlet"
    >>> browser.open(add_portlet)
    >>> browser.getControl('Header').value = "Testing portlet"
    >>> browser.getControl(name="form.searchpath").value = ['/plone/success-stories']
    >>> browser.getControl(name="form.number_of_stories").value = '1'
    >>> browser.getControl('Save').click()
    >>> 'error' not in browser.contents.lower()
    True
    >>> 'Success Story Portlet' in browser.contents
    True
    >>> browser.open(portal_url)
    >>> 'testing portlet' not in browser.contents.lower()
    True
    >>> 'error' not in browser.contents.lower()
    True

Ok, we already have our portlet, and is not showing nothing, since we have no success stories loaded
Let's load two of them

    >>> atssf = portal_url + '/success-stories'
    >>> browser.open(atssf)
    >>> test_file_1 = open(('/'.join(__file__.split('/')[:-1]))+'/input/image1.jpg','rb')
    >>> test_file_2 = open(('/'.join(__file__.split('/')[:-1]))+'/input/image2.jpg','rb')
    >>> #Success stories should be created as below, but apparently it doesn't work
    >>> #browser.getLink('Add new').click()
    >>> #browser.getControl('Success Story').click()
    >>> #browser.getControl('Add').click()
    >>> #browser.getControl('Title').value = 'Success Story 1'
    >>> #browser.getControl('Description').value = 'Showing in the portlet number 1'
    >>> #browser.getControl('Story').value = 'This is the story for number 1'
    >>> #browser.getControl(name="Image_file").value = test_file_1
    >>> #browser.getControl('Save').click()
    >>> folder = getattr(self.portal, 'success-stories')
    >>> folder.invokeFactory('ATSuccessStory', 'success-story-1', title='Success Story 1', description='Showing in the portlet number 1', story='This is the story for number 1', image=test_file_1)
    'success-story-1'
    >>> folder.invokeFactory('ATSuccessStory', 'success-story-2', title='Success Story 2', description='Showing in the portlet number 2', story='This is the story for number 2', image=test_file_2)
    'success-story-2'


We have our success stories, we go to the portal root, where our portlet was, and check that it is showing and that it
shows one of the two stories

    >>> browser.open(portal_url)
    >>> 'testing portlet' in browser.contents.lower()
    True
    >>> content = browser.contents.lower()
    >>> atss1 = 'success story 1' in content and 'showing in the portlet number 1' in content
    >>> atss2 = 'success story 2' in content and 'showing in the portlet number 2' in content
    >>> atss1 or atss2
    True

Now we will add another success stories folder, add more stories inside and add a global portlet
that will list all stories from site

    >>> browser.open(portal_url)
    >>> browser.getLink('Add new').click()
    >>> browser.getControl('Success Story Folder').click()
    >>> browser.getControl('Add').click()
    >>> browser.getControl('Title').value="Success Stories 2"
    >>> browser.getControl('Save').click()

And we add the global portlet

    >>> add_portlet = portal_url + "/++contextportlets++plone.rightcolumn/+/atss.rotating.portlet"
    >>> browser.open(add_portlet)
    >>> browser.getControl('Header').value = "Testing global portlet"
    >>> browser.getControl(name="form.searchpath").value = ['/plone']
    >>> browser.getControl(name="form.number_of_stories").value = '5'
    >>> browser.getControl('Save').click()
    >>> 'error' not in browser.contents.lower()
    True
    >>> 'Success Story Portlet' in browser.contents
    True
    >>> browser.open(portal_url)
    >>> 'error' not in browser.contents.lower()
    True

Ok, we have our portlet, and should be showing the existing stories from the previous tests

    >>> atssf = portal_url + '/success-stories-2'
    >>> browser.open(atssf)
    >>> test_file_1 = open(('/'.join(__file__.split('/')[:-1]))+'/input/image1.jpg','rb')
    >>> test_file_2 = open(('/'.join(__file__.split('/')[:-1]))+'/input/image2.jpg','rb')
    >>> #Success stories should be created as below, but apparently it doesn't work
    >>> #browser.getLink('Add new').click()
    >>> #browser.getControl('Success Story').click()
    >>> #browser.getControl('Add').click()
    >>> #browser.getControl('Title').value = 'Success Story 1'
    >>> #browser.getControl('Description').value = 'Showing in the portlet number 1'
    >>> #browser.getControl('Story').value = 'This is the story for number 1'
    >>> #browser.getControl(name="Image_file").value = test_file_1
    >>> #browser.getControl('Save').click()
    >>> folder = getattr(self.portal, 'success-stories-2')
    >>> folder.invokeFactory('ATSuccessStory', 'success-story-3', title='Success Story 3', description='showing in the portlet number 3', story='This is the story for number 3', image=test_file_1)
    'success-story-3'
    >>> folder.invokeFactory('ATSuccessStory', 'success-story-4', title='Success Story 4', description='showing in the portlet number 4', story='This is the story for number 4', image=test_file_2)
    'success-story-4'
    >>> folder.invokeFactory('ATSuccessStory', 'success-story-5', title='Success Story 5', description='showing in the portlet number 5', story='This is the story for number 5', image=test_file_2)
    'success-story-5'

Now we go back to the portal url and check the portlet

    >>> browser.open(portal_url)
    >>> 'testing global portlet' in browser.contents.lower()
    True
    >>> content = browser.contents.lower()
    >>> atss1 = 'success story 1' in content and 'showing in the portlet number 1' in content
    >>> atss2 = 'success story 2' in content and 'showing in the portlet number 2' in content
    >>> atss3 = 'success story 3' in content and 'showing in the portlet number 3' in content
    >>> atss4 = 'success story 4' in content and 'showing in the portlet number 4' in content
    >>> atss5 = 'success story 5' in content and 'showing in the portlet number 5' in content
    >>> atss1 and atss2 and atss3 and atss4 and atss5
    True
