## $Id: test_browser.py 11755 2014-07-09 05:43:16Z henrik $
##
## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##
import grok
from zope.event import notify
from zope.component import createObject, getUtility
from waeup.kofa.configuration import SessionConfiguration
from waeup.aaue.testing import FunctionalLayer
from waeup.kofa.applicants.tests.test_browser import (
    ApplicantsFullSetup, container_name_1, session_1)

class CustomApplicantUITest(ApplicantsFullSetup):
    """Perform some browser tests.
    """

    layer = FunctionalLayer

    def test_show_credentials_on_landing_page(self):
        # An applicant can register himself.
        self.applicant.reg_number = u'1234'
        notify(grok.ObjectModifiedEvent(self.applicant))
        self.browser.open('http://localhost/app/applicants/%s/' % container_name_1)
        self.browser.getLink("Register for application").click()
        # Fill the edit form with suitable values
        self.browser.getControl(name="form.firstname").value = 'Klaus'
        self.browser.getControl(name="form.lastname").value = 'Lutz'
        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
        self.browser.getControl("Send login credentials").click()
        self.assertMatches('...Your registration was successful...',
            self.browser.contents)
        self.assertTrue('<td>Password:</td>' in self.browser.contents)
        return

    def test_payment_slip_download_warning(self):
        configuration = SessionConfiguration()
        configuration.academic_session = session_1
        configuration.application_fee = 200.0
        self.app['configuration'].addSessionConfiguration(configuration)
        self.login()
        self.browser.open(self.edit_path)
        self.fill_correct_values()
        self.browser.getControl(name="form.programme_type").value = ['regular']
        self.browser.getControl(name="form.nationality").value = ['NG']
        self.browser.getControl("Save").click()
        self.browser.getControl("Add online payment ticket").click()
        self.assertMatches('...Payment ticket created...',
                           self.browser.contents)
        # Payment tickets can be downloaded without submitting the form.
        self.browser.getLink("Download payment slip").click()
        self.assertEqual(self.browser.headers['Content-Type'],
                 'application/pdf')
        return
