===================================
Manage persistent Cheetah templates
===================================


  >>> from zope.testbrowser.testing import Browser
  >>> browser = Browser()
  >>> browser.addHeader('Authorization','Basic mgr:mgrpw')
  >>> browser.handleErrors = False

  >>> browser.open('http://localhost/@@managesamples.html')
  >>> browser.getLink(text='ice.template').click()
  >>> browser.getControl(name='z3c.sampledata.site.sitename').value = 'site'
  >>> browser.getControl('Generate').click()

  >>> skin = 'http://localhost/++skin++testlayer/site'

All storages::

  >>> browser.open(skin + '/@@manageTemplates.html')

  >>> browser.getLink('mail-templates')
  <Link text='mail-templates' url='http://localhost/++skin++testlayer/site/++etc++site/mail-templates/index.html'>

  >>> browser.getLink('skin-templates')
  <Link text='skin-templates' url='http://localhost/++skin++testlayer/site/++etc++site/skin-templates/index.html'>

  >>> browser.getLink('mail-templates').click()
  >>> browser.url
  'http://localhost/++skin++testlayer/site/++etc++site/mail-templates/index.html'

Mail templates storage::

  >>> browser.getLink('Registration Mail')
  <Link text='Registration Mail' url='http://localhost/++skin++testlayer/site/++etc++site/mail-templates/registration'>

  >>> browser.getLink('Welcome Mail')
  <Link text='Welcome Mail' url='http://localhost/++skin++testlayer/site/++etc++site/mail-templates/welcome'>

Edit template::

  >>> browser.getLink('Welcome Mail').click()
  >>> browser.url
  'http://localhost/++skin++testlayer/site/++etc++site/mail-templates/welcome'

  >>> '<div class="preview-text"' in browser.contents
  False

  >>> browser.getControl(name="form.widgets.body").value
  'Dear $user_name!\r\nWelcome to $site_name!\r\n'

Preview text with wrong variables::

  >>> browser.getControl(name="form.widgets.body").value = '$user_nam!\r\nWelcome to $site_name!\r\n'
  >>> browser.getControl('Preview and Test').click()

  >>> '<div class="preview-text"' in browser.contents
  False

  >>> 'There are some errors in the template' in browser.contents
  True

  >>> browser.getControl(name="form.widgets.body").value
  '$user_nam!\r\nWelcome to $site_name!\r\n'

  >>> browser.getControl('Refresh').click()

  >>> browser.getControl(name="form.widgets.body").value
  'Dear $user_name!\r\nWelcome to $site_name!\r\n'

Try to save text with wrong variables::

  >>> browser.getControl(name="form.widgets.body").value = '$user_nam!\r\nWelcome to $site_name!\r\n'
  >>> browser.getControl('Apply').click()

  >>> '<div class="preview-text"' in browser.contents
  False

  >>> 'There are some errors in the template' in browser.contents
  True

  >>> browser.getControl('Refresh').click()

Preview text with true variables::

  >>> browser.getControl(name="form.widgets.body").value
  'Dear $user_name!\r\nWelcome to $site_name!\r\n'

  >>> browser.getControl(name="form.widgets.body").value = '$user_name!\r\nWelcome to $site_name!\r\n'
  >>> browser.getControl('Preview and Test').click()

  >>> 'There are some errors in the template' in browser.contents
  False

  >>> 'Ok' in browser.contents
  True

  >>> '<div class="preview-text">***!\r\nWelcome to ***!\r\n</div>' in browser.contents
  True

Save text with true variables::

  >>> browser.getControl('Apply').click()
  >>> browser.headers['STATUS']
  '200 Ok'

  >>> browser.open('http://localhost/++skin++testlayer/site/++etc++site/mail-templates/welcome')
  >>> browser.getControl(name="form.widgets.body").value
  '$user_name!\r\nWelcome to $site_name!\r\n'

Reset from source file::

  >>> browser.getControl('Reset from source').click()

  >>> browser.getControl(name="form.widgets.body").value
  'Dear $user_name!\r\nWelcome to $site_name!\r\n'

Then save::

  >>> browser.getControl('Apply').click()
  >>> browser.headers['STATUS']
  '200 Ok'

  >>> browser.open('http://localhost/++skin++testlayer/site/++etc++site/mail-templates/welcome')
  >>> browser.getControl(name="form.widgets.body").value
  'Dear $user_name!\r\nWelcome to $site_name!\r\n'
