Testing PloneArticle support for finding file links
===================================================

.. Copyright (C) 2008 Ingeniweb

.. This program is free software; you can redistribute it and/or modify
.. it under the terms of the GNU General Public License as published by
.. the Free Software Foundation; either version 2 of the License, or (at
.. your option) any later version.

.. This program is distributed in the hope that it will be useful, but
.. WITHOUT ANY WARRANTY; without even the implied warranty of
.. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
.. General Public License for more details.

.. You should have received a copy of the GNU General Public License
.. along with this program; see the file LICENSE.txt. If not, write to
.. the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
.. USA.

.. $Id: test_plonearticle_linksfinder.txt 36 2008-09-07 09:08:55Z glenfant $

Some inits and setups
---------------------

  >>> from zope.component import getAdapter
  >>> from iw.sitestat.interfaces import IFileLinksFinder
  >>> self.loginAsPortalOwner()
  >>> from iw.sitestat.tests import utils as ns_utils
  >>> from Products.Archetypes.public import BaseUnit
  >>> self.loginAsPortalOwner()
  >>> foo_art = ns_utils.addPloneArticle(self.portal, 'foo', 'Foo')
  >>> foo_art.title_or_id()
  'Foo'

Let's add a PDF file
--------------------

  >>> file_bu = BaseUnit('loremipsum.pdf', ns_utils.LOREM_IPSUM_PDF)
  >>> settings = ({
  ...     'description': ('Lorem Ipsum is essential talk', {}),
  ...     'id': ('loremipsum.pdf', {}),
  ...     'attachedFile': (file_bu, {}),
  ...     'title': ('Lorem Ipsum', {})
  ...     },)
  >>> ffield = foo_art.getField('files')
  >>> ffield.set(foo_art, settings)

Finding apppropriate links finder
---------------------------------

  >>> links_finder = getAdapter(foo_art, IFileLinksFinder)
  >>> links_finder
  <iw.sitestat.linksfinders.thirdparty.plonearticle.PloneArticleFileLinksFinder...>

Getting the file links from that article
----------------------------------------

  >>> links_finder.fileURLs()
  []
  >>> links_finder.pdfFileURLs()
  ['http://nohost/plone/foo/files/loremipsum.pdf']

Let's add an HTML file
----------------------

  >>> html_bu = BaseUnit('loremipsum.html', ns_utils.LOREM_IPSUM_HTML)
  >>> settings =  settings + ({
  ...     'description': ('Lorem Ipsum is essential talk', {}),
  ...     'id': ('loremipsum.html', {}),
  ...     'attachedFile': (html_bu, {}),
  ...     'title': ('Lorem Ipsum', {})
  ...     },)
  >>> ffield = foo_art.getField('files')
  >>> ffield.set(foo_art, settings)
  >>> len(ffield.get(foo_art))
  2

And let's check the file links from the article
-----------------------------------------------

  >>> links_finder = getAdapter(foo_art, IFileLinksFinder)
  >>> links_finder.fileURLs()
  ['http://nohost/plone/foo/files/loremipsum.html']
  >>> links_finder.pdfFileURLs()
  ['http://nohost/plone/foo/files/loremipsum.pdf']
