From 2387b8db1117eabf6590aaf86bcf670b09ed54bc Mon Sep 17 00:00:00 2001
From: Nicolas Delaby <nicolas@nexedi.com>
Date: Fri, 4 Dec 2009 10:42:02 +0000
Subject: [PATCH] test CheckBox replacement

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@31073 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5OOo/tests/testFormPrintout.py | 29 ++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/product/ERP5OOo/tests/testFormPrintout.py b/product/ERP5OOo/tests/testFormPrintout.py
index d2e9f21749..69fd62f938 100644
--- a/product/ERP5OOo/tests/testFormPrintout.py
+++ b/product/ERP5OOo/tests/testFormPrintout.py
@@ -67,11 +67,15 @@ class TestFormPrintout(ERP5TypeTestCase):
                                   'Foo_003.odt') 
     foo4_file_path = os.path.join(os.path.dirname(__file__),
                                   'test_document',
-                                  'Foo_004.odt') 
+                                  'Foo_004.odt')
+    foo5_file_path = os.path.join(os.path.dirname(__file__),
+                                  'test_document',
+                                  'Foo_005.odt')
     foo_file = open(foo_file_path, 'rb')
     foo2_file = open(foo2_file_path, 'rb')
     foo3_file = open(foo3_file_path, 'rb')
     foo4_file = open(foo4_file_path, 'rb')
+    foo5_file = open(foo5_file_path, 'rb')
     custom = self.portal.portal_skins.custom
     addStyleSheet = custom.manage_addProduct['OFSP'].manage_addFile
     if custom._getOb('Foo_getODTStyleSheet', None) is None:
@@ -86,6 +90,9 @@ class TestFormPrintout(ERP5TypeTestCase):
     if custom._getOb('Foo4_getODTStyleSheet', None) is None:
       addStyleSheet(id='Foo4_getODTStyleSheet', file=foo4_file, title='',
                     precondition='', content_type = 'application/vnd.oasis.opendocument.text')
+    if custom._getOb('Foo5_getODTStyleSheet', None) is None:
+      addStyleSheet(id='Foo5_getODTStyleSheet', file=foo5_file, title='',
+                    precondition='', content_type = 'application/vnd.oasis.opendocument.text')
     erp5OOo = custom.manage_addProduct['ERP5OOo']
     addOOoTemplate = erp5OOo.addOOoTemplate
     if custom._getOb('Foo_viewAsOdt', None) is None:
@@ -105,6 +112,9 @@ class TestFormPrintout(ERP5TypeTestCase):
     if custom._getOb('FooReport_viewAsPrintout', None) is None:
       erp5OOo.addFormPrintout(id='FooReport_viewAsPrintout',
                               title='')
+    if custom._getOb('Foo5_viewAsPrintout', None) is None:
+      erp5OOo.addFormPrintout(id='Foo5_viewAsPrintout', title='',
+                              form_name='Foo_view', template='Foo5_getODTStyleSheet')
 
     ## append 'test1' data to a listbox
     foo_module = self.portal.foo_module
@@ -1184,6 +1194,23 @@ return []
     #test_output.write(printout.data)
     self.assertEqual('application/msword', guessMime(printout.data))
 
+  def test_09_FieldReplacement(self, run=run_all_test):
+    """test field in ODF Documents"""
+    foo_printout = self.portal.foo_module.test1.Foo5_viewAsPrintout
+    foo_form = self.portal.foo_module.test1.Foo_view
+    field_name = 'your_checkbox'
+    if foo_form._getOb(field_name, None) is None:
+      foo_form.manage_addField(field_name, 'CheckBox', 'CheckBoxField')
+    checkbox = getattr(foo_form, field_name)
+    checkbox.values['default'] = 1
+
+    odf_document = foo_printout()
+    builder = OOoBuilder(odf_document)
+    content_xml = builder.extract("content.xml")
+    document_tree = etree.XML(content_xml)
+    node = document_tree.xpath('//form:checkbox[@form:name = "%s"]' % field_name, namespaces=document_tree.nsmap)[0]
+    self.assertTrue(node.get('{%s}current-state' % document_tree.nsmap['form']))
+
 
 def test_suite():
   suite = unittest.TestSuite()
-- 
2.30.9