From f24b9247cad80499b888109167ee63c3720e93e7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Fri, 17 Sep 2010 11:07:35 +0000
Subject: [PATCH] Tests html preview of an OOo document with images as
 extensible content.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@38448 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/tests/testERP5WebWithDms.py | 73 ++++++++++++++++++++++++
 1 file changed, 73 insertions(+)

diff --git a/product/ERP5/tests/testERP5WebWithDms.py b/product/ERP5/tests/testERP5WebWithDms.py
index dd7c76ed03..f876f97fc9 100644
--- a/product/ERP5/tests/testERP5WebWithDms.py
+++ b/product/ERP5/tests/testERP5WebWithDms.py
@@ -30,6 +30,9 @@
 import unittest
 import os
 import transaction
+from lxml import etree
+from StringIO import StringIO
+
 from AccessControl import Unauthorized
 from AccessControl.SecurityManagement import newSecurityManager
 from Testing import ZopeTestCase
@@ -561,6 +564,76 @@ class TestERP5WebWithDms(ERP5TypeTestCase, ZopeTestCase.Functional):
     self.assertEquals(response.getHeader('content-type'),
                                          'text/html; charset=utf-8')
 
+  def test_PreviewOOoDocumentWithEmbeddedImage(self):
+    """Tests html preview of an OOo document with images as extensible content.
+    """
+    portal = self.portal
+    request = portal.REQUEST
+    request['PARENTS'] = [self.app]
+    website = self.setupWebSite()
+    web_section_portal_type = 'Web Section'
+    web_section = website.newContent(portal_type=web_section_portal_type)
+
+    document_reference = 'tiolive-ERP5.Freedom.TioLive'
+    upload_file = makeFileUpload('tiolive-ERP5.Freedom.TioLive-001-en.odp')
+    document = self.portal.document_module.newContent(
+                                          portal_type='Presentation',
+                                          reference=document_reference,
+                                          file=upload_file)
+    transaction.commit()
+    self.tic()
+    credential = 'ERP5TypeTestCase:'
+
+    # first, preview the draft in its physical location (in document module)
+    response = self.publish('%s/asEntireHTML' % document.absolute_url_path(),
+                            credential)
+    self.assertEquals(response.getHeader('content-type'), 'text/html')
+    html = response.getBody()
+    self.assertTrue('<img' in html, html)
+    
+    # find the img src
+    parser = etree.HTMLParser()
+    tree = etree.parse(StringIO(html), parser)
+    img_list = tree.findall('//img')
+    self.assertEquals(1, len(img_list))
+    src = img_list[0].get('src')
+
+    # and make another query for this img
+    response = self.publish('%s/%s' % ( document.absolute_url_path(), src),
+                            credential)
+    self.assertEquals(response.getHeader('content-type'), 'image/png')
+    png = response.getBody()
+    self.assertTrue(png.startswith('\x89PNG'))
+
+    # then publish the document and access it anonymously by reference through
+    # the web site
+    document.publish()
+    
+    transaction.commit()
+    self.tic()
+
+    response = self.publish('%s/%s/asEntireHTML' % (
+              website.absolute_url_path(), document_reference))
+    self.assertEquals(response.getHeader('content-type'), 'text/html')
+    html = response.getBody()
+    self.assertTrue('<img' in html, html)
+    
+    # find the img src
+    parser = etree.HTMLParser()
+    tree = etree.parse(StringIO(html), parser)
+    img_list = tree.findall('//img')
+    self.assertEquals(1, len(img_list))
+    src = img_list[0].get('src')
+
+    # and make another query for this img
+    response = self.publish('%s/%s/%s' % (
+           website.absolute_url_path(), document_reference, src))
+    self.assertEquals(response.getHeader('content-type'), 'image/png')
+    png = response.getBody()
+    self.assertTrue(png.startswith('\x89PNG'))
+
+
+
 def test_suite():
   suite = unittest.TestSuite()
   suite.addTest(unittest.makeSuite(TestERP5WebWithDms))
-- 
GitLab