Add the default profile and check the test content is present
=============================================================

Integration and functional tests for conent created by the 
test profile install by Ed Crewe, ILRT (University of Bristol) 
January 2009

This test uses the default profile which just installs the 
minimum of content ie. two folders, the second a copy of the first,
both containing a subfolder with two pages and an image in it.

Check that the content generator plone site is added

    >>> portal.getId()
    'plone'

Confirm it has the default content profile structure
----------------------------------------------------

Find the default folder created by the test theme

    >>> folder = getattr(portal,'default1',None)
    >>> folder.getId()
    'default1'

Get the subfolder created in it

    >>> subfolder = getattr(folder,'subfolder1',None)

Check that the subfolder contains three items

    >>> subfolderids = ['ids',]
    >>> subfoldertitles = ['titles',]
    >>> for item in subfolder.items():
    ...     subfolderids.append(item[0])
    ...     subfoldertitles.append(item[1].title)
    >>> len(subfolderids)
    4

Keep the ids for the browser test

    >>> folderids = subfolderids[1:]

Find the cloned folder

    >>> clone = getattr(portal,'default1copy1',None)
    >>> clone.getId()
    'default1copy1'
    >>> subclone = getattr(clone,'subfolder1',None)

Now confirm they contain the same content or at least 
the number of objects, their ids and titles are the same

    >>> for item in subclone.items():
    ...     subfolderids.remove(item[0])
    ...     subfoldertitles.remove(item[1].title)
    >>> subfolderids
    ['ids']
    >>> subfoldertitles
    ['titles']

Functional tests that everything is there as expected via a browser
-------------------------------------------------------------------

First, we must perform some setup of the test browser.

    >>> from Products.Five.testbrowser import Browser
    >>> portal_url = portal.absolute_url()
    >>> browser = Browser()

The default profile installs a minimum folder with a document and image which 
is then duplicated to a second folder.
Hence a browser test that the above content exists confirms that the core 
functionality of contentgenerator is in place. 

Next we need to login using the default user from PloneTestCase:

    >>> from Products.PloneTestCase.setup import portal_owner, default_password
    >>> browser.open(portal_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()

We check that we get the logged-in message:

    >>> "You are now logged in" in browser.contents
    True

Now check via the browser that a folder has been created which contains a flickr image

    >>> browser.open(portal_url + '/default1/subfolder1')
    >>> 'flickr' in browser.contents
    True

Get the ids of the image and a page

    >>> for id in folderids:
    ...    if id.startswith('flickr'):
    ...        imageid = id
    ...    else:
    ...        pageid = id

Get the image and check it is an image of non-zero length

    >>> browser.open(portal_url + '/default1/subfolder1/' + imageid)
    >>> browser.headers['content-type']
    'image/jpeg'
    >>> int(browser.headers['content-length'])>100
    True

Get the page and check it is a page of non-zero length

    >>> browser.open(portal_url + '/default1/subfolder1/' + pageid)
    >>> browser.isHtml
    True
    >>> int(browser.headers['content-length'])>100
    True
