==============================================================================
Doctest generated Mon Oct 15 2007 12:36:37 GMT+0200 (CEST)
by cjj
==============================================================================

Create the browser object we'll be using.

    >>> from Products.Five.testbrowser import Browser
    >>> browser = Browser()
    >>> browser.handleErrors = False
    >>> browser.open(portal.absolute_url())
    >>> 'Welcome to Plone' in browser.contents
    True

Preparing the site to test for anonymous and logged in users behaviour of
address book in checkout

     >>> membership = self.portal.portal_membership
     >>> membership.addMember('testmanager', 'secret',
     ...             ['Member', 'Manager'], [])
     >>> membership.getMemberById('testmanager').setMemberProperties({'email':'testmember@getpaid.org','location':'here on earth'})
     >>> 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')
     'Installing Dependencies\n'
     >>> browser.getLink('Home').click()
 
Setting required settings. (Especially anonymous checkout)

    >>> 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(name = 'form.allow_anonymous_checkout').value = True
    >>> 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('Email Notifications').click()
    >>> browser.getControl(name='form.merchant_email_notification').displayValue = ['Do not send merchant email notification of a completed transaction']
    >>> 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
    >>> browser.getLink('Payment Options').click()
    >>> browser.getControl(name ='form.allow_anonymous_checkout').value
    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']

Here we set up the Credit cards accepted for payment:

   >>> options.accepted_credit_cards = ["Visa"]

Add a buyable document.

    >>> browser.getLink('Home').click()
    >>> browser.getLink('Make Buyable').click()
    >>> browser.getControl('Product Code').value = 'PAY-ME'
    >>> browser.getControl('Price').value = '42.17'
    >>> browser.getControl('Activate').click()
  
We want it (again) so we buy it.

    >>> browser.getLink('Home').click()
    >>> 'Add to Cart' in browser.contents
    True
    >>> browser.getLink('Add to Cart').click()

And we do our anonymous checkout

    >>> browser.getControl('Checkout').click()

We check that the fields are not empty since now we are logged in
    
    >>> browser.getControl(name='form.name').value = 'username'
    >>> browser.getControl(name='form.email').value = 'testmanager@getpaid.org'
    >>> browser.getControl(name='form.phone_number').value = '55555555'
    >>> browser.getControl(name='form.bill_name').value = 'username'
    >>> browser.getControl(name='form.bill_first_line').value = 'here on earth'
    >>> browser.getControl(name='form.bill_city').value = 'doctic city'
    >>> browser.getControl(name='form.bill_country').value = ['US']
    >>> browser.getControl(name='form.bill_state').displayValue = ['Alabama']
    >>> browser.getControl(name='form.bill_postal_code').value = '5000'
    >>> browser.getControl(name='form.ship_same_billing').value = True

We fill this field that wouldn't be visible normaly but the button that
enables it does javascript which is not supported by doctests

    >>> browser.getControl(name='addressbook_entry_name').value = 'my first entry'

we check that the user gets confirmation
after saving on the Address book

    >>> browser.getControl(name='form.actions.continue').click()
    >>> 'A new address has been saved' in browser.contents
    True

in the Address book utility should be the entry

    >>> from zope import component
    >>> from Products.PloneGetPaid.interfaces import IAddressBookUtility
    >>> adressBookUtility = component.queryUtility(IAddressBookUtility,context=self.portal)
    >>> addressBookUser = adressBookUtility.get('testmanager')
    >>> address = addressBookUser['my first entry']
    >>> address != None 
    True
    
finally we check that all the data is store

    print dir(address)

    >>> address.ship_first_line == 'here on earth'
    True
    >>> address.ship_city == 'doctic city'
    True
    >>> address.ship_country == 'US'
    True
    >>> address.ship_state == 'US-AL'
    True
    >>> address.ship_postal_code == '5000'
    True

Finished verification.
