And and view a blog item
========================


The scoop of this browser test is to ensure the view templates of the a blog
entry and the blog entries listings are working in a *real* browser.


Setup doctest
=============

Create a test browser and log in.

    >>> from Products.Five.testbrowser import Browser
    >>> browser = Browser()
    >>> portal_url = self.portal.absolute_url()
    >>> browser.open(portal_url + '/login_form')
    >>> from Products.PloneTestCase.setup import portal_owner, default_password
    >>> browser.getControl(name='__ac_name').value = portal_owner
    >>> browser.getControl(name='__ac_password').value = default_password
    >>> browser.getControl(name='submit').click()
    >>> 'You are now logged in' in browser.contents
    True


Add a blog entry
================


We use the 'Add new' menu to add a new content item.

    >>> browser.open(portal_url)
    >>> browser.getLink('Add new').click()

Then we select the type of item we want to add. In this case we select
'Page' and click the 'Add' button to get to the add form.

    >>> browser.getControl('Blog Entry').click()
    >>> browser.getControl(name='form.button.Add').click()
    >>> 'Blog Entry' in browser.contents
    True

Fill in the fields

    >>> browser.getControl(name='title').value = 'Blog entry - Plone conference 2009'
    >>> browser.getControl(name='description').value = 'Plone conference 2009 and sprint was great !'
    >>> browser.getControl(name='text').value = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'
    >>> browser.getControl(name='subject_keywords:lines').value = 'plone\npython\nbudapest'
    >>> browser.getControl('Save').click()    
    >>> 'Changes saved' in browser.contents
    True

Lets add an image as well.

    >>> browser.getLink('Edit').click()

First prepare image upload, create a fake image file/image. 
The approach from http://tr.im/DNee is done slightly different since 
doing StringIO.StringIO('my photo') raised errors about string is not an image.

    >>> from base64 import decodestring 
    >>> import StringIO
    >>> data = decodestring('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAEALAAAAAABAAEAAAIBTAA7\n') 
    >>> myPhoto = StringIO.StringIO(data)
    >>> control = browser.getControl(name='image_file')
    >>> fileControl = control.mech_control
    >>> fileControl.add_file(myPhoto, filename='myPhoto.gif')
    >>> browser.getControl('Save').click()

Lets publish our great blog post. Take care here in the UI TTW it said 'Changes saved' but its slightly
different in the browser test.

    >>> browser.getLink('Publish').click()
    >>> 'Item state changed' in browser.contents
    True

Lets have a quick look at the blog entry. 

There should be an image, "news item style".

    >>> '<img src="http://nohost/plone/blog-entry-plone-conference-2009/image_mini" alt="Blog entry - Plone conference 2009" title="Blog entry - Plone conference 2009" height="1" width="1" class="newsImage" />' in browser.contents or '<img src="http://nohost/plone/blog-entry-plone-conference-2009/image_mini" alt="Blog entry - Plone conference 2009" title="" height="1" width="1" class="newsImage" />' in browser.contents
    True

Tags (filed under...) should be clickable.

    >>> browser.getLink('budapest').click()
    >>> tag_url = '%s/search?Subject=budapest' % portal_url
    >>> browser.url == tag_url
    True
    
    >>> browser.getLink('Blog entry - Plone conference 2009').click()
 
Lets create the collection for the Blog listing view (blog_view.pt). We are a bit pragmatic 
here and doesn't create the collection browser test style.

    >>> self.setRoles(('Manager',))    
    >>> blog = self.portal.invokeFactory('Topic','blog', title='List all blog entries')
    >>> blog = self.portal.blog
    >>> blog.setText('Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.')    
    >>> type_crit = blog.addCriterion('portal_type', 'ATSimpleStringCriterion')
    >>> type_crit.setValue('Blog Entry')    
    >>> state_crit = blog.addCriterion('review_state', 'ATSimpleStringCriterion')
    >>> state_crit.setValue('published')
    >>> blog.setSortCriterion('effective', True)        
    >>> blog.setLayout('blog_view')
    >>> blog.unmarkCreationFlag()  

Lets have a look at the Blog listing view. Our nice blog entry about the fabulous
Budapest conference 2009 / sprint should be listed.

    >>> blog_url = "%s/blog" % portal_url 
    >>> browser.open(blog_url)
    >>> 'Blog entry - Plone conference 2009' in browser.contents
    True

The tags (filed under...) should also be clickable in the blog entries listing.

    >>> browser.getLink('python').click()
    >>> tag_url = '%s/blog?Subject=python' % portal_url
    >>> browser.url == tag_url
    True 

Lets go back to the listing
    >>> browser.getLink('List all blog entries').click()

There should be an image as well in the listing, "folder summary view style".

    >>> '<img src="http://nohost/plone/blog-entry-plone-conference-2009/image_thumb" alt="Blog entry - Plone conference 2009" title="Blog entry - Plone conference 2009" height="1" width="1" class="tileImage" />' in browser.contents or '<img src="http://nohost/plone/blog-entry-plone-conference-2009/image_thumb" alt="Blog entry - Plone conference 2009" title="" height="1" width="1" class="tileImage" />' in browser.contents
    True

