
==============================================================================
Doctest half stolen half handwritten
created by Juan Pablo Giménez
==============================================================================

Create the browser object we'll be using.

    >>> from Products.Five.testbrowser import Browser
    >>> browser = Browser()
    >>> browser.handleErrors = False
    >>> browser.open(self.portal.absolute_url())
    >>> 'Welcome to Plone' in browser.contents
    True
     >>> membership = self.portal.portal_membership
     >>> membership.addMember('testmanager', 'secret',
     ...                      ['Member', 'Manager'], [])

     >>> browser.getLink('Log in').click()
     >>> browser.getControl('Login Name').value = 'testmanager'
     >>> browser.getControl('Password').value = 'secret'
     >>> browser.getControl('Log in').click()
     >>> self.portal.portal_quickinstaller.installProduct('PloneGetPaid')
     ''
     >>> browser.getLink('Home').click()

Testing the setup aspects of GetPaid. Setting required settings.

    >>> browser.getLink('Site Setup').click()
    >>> browser.getLink('GetPaid').click()
    >>> browser.getLink('Site Profile').click()
    >>> browser.getControl('Contact Email').value = 'info@plonegetpaid.com'
    >>> browser.getControl( name="form.store_name").value = 'Test this fake company'
    >>> browser.getControl('Contact Country').value = ['US']
    >>> browser.getControl('Apply').click()
    >>> browser.getLink('GetPaid').click()
    >>> browser.getLink('Content Types').click()
    >>> browser.getLink('GetPaid').click()
    >>> browser.getLink('Payment Options').click()
    >>> browser.getControl(name = 'form.payment_processor').displayValue = ['Testing Processor']
    >>> browser.getControl(name = 'form.allow_anonymous_checkout.used').value = 'on'
    >>> browser.getControl('Apply').click()
    >>> browser.getLink('GetPaid').click()
    >>> browser.getLink('Payment Processor Settings').click()
    >>> browser.getControl(name="form.allow_authorization").displayValue = ['allow_authorization']
    >>> browser.getControl(name="form.allow_capture").displayValue = ['allow_capture']
    >>> browser.getControl(name="form.allow_refunds").displayValue = ['allow_refund']
    >>> browser.getControl('Apply').click()
    >>> browser.getLink('GetPaid').click()
    >>> browser.getLink('Legal Disclaimers').click()
    >>> browser.getControl(name='form.disclaimer').value = 'Test disclaimer'
    >>> browser.getControl(name='form.privacy_policy').value = 'Test privacy policy'
    >>> browser.getControl('Apply').click()
    >>> browser.getLink('GetPaid').click()
    >>> 'Test this fake company' in browser.contents
    True

Here we are setting the buyable types for use in the following tests

    >>> from Products.PloneGetPaid.interfaces import IGetPaidManagementOptions
    >>> options = IGetPaidManagementOptions(self.portal)
    >>> options.buyable_types = ['Document']
    >>> options.donate_types = ['Document']
    >>> options.shippable_types = ['Document']


Check to make sure the settings we put in Site Profile appear on this page.

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

Testing process of configuring Plone content for "buyable" states of donation, buyable and shippable. Depends on options that were set in the admin functional tests.

Test Make Buyable

    >>> browser.getLink('Make Buyable').click()
    >>> browser.getControl(name='form.product_code').value = 'Test Buy Code #1'
    >>> browser.getControl(name='form.price').value = '10.00'
    >>> browser.getControl('Activate').click()

Test for expected results in home page.  There should be a link to reverse it and a price in the portlet on the right

    >>> browser.getLink('Home').click()
    >>> 'Make Not Buyable' in browser.contents
    True
    >>> '10.00' in browser.contents
    True

    >>> from Products.PloneGetPaid import interfaces
    >>> self.setRoles(('Manager'),)
    >>> self.portal.invokeFactory('Document', 'testpage1')
    'testpage1'

    >>> testpage = self.portal.testpage1
    >>> IRecurringPaymentMarker = interfaces.IRecurringPaymentMarker
    >>> from Products.Five.utilities.marker import mark
    >>> mark(testpage, IRecurringPaymentMarker)
    >>> IRecurringPaymentMarker(testpage)
    <ATDocument at ...>
    >>> IRecurringPaymentMarker.providedBy( testpage )
    True

Test for recurring payment in the actions dropdown...
We have the text and is a link...

    >>> self.portal.invokeFactory('Document', 'testpage2')
    'testpage2'

    >>> testpage = self.portal.testpage2
    >>> browser.open(testpage.absolute_url())
    >>> browser.getLink('Make Recurring Payable')
    <Link text='Make Recurring Payable' ...>

We don't have a "disable" button link...
    >>> browser.getLink('Make Not Recurring Payable')
    Traceback (most recent call last):
    ...
    LinkNotFoundError

    >>> browser.getLink('Make Recurring Payable').click()

We are going to activate a recurring payment?
    >>> browser.getForm(action='activate-recurring-payment')
    <zope.testbrowser.browser.Form ...>

Yes, so fill up the form...
    >>> browser.getControl(name='form.price').value = '1'
    >>> browser.getControl(name='form.product_code').value = 'Test Buy Code #2'
    >>> browser.getControl(name='form.interval').value = '1'
    >>> browser.getControl(name='form.total_occurrences').value = '1'
    >>> browser.getControl('Activate').click()

We can disable...
    >>> browser.getLink(url='@@deactivate-recurring-payment')
    <Link text='Make Not Recurring Payable' ...>

But we can't enable again...
    >>> browser.getLink(url='@@activate-recurring-payment')
    Traceback (most recent call last):
    ...
    LinkNotFoundError

    >>> browser.getLink(url='@@deactivate-recurring-payment').click()

We can't disable it twice...
    >>> browser.getLink(url='@@deactivate-recurring-payment')
    Traceback (most recent call last):
    ...
    LinkNotFoundError

But we can enable again...
    >>> browser.getLink(url='@@activate-recurring-payment')
    <Link text='Make Recurring Payable' ...>
    >>> browser.getLink(url='@@activate-recurring-payment').click()

fill up the form...
    >>> browser.getControl(name='form.price').value = '2'
    >>> browser.getControl(name='form.product_code').value = 'Test Buy Code #3'
    >>> browser.getControl(name='form.interval').value = '2'
    >>> browser.getControl(name='form.total_occurrences').value = '2'
    >>> browser.getControl('Activate').click()

And we will test the checkout process now...
First, we have the portlet?

    >>> "Recurring Payable Content Portlet" in browser.contents
    True

Then add it to the cart...
    >>> browser.getControl('Add to Cart').click()

Then we can see the details in the cart listing...

    >>> 'You will be billed for this product every 2 months, for a total of 2 payments.' in browser.contents
    True
