Index: main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py
===================================================================
--- main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py	(revision 16186)
+++ main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py	(revision 16187)
@@ -1677,4 +1677,56 @@
         IWorkflowInfo(self.student).fireTransition('clear')
         self.assertEqual(self.student.officer_comment, None)
+        return
+
+    def test_handle_temp_clearance_by_co(self):
+        self.app['configuration']['2004'].clearance_enabled = True
+        self.init_clearance_officer()
+        # Hide real name.
+        self.app['users']['mrclear'].public_name = 'My Public Name'
+        IWorkflowInfo(self.student).fireTransition('request_clearance')
+        #notify(LocalRoleSetEvent(
+        #    self.department, 'waeup.local.ClearanceOfficer', 'mrclear',
+        #    granted=True))
+        # CO can view the student ...
+        self.browser.open(self.clearance_path)
+        self.browser.getLink("Clear student temporarily").click()
+        self.assertEqual(
+            self.browser.url, self.student_path + '/temp_clearance')
+        # Type comment why.
+        self.browser.getControl(name="form.officer_comment").value = (
+            'Dear Student,\n'
+            'Your birth cert is missing.')
+        self.browser.getControl(
+            'Save comment and clear student temporarily now').click()
+        self.assertTrue('Student has been temporarily cleared.'
+            in self.browser.contents)
+        url = ('http://localhost/app/students/K1000000/'
+              'contactstudent?body=Dear+Student%2C%0AYour+birth+cert+is+missing.'
+              '&subject=You+have+been+temporarily+cleared.')
+        # CO does now see the prefilled contact form and can send a message.
+        self.assertEqual(self.browser.url, url)
+        self.assertTrue('clearance requested' in self.browser.contents)
+        self.assertTrue('name="form.subject" size="20" type="text" '
+            'value="You have been temporarily cleared."'
+            in self.browser.contents)
+        self.assertTrue('name="form.body" rows="10" >Dear Student,'
+            in self.browser.contents)
+        self.browser.getControl("Send message now").click()
+        self.assertTrue('Your message has been sent' in self.browser.contents)
+        # The comment has been stored ...
+        self.assertEqual(self.student.officer_comment,
+            'Temporarily cleared by My Public Name. Officers comment:\n'
+            'Dear Student,\nYour birth cert is missing.')
+        # ... and logged.
+        logfile = os.path.join(
+            self.app['datacenter'].storage, 'logs', 'students.log')
+        logcontent = open(logfile).read()
+        self.assertTrue(
+            'INFO - mrclear - students.browser.StudentTempClearancePage - '
+            'K1000000 - comment: Dear Student,<br>Your birth cert is '
+            'missing.\n' in logcontent)
+        # CO can view the student bus no longer see the temp clearance button ...
+        self.browser.open(self.clearance_path)
+        self.assertFalse('Clear student temporarily' in self.browser.contents)
         return
 
