Browser test
=============

Accessing as portal owner
-------------------------

  >>> from Products.Five.testbrowser import Browser
  >>> from Testing.ZopeTestCase import user_password
  >>> browser = Browser()
  >>> browser.addHeader('Authorization',
  ...                   'Basic %s:%s' % ('portal_owner', user_password))

Accessing as anonymous user
---------------------------

  >>> anBrowser = Browser()

Create a content
----------------

First we create a Hello World news item on the portal root ::

  >>> browser.open(self.portal.absolute_url())
  >>> browser.getLink('Add new').click()
  >>> 'Add new item' in browser.contents
  True
  >>> browser.getControl('News Item').click()
  >>> browser.getControl('Add').click()
  >>> browser.getControl('Title').value = 'Hello World'
  >>> browser.getControl('Save').click()
  >>> 'Changes saved.' in browser.contents
  True
  >>> browser.url == 'http://nohost/plone/hello-world'
  True

Validating if we are counting accesses
--------------------------------------

Let's check if we have the viewcounter viewlet comment inside our source code::

  >>> '<!-- viewcounter -->' in browser.contents
  False

That happens because we will only count access to contents in chosen workflow states -- per default, published -- so we need to publish this content::

  >>> browser.getLink(url='%s/content_status_history' % browser.url).click()
  >>> browser.getControl('Publish').click()
  >>> browser.getControl('Save').click()
  >>> 'published.' in browser.contents
  True

Let's check again for the viewcounter marker::

    >>> '<!-- viewcounter -->' in browser.contents
    True

Now accessing the same content as anonymous we should also have the viewlet enabled::
   
   >>> anBrowser.open('%s/hello-world' % self.portal.absolute_url())
   >>> '<!-- viewcounter -->' in browser.contents
   True

Edit and sharing views
----------------------

Edit and sharing views should not count as valids content accesses::

    >>> browser.getLink('Edit').click()
    >>> browser.url == 'http://nohost/plone/hello-world/edit'
    True
    >>> '<!-- viewcounter -->' in browser.contents
    False
    
    >>> browser.getLink('Sharing').click()
    >>> browser.url == 'http://nohost/plone/hello-world/@@sharing'
    True
    >>> '<!-- viewcounter -->' in browser.contents
    False