Index: main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_browser.py
===================================================================
--- main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_browser.py	(revision 13992)
+++ main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_browser.py	(revision 14014)
@@ -24,4 +24,5 @@
 import tempfile
 import grok
+import logging
 from datetime import datetime
 from StringIO import StringIO
@@ -41,4 +42,5 @@
 from waeup.kofa.payments.interfaces import IPayer
 from waeup.kofa.configuration import SessionConfiguration
+from waeup.kofa.refereeentries import RefereeEntry
 from waeup.kofa.applicants.container import ApplicantsContainer
 from waeup.kofa.applicants.applicant import Applicant
@@ -1526,4 +1528,37 @@
     layer = FunctionalLayer
 
+    def setUp(self):
+        super(ApplicantRefereeReportTests, self).setUp()
+        self.setup_logging()
+        return
+
+    def tearDown(self):
+        super(ApplicantRefereeReportTests, self).tearDown()
+        self.teardown_logging()
+        return
+
+    def setup_logging(self):
+        # setup a log-handler that catches all fake mailer output
+        self.stream = StringIO()
+        handler = logging.StreamHandler(self.stream)
+        logger = logging.getLogger('test.smtp')
+        logger.addHandler(handler)
+        logger.setLevel(logging.INFO)
+        return
+
+    def get_fake_smtp_output(self):
+        # get output generated by fake mailer
+        self.stream.flush()
+        self.stream.seek(0)
+        return self.stream.read()
+
+    def teardown_logging(self):
+        # remove the log handler for fake mailer output
+        logger = logging.getLogger('test.smtp')
+        handlers = [x for x in logger.handlers]
+        for handler in handlers:
+            logger.removeHandler(handler)
+        return
+
     def test_refereereport_mandate(self):
         mandate = RefereeReportMandate()
@@ -1604,2 +1639,51 @@
         # Mandate is deleted
         self.assertEqual(len(self.app['mandates'].keys()), 0)
+
+    def test_final_submit_with_referees(self):
+        # Add two referees
+        referee1 = RefereeEntry()
+        referee2 = RefereeEntry()
+        referee1.name = u'Linda Tree'
+        referee1.email = 'linda@forest.de'
+        referee2.name = u'Otis Stone'
+        referee2.email = 'otis@stones.de'
+        self.applicant.referees = [referee1, referee2]
+        self.assertFalse(referee1.email_sent)
+        self.assertFalse(referee2.email_sent)
+        self.login()
+        IWorkflowInfo(self.applicant).fireTransition('pay')
+        self.browser.open(self.edit_path)
+        self.fill_correct_values() # fill other fields with correct values
+        image = open(SAMPLE_IMAGE, 'rb')
+        ctrl = self.browser.getControl(name='form.passport')
+        file_ctrl = ctrl.mech_control
+        file_ctrl.add_file(image, filename='myphoto.jpg')
+        self.browser.getControl("Save").click()
+        self.browser.getControl(name="confirm_passport").value = True
+        self.browser.getControl("Finally Submit").click()
+        self.assertEqual(
+            [u'Sending email from no-reply@waeup.org to linda@forest.de:',
+             u'Message:',
+             u'msg: MIME-Version: 1.0',
+             u'msg: Content-Type: text/plain; charset="us-ascii"',
+             u'msg: Content-Transfer-Encoding: 7bit',
+             u'msg: From: Administrator <no-reply@waeup.org>',
+             u'msg: To: Linda Tree <linda@forest.de>',
+             u'msg: Reply-To: Administrator <contact@waeup.org>',
+             u'msg: Subject: Request for referee report from Sample University',
+             u'msg: ',
+            ], self.get_fake_smtp_output().split('\n')[:10]
+            )
+        self.assertTrue(
+            'Application submitted' in self.browser.contents)
+        logfile = os.path.join(
+            self.app['datacenter'].storage, 'logs', 'applicants.log')
+        logcontent = open(logfile).read()
+        self.assertTrue(
+            '%s - applicants.browser.ApplicantEditFormPage - %s - '
+            'email sent: otis@stones.de' %
+            (self.applicant.applicant_id, self.applicant.applicant_id)
+            in logcontent)
+        self.assertTrue(referee1.email_sent)
+        self.assertTrue(referee2.email_sent)
+        return
