Sitemap testing
===============

First some initial setup code:

    >>> self.loginAsPortalOwner()

There is a site property which controls accesso to the sitemap. This defaults
to off, since generating the sitemap is an expensive operation which can
easily lead to denial of service attack.

    >>> self.portal.portal_properties.site_properties.getProperty("enable_sitemap")
    False


Disabled sitemap
----------------

Trying to download the sitemap while it is not enabled results in an error:

    >>> self.browser.open('http://nohost/plone/sitemap.xml.gz')
    Traceback (most recent call last):
    ...
    HTTPError: HTTP Error 404: Not Found


Obtain the sitemap
------------------

To test the sitemap we first need to enable it:

    >>> self.portal.portal_properties.site_properties.manage_changeProperties(enable_sitemap=True)

Then modify worklfow to have some private content with the folder_workflow:

    >>> self.portal.portal_workflow.setChainForPortalTypes(['Large Plone Folder'], ('folder_workflow',))
    >>> updated = self.portal.portal_workflow.updateRoleMappings()

'Events' folder will be published and in the archive:

    >>> self.portal.portal_workflow.getChainFor(self.portal.events)
    ('folder_workflow',)
    >>> self.portal.portal_workflow.getInfoFor(self.portal.events, 'review_state')
    'visible'
    >>> self.portal.portal_workflow.doActionFor(self.portal.events, 'publish')
    >>> self.portal.portal_workflow.getInfoFor(self.portal.events, 'review_state')
    'published'

'News' folder will be visible and in the archive:

    >>> self.portal.portal_workflow.getInfoFor(self.portal.news, 'review_state')
    'visible'

'Members' folder will be private and should not be in the archive

    >>> self.portal.portal_workflow.getInfoFor(self.portal.Members, 'review_state')
    'visible'
    >>> self.portal.portal_workflow.doActionFor(self.portal.Members, 'hide')
    >>> self.portal.portal_workflow.getInfoFor(self.portal.Members, 'review_state')
    'private'

Finally log out because search bots are not authenticated:

    >>> self.logout()

we can now open the sitemap:

    >>> self.browser.open('http://nohost/plone/sitemap.xml.gz')
    >>> self.browser.url
    'http://nohost/plone/sitemap.xml.gz'

Get the contents and decode them
    >>> data = self.browser.contents
    >>> from gzip import GzipFile
    >>> from StringIO import StringIO
    >>> sio = StringIO(data)
    >>> fp = GzipFile(fileobj=sio)
    >>> xml = fp.read()
    >>> fp.close()

Not sure how to test the XML now as it also contains dates but for now
we will just search for some URLs and tags.

    >>> xml.find('<loc>http://nohost/plone/front-page</loc>')!=-1
    True
    >>> xml.find('<loc>http://nohost/plone/events</loc>')!=-1
    True
    >>> xml.find('<loc>http://nohost/plone/news</loc>')!=-1
    True
    >>> xml.find('<loc>http://nohost/plone/Members</loc>')!=-1
    False
