From edefaeb2612341e1f8da7f4af735b5c640d4455b Mon Sep 17 00:00:00 2001
From: Nicolas Delaby <nicolas@nexedi.com>
Date: Thu, 21 Jan 2010 14:43:36 +0000
Subject: [PATCH] Check that Last-Modified set by caching policy manager is
 correctly filled with getModificationDate of content. reviewed by Romain

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

diff --git a/product/ERP5/tests/testERP5Web.py b/product/ERP5/tests/testERP5Web.py
index 3ca589fdf7..b9f9375860 100644
--- a/product/ERP5/tests/testERP5Web.py
+++ b/product/ERP5/tests/testERP5Web.py
@@ -1179,6 +1179,65 @@ Hé Hé Hé!""", page.asText().strip())
     self.assertTrue('manage_main' not in response.getBody())
     self.assertTrue('manage_messages' not in response.getBody())
 
+  def test_15_Check_LastModified_Header(self):
+    """This allow check that Last-Modified set by caching policy manager
+    is correctly filled with getModificationDate of content.
+    This test check all Policy installed by erp5_web:
+    Policy ID - unauthenticated web pages
+                unauthenticated
+                authenticated
+    """
+    request = self.portal.REQUEST
+    website = self.setupWebSite()
+    web_section_portal_type = 'Web Section'
+    web_section = website.newContent(portal_type=web_section_portal_type)
+
+    content = '<p>initial text</p>'
+    document = self.portal.web_page_module.newContent(portal_type='Web Page',
+            id='document_cache',
+            reference='NXD-Document.Cache',
+            text_content=content)
+    document.publish()
+    transaction.commit()
+    self.tic()
+    path = website.absolute_url_path() + '/NXD-Document.Cache'
+    # test Different Policy installed by erp5_web
+    # unauthenticated web pages
+    response = self.publish(path)
+    last_modified_header = response.getHeader('Last-Modified')
+    self.assertTrue(last_modified_header)
+    from App.Common import rfc1123_date
+    # Convert the Date into string according RFC 1123 Time Format
+    modification_date = rfc1123_date(document.getModificationDate())
+    self.assertEqual(modification_date, last_modified_header)
+
+    # authenticated
+    user = self.createUser('webmaster')
+    self.createUserAssignement(user, {})
+    response = self.publish(path, 'webmaster:webmaster')
+    last_modified_header = response.getHeader('Last-Modified')
+    self.assertTrue(last_modified_header)
+    from App.Common import rfc1123_date
+    # Convert the Date into string according RFC 1123 Time Format
+    modification_date = rfc1123_date(document.getModificationDate())
+    self.assertEqual(modification_date, last_modified_header)
+
+    # unauthenticated
+    document_portal_type = 'Text'
+    document_module = self.portal.getDefaultModule(document_portal_type)
+    document = document_module.newContent(portal_type=document_portal_type,
+                                          reference='NXD-Document-TEXT.Cache')
+    document.publish()
+    transaction.commit()
+    self.tic()
+    path = website.absolute_url_path() + '/NXD-Document-TEXT.Cache'
+    response = self.publish(path)
+    last_modified_header = response.getHeader('Last-Modified')
+    self.assertTrue(last_modified_header)
+    from App.Common import rfc1123_date
+    # Convert the Date into string according RFC 1123 Time Format
+    modification_date = rfc1123_date(document.getModificationDate())
+    self.assertEqual(modification_date, last_modified_header)
 
 class TestERP5WebWithSimpleSecurity(ERP5TypeTestCase):
   """
-- 
2.30.9