From 39d5fb1f47c2c3a3586f668af2125c55858e9fa8 Mon Sep 17 00:00:00 2001
From: Rafael Monnerat <rafael@nexedi.com>
Date: Fri, 7 Jan 2011 04:32:57 +0000
Subject: [PATCH] Add test for before script.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@42103 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../ERP5Workflow/tests/testERP5Workflow.py    | 35 +++++++++++++++----
 1 file changed, 29 insertions(+), 6 deletions(-)

diff --git a/product/ERP5Workflow/tests/testERP5Workflow.py b/product/ERP5Workflow/tests/testERP5Workflow.py
index b2b14bda93..e37e1cbeb1 100644
--- a/product/ERP5Workflow/tests/testERP5Workflow.py
+++ b/product/ERP5Workflow/tests/testERP5Workflow.py
@@ -32,12 +32,6 @@ from AccessControl.SecurityManagement import newSecurityManager
 from AccessControl import Unauthorized
 from AccessControl import SpecialUsers
 
-try:
-  from transaction import get as get_transaction
-except ImportError:
-  pass
-
-
 class TestERP5Workflow(ERP5TypeTestCase):
   """
     Tests ERP5 Workflow.
@@ -166,6 +160,35 @@ class TestERP5Workflow(ERP5TypeTestCase):
     # FIXME: not passing parameter to an after script is probably too
     # restrictive
 
+  def test_BeforeScript(self):
+    workflow = self.workflow_module.newContent(
+                                portal_type='Workflow',
+                                state_base_category='current_state')
+    s1 = workflow.newContent(portal_type='State',
+                             title='State 1')
+    s2 = workflow.newContent(portal_type='State',
+                             title='State 2')
+    t1 = workflow.newContent(portal_type='Transition',
+                             title='Transition 1',
+                             before_script_id='Document_testBeforeScript'
+                             )
+    s1.setDestinationValue(t1)
+    t1.setDestinationValue(s2)
+    workflow.setSourceValue(s1)
+
+    doc = self.portal.newContent(portal_type='Folder', id='test_doc')
+
+    called = []
+    def Document_testBeforeScript(**kw):
+      called.append('called %s' % kw)
+    doc.Document_testBeforeScript = Document_testBeforeScript
+
+    workflow.initializeDocument(doc)
+    t1.execute(doc)
+    self.assertEquals(['called {}'], called)
+    # FIXME: not passing parameter to an before script is probably too
+    # restrictive
+
   def test_WorkflowSecurity(self):
     """
      Test workflow security.
-- 
2.30.9