Internet contact info
========================

Implementation of a behavior providing common used contact info

Test Internet Contact Info
---------------------------

When we create a dexterity content type::

    >>> app = layer['app']
    >>> portal = layer['portal']
    >>> portalURL = portal.absolute_url()
    >>> from plone.dexterity.fti import DexterityFTI
    >>> from collective.behavior.contactinfo.behavior.contactinfo import INetContactInfo
    >>> fti = DexterityFTI('simple_type')
    >>> fti.behaviors = ('collective.behavior.contactinfo.behavior.contactinfo.INetContactInfo',)
    >>> portal.portal_types._setObject('simple_type', fti)
    'simple_type'
    >>> schema = fti.lookupSchema()

If we access the site as an admin TTW::

    >>> from plone.app.testing import TEST_USER_ID, TEST_USER_PASSWORD, setRoles
    >>> setRoles(portal, TEST_USER_ID, ['Manager'])
    >>> import transaction; transaction.commit()
    >>> from plone.testing.z2 import Browser
    >>> browser = Browser(app)
    >>> browser.addHeader('Authorization', 'Basic %s:%s' % (TEST_USER_ID, TEST_USER_PASSWORD,))

We can see this type in the addable types at the root of the site::

    >>> browser.open("http://nohost/plone/folder_factories")
    >>> "simple_type" in browser.contents
    True
    >>> browser.getControl("simple_type").click()
    >>> browser.getControl("Add").click()
    >>> browser.getControl(name="form.widgets.title").value = "Foo"
    >>> browser.getControl(name="form.widgets.INetContactInfo.email").value = "email@domain.com"
    >>> browser.getControl(name="form.widgets.INetContactInfo.twitter").value = "@bomdiaporque"
    >>> browser.getControl(name="form.widgets.INetContactInfo.irc_nickname").value = "bomdiaporque"
    >>> browser.getControl(name="form.widgets.INetContactInfo.site").value = "http://domain.com"
    >>> browser.getControl(name="form.buttons.save").click()
    >>> browser.url
    'http://nohost/plone/simple_type/view'

We can now access our type and its values::

    >>> md = portal.simple_type
    >>> md.email
    u'email@domain.com'
    >>> md.twitter
    u'@bomdiaporque'
    >>> md.irc_nickname
    u'bomdiaporque'
    >>> md.site
    'http://domain.com'

Test Behavior selection
----------------------------

This will test adding a behavior to an existing content type.

When we create a dexterity content type::

    >>> fti = DexterityFTI('new_simple_type')
    >>> portal.portal_types._setObject('new_simple_type', fti)
    'new_simple_type'
    >>> schema = fti.lookupSchema()
    >>> import transaction; transaction.commit()

We can see this type in the addable types at the root of the site::

    >>> browser.open("http://nohost/plone/folder_factories")
    >>> "new_simple_type" in browser.contents
    True
    >>> browser.getControl("new_simple_type").click()
    >>> browser.getControl("Add").click()
    >>> browser.getControl(name="form.widgets.title").value = "Foo"
    >>> browser.getControl(name="form.buttons.save").click()
    >>> browser.url
    'http://nohost/plone/new_simple_type/view'

Now we add the behavior to this new content type::

    >>> portal.portal_types['new_simple_type'].behaviors = ('collective.behavior.contactinfo.behavior.contactinfo.INetContactInfo',)
    >>> import transaction; transaction.commit()

And visit an existing content::

    >>> browser.open("http://nohost/plone/new_simple_type/view")
    >>> "email" in browser.contents
    True
    
    

