Commit 0ba94ac4 authored by Jean-Paul Smets's avatar Jean-Paul Smets

This patch fixes the problem of wrong base URL for default pages of web sites...

This patch fixes the problem of wrong base URL for default pages of web sites in the case of web sites which are not virtually hosted. Tests were added.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@25568 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 6236f60e
......@@ -65,7 +65,6 @@ class WebSection(Domain, PermanentURLMixIn):
- WebSection_getDefaultDocumentValue
- WebSection_getSectionValue
- WebSection_getWebSiteValue
It defines the following REQUEST global variables:
......@@ -192,8 +191,15 @@ class WebSection(Domain, PermanentURLMixIn):
# force user to login as specified in Web Section
raise Unauthorized
if document is not None:
self.REQUEST.set('current_web_document', document.__of__(self)) # Used to be document
self.REQUEST.set('current_web_document', document)
self.REQUEST.set('is_web_section_default_document', 1)
document = aq_base(document.asContext(
id=self.getId(), # A quick hack to force URL to point to self
# XXX - A better solution here consists of using PermanentURL
# to find out under which id the document should be published
original_container=document.getParentValue(),
original_id=document.getId(),
editable_absolute_url=document.absolute_url()))
return document.__of__(self)()
return Domain.__call__(self)
......
......@@ -28,6 +28,7 @@
##############################################################################
import os
import re
import unittest
import random
......@@ -273,7 +274,7 @@ class TestERP5Web(ERP5TypeTestCase, ZopeTestCase.Functional):
def test_05_WebPageVersioning(self, quiet=quiet, run=run_all_test):
"""
Simple Case of showing the proper most recent public Web Page based on
(language, version
(language, version)
"""
if not run:
return
......@@ -364,7 +365,7 @@ class TestERP5Web(ERP5TypeTestCase, ZopeTestCase.Functional):
self.logout()
self.assertRaises(Unauthorized, websection._getExtensibleContent, request, document_reference)
def test_07_WebPageTextContentSubstituions(self, quiet=quiet, run=run_all_test):
def test_07_WebPageTextContentSubstitutions(self, quiet=quiet, run=run_all_test):
"""
Simple Case of showing the proper text content with and without a substitution
mapping method.
......@@ -456,8 +457,16 @@ class TestERP5Web(ERP5TypeTestCase, ZopeTestCase.Functional):
self.assertEquals(web_page_en, websection.getDocumentValueList()[0].getObject())
def test_09_DefaultDocumentForWebSection(self, quiet=quiet, run=run_all_test):
""" Testetting default document for a Web Section. Test use case like workflow state of document.
Note: due to generic ERP5 Web implementation this test highly depends on WebSection_geDefaulttDocumentValueList
"""
Testing the default document for a Web Section.
If a Web Section has a default document defined and if that default
document is published, then getDefaultDocumentValue on that
web section should return the latest version in the most
appropriate language of that default document.
Note: due to generic ERP5 Web implementation this test highly depends
on WebSection_geDefaulttDocumentValueList
"""
if not run: return
if not quiet:
......@@ -470,19 +479,70 @@ class TestERP5Web(ERP5TypeTestCase, ZopeTestCase.Functional):
# create pages belonging to this publication_section 'documentation'
web_page_en = portal.web_page_module.newContent(portal_type = 'Web Page',
id='section_home',
language = 'en',
reference='NXD-DDP',
publication_section_list=publication_section_category_id_list[:1])
websection.setAggregateValue(web_page_en)
get_transaction().commit()
self.tic()
self.assertEqual(None, websection.getDefaultDocumentValue())
self.assertEqual(None, websection.getDefaultDocumentValue())
# publish it
web_page_en.publish()
get_transaction().commit()
self.tic()
self.assertEqual(web_page_en, websection.getDefaultDocumentValue())
self.assertEqual(web_page_en, websection.getDefaultDocumentValue())
# and make sure that the base meta tag which is generated
# uses the web section rather than the portal
html_page = websection()
from Products.ERP5.Document.Document import Document
base_list = re.findall(Document.base_parser, str(html_page))
base_url = base_list[0]
self.assertEqual(base_url, "%s/%s/" % (websection.absolute_url(), websection.getId()))
def test_09b_DefaultDocumentForWebSite(self, quiet=quiet, run=run_all_test):
"""
Testing the default document for a Web Site.
If a Web Section has a default document defined and if that default
document is published, then getDefaultDocumentValue on that
web section should return the latest version in the most
appropriate language of that default document.
Note: due to generic ERP5 Web implementation this test highly depends
on WebSection_geDefaulttDocumentValueList
"""
if not run: return
if not quiet:
message = '\ntest_09b_DefaultDocumentForWebSite'
ZopeTestCase._print(message)
portal = self.getPortal()
website = self.setupWebSite()
publication_section_category_id_list = ['documentation', 'administration']
# create pages belonging to this publication_section 'documentation'
web_page_en = portal.web_page_module.newContent(portal_type = 'Web Page',
id='site_home',
language = 'en',
reference='NXD-DDP-Site',
publication_section_list=publication_section_category_id_list[:1])
website.setAggregateValue(web_page_en)
get_transaction().commit()
self.tic()
self.assertEqual(None, website.getDefaultDocumentValue())
# publish it
web_page_en.publish()
get_transaction().commit()
self.tic()
self.assertEqual(web_page_en, website.getDefaultDocumentValue())
# and make sure that the base meta tag which is generated
# uses the web site rather than the portal
html_page = website()
from Products.ERP5.Document.Document import Document
base_list = re.findall(Document.base_parser, str(html_page))
base_url = base_list[0]
self.assertEqual(base_url, "%s/%s/" % (website.absolute_url(), website.getId()))
def test_10_WebSectionAuthorizationForcedForDefaultDocument(self, quiet=quiet, run=run_all_test):
""" Check that when a Web Section contains a default document not accessible by user we have a chance to
require user to login.
......@@ -1150,7 +1210,7 @@ class TestERP5WebWithSimpleSecurity(ERP5TypeTestCase):
self.portal.Localizer.changeLanguage('jp')
self.assertEquals(0, len(section.WebSection_getDocumentValueList()))
# First Japonese Object
# First Japanese Object
self.changeUser('erp5user')
page_jp_0.publish()
get_transaction().commit()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment