Index: main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py
===================================================================
--- main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py	(revision 12090)
+++ main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py	(revision 12091)
@@ -107,4 +107,7 @@
         document.title = u'My first document'
         self.customer['documents'].addDocument(document)
+        application = createObject('waeup.SampleApplication')
+        application.title = u'My first application'
+        self.customer['applications'].addApplication(application)
 
         # Set password
@@ -121,4 +124,5 @@
         self.history_path = self.customer_path + '/history'
         self.documents_path = self.customer_path + '/documents'
+        self.applications_path = self.customer_path + '/applications'
 
         self.app['configuration'].carry_over = True
@@ -849,12 +853,10 @@
         self.assertTrue(
             'INFO - zope.mgr - customers.browser.DocumentManageFormPage '
-            '- K1000000 - saved: title'
+            '- K1000000 - saved d102: title'
             in logcontent)
-
         self.assertTrue(
             'INFO - zope.mgr - customers.browser.DocumentAddFormPage '
             '- K1000000 - added: PDF Document %s'
             % document.document_id in logcontent)
-
         self.assertTrue(
             'INFO - zope.mgr - customers.browser.DocumentsManageFormPage '
@@ -1030,5 +1032,5 @@
         self.assertEqual(self.browser.headers['Status'], '200 Ok')
         self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
-        path = os.path.join(samples_dir(), 'overview_slip.pdf')
+        path = os.path.join(samples_dir(), 'documents_overview_slip.pdf')
         open(path, 'wb').write(self.browser.contents)
         print "Sample PDF overview_slip.pdf written to %s" % path
@@ -1041,2 +1043,122 @@
         open(path, 'wb').write(self.browser.contents)
         print "Sample document_slip.pdf written to %s" % path
+
+
+class ApplicationUITests(CustomersFullSetup):
+    # Tests for CustomerSampleApplication relates views and pages
+
+    def test_manage_application(self):
+        # Managers can access the pages of customer applicationsconter
+        # and can perform actions
+        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
+        self.browser.open(self.customer_path)
+        self.assertEqual(self.browser.headers['Status'], '200 Ok')
+        self.assertEqual(self.browser.url, self.customer_path)
+        self.browser.open(self.customer_path)
+        self.browser.getLink("Applications").click()
+        self.browser.getLink("Add application").click()
+        self.browser.getControl(name="apptype").value = ['SampleApplication']
+        self.browser.getControl("Create application").click()
+        self.assertTrue('Sample Application created.' in self.browser.contents)
+        application = self.customer['applications']['a102']
+
+        # Application can be edited
+        self.browser.getLink("a102").click()
+        self.browser.getLink("Manage").click()
+        self.browser.getControl(name="form.title").value = 'My second app'
+        self.browser.getControl("Save").click()
+        self.assertTrue('Form has been saved.' in self.browser.contents)
+        self.browser.getLink("View").click()
+        self.assertEqual(self.browser.url, self.applications_path + '/a102/index')
+
+        # Transitions can be performed
+        self.browser.getLink("Transition").click()
+        self.browser.getControl(name="transition").value = ['submit']
+        self.browser.getControl("Save").click()
+        self.browser.getControl(name="transition").value = ['approve']
+        self.browser.getControl("Save").click()
+        self.assertEqual(application.state, 'approved')
+
+        # Applications can be removed
+        self.browser.getLink("Applications").click()
+        ctrl = self.browser.getControl(name='val_id')
+        ctrl.getControl(value=application.application_id).selected = True
+        self.browser.getControl("Remove selected", index=0).click()
+        self.assertTrue('Successfully removed' in self.browser.contents)
+
+        # All actions are being logged
+        logfile = os.path.join(
+            self.app['datacenter'].storage, 'logs', 'customers.log')
+        logcontent = open(logfile).read()
+        self.assertTrue(
+            'INFO - zope.mgr - customers.browser.ApplicationManageFormPage '
+            '- K1000000 - saved a102: title'
+            in logcontent)
+        self.assertTrue(
+            'INFO - zope.mgr - customers.browser.ApplicationAddFormPage '
+            '- K1000000 - added: Sample Application %s'
+            % application.application_id in logcontent)
+        self.assertTrue(
+            'INFO - zope.mgr - customers.browser.ApplicationsManageFormPage '
+            '- K1000000 - removed: %s'
+            % application.application_id in logcontent)
+
+    def test_edit_sample_application(self):
+        # Customers can manage applications under certain conditions
+        self.browser.open(self.login_path)
+        self.browser.getControl(name="form.login").value = self.customer_id
+        self.browser.getControl(name="form.password").value = 'cpwd'
+        self.browser.getControl("Login").click()
+        self.assertMatches(
+            '...You logged in...', self.browser.contents)
+        self.browser.getLink("Applications").click()
+        self.browser.getLink("Add application").click()
+        self.browser.getControl(name="apptype").value = ['SampleApplication']
+        self.browser.getControl("Create application").click()
+        self.assertTrue('Sample Application created.' in self.browser.contents)
+        application = self.customer['applications']['a102']
+
+        # Application can be edited ...
+        self.browser.getLink("a102").click()
+        self.browser.open(self.applications_path + '/a102/edit')
+        #self.browser.getLink("Edit").click()
+        self.assertTrue('The requested form is locked' in self.browser.contents)
+        # Customer is in wrong state
+        IWorkflowState(self.customer).setState(APPROVED)
+        self.browser.open(self.applications_path + '/a102/edit')
+        self.browser.getControl(name="form.title").value = 'My second app'
+        self.browser.getControl("Save").click()
+        self.assertEqual(application.title, 'My second app')
+        self.assertTrue('Form has been saved.' in self.browser.contents)
+        self.browser.getLink("View").click()
+        self.assertEqual(self.browser.url, self.applications_path + '/a102/index')
+        # Customer can submit the form. The form is also saved.
+        self.browser.getLink("Edit").click()
+        self.browser.getControl(name="form.title").value = 'My third app'
+        self.browser.getControl("Final Submit").click()
+        self.assertEqual(application.title, 'My third app')
+        self.assertEqual(application.state, 'submitted')
+        self.assertTrue('Application State: submitted for approval' in self.browser.contents)
+        # Customer can't edit the application once it has been submitted
+        self.browser.open(self.applications_path + '/a102/edit')
+        self.assertTrue('The requested form is locked' in self.browser.contents)
+
+    def test_view_slips(self):
+        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
+        # Officers can open the application overview
+        self.browser.open(self.customer_path + '/applications')
+        self.browser.getLink("Download applications overview").click()
+        self.assertEqual(self.browser.headers['Status'], '200 Ok')
+        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
+        path = os.path.join(samples_dir(), 'applications_overview_slip.pdf')
+        open(path, 'wb').write(self.browser.contents)
+        print "Sample PDF overview_slip.pdf written to %s" % path
+        # Officers can open application slips
+        self.browser.open(self.customer_path + '/applications/a101')
+        self.browser.getLink("Download application slip").click()
+        self.assertEqual(self.browser.headers['Status'], '200 Ok')
+        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
+        path = os.path.join(samples_dir(), 'application_slip.pdf')
+        open(path, 'wb').write(self.browser.contents)
+        print "Sample application_slip.pdf written to %s" % path
+
