archetypes.referencebrowserwidget
=================================

Some integration tests of the archetypes.referencebrowserwidget. Basically we
create a demo-type which has some of our widgets and look, if they are
available in the default views.

  >>> self.setRoles(['Manager'])
  >>> self.portal.portal_types.invokeFactory('RefBrowserDemo', 'demo1')
  'demo1'
  
  >>> demo1_url = self.portal.demo1.absolute_url(1)
  >>> popup_url = '%s/refbrowser_popup' % demo1_url

Let's see if the Widget Base is here.
    
  >>> response = self.publish('%s/base_edit' % demo1_url, self.basic_auth)
  >>> print response.getBody() #  doctest: +ELLIPSIS
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ...
        <script type="text/javascript" charset="iso-8859-1"
                src="http://nohost/plone/referencebrowser.js">
        </script>...
        <div class="field ArchetypesReferenceBrowserWidget  kssattr-atfieldname-singleRef"
             id="archetypes-fieldname-singleRef">
          <span></span>
            <label ...for="singleRef">SingleRef</label>...
	  <input id="singleRef_label" size="50" type="text"
		 readonly="readonly"
		 value="No reference set. Click the add button to select." />
	  <input type="hidden" name="singleRef" id="singleRef" />...
	<div style="clear: both">
	  <input type="button" class="searchButton"
		 value="Add..."
		 onclick="javascript:refbrowser_openBrowser('http://nohost/plone/demo1','singleRef', '/plone/demo1', 'singleRef', 500, 550)" />
	  <input type="button" class="destructive"
		 value="Remove reference"
		 onclick="javascript:refbrowser_removeReference('singleRef', 0)" />
	</div>...

Now check the popup.
  
  >>> resp = self.publish(
  ...     '%s?fieldName=singleRef&fieldRealName=singleRef&at_url=%s'
  ...     % (popup_url, demo1_url), self.basic_auth)
  
  >>> body = resp.getBody()
  >>> print body
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ...
    <head>
      <title>demo1</title>
      <meta http-equiv="Content-Type"
            content="text/html;charset=utf-8" />...
            
      <body class="popup atrefbrowser"
            onload="focus();self.name='referencebrowser_popup'"...

          <h2 class="documentFirstHeading">SingleRef</h2>...
          
              <input type="hidden" name="fieldName"
                     value="singleRef" />
              <input type="hidden" name="fieldRealName"
                     value="singleRef" />
              <input type="hidden" name="at_url"
                     value="plone/demo1" />
                   
           ...
           
  >>> import re
  >>> INSERTLINK = re.compile(
  ...     r"onclick=\"window.opener.refbrowser_setReference[(]'singleRef'")
  
  >>> ROWS = re.compile(r'<tr.*?>(.*?)</tr>', re.MULTILINE|re.DOTALL)
  >>> len(ROWS.findall(body))
  5
  
  >>> len(INSERTLINK.findall(body))
  1
  
  Now add a news item. We see it, but we shouldn't be able to add it.
  
  >>> self.portal.portal_types.invokeFactory('News Item', 'newsitem')
  'newsitem'
  
  >>> resp = self.publish(
  ...     '%s?fieldName=singleRef&fieldRealName=singleRef&at_url=%s'
  ...     % (popup_url, demo1_url), self.basic_auth)
  >>> body = resp.getBody()
  
  >>> len(ROWS.findall(body))
  6
  
  >>> len(INSERTLINK.findall(body))
  1
  
You can specify the size, of the popup-window with the properties 
`popup_width` and `popup_height` on the widget. The default values are
500 for `popup_width` and 550 for `popup_height`.

  >>> response = self.publish('%s/base_edit' % demo1_url, self.basic_auth)
  >>> f = open('/tmp/result.html', 'w')
  >>> f.write(response.getBody())
  >>> f.close()
  >>> print response.getBody() #  doctest: +ELLIPSIS
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ...
 
                 onclick="javascript:refbrowser_openBrowser('http://nohost/plone/demo1','singleRef', '/plone/demo1', 'singleRef', 500, 550)" />...

+                onclick="javascript:refbrowser_openBrowser('http://nohost/plone/demo1','multiRef5', '/plone/demo1', 'multiRef5', 173, 209)" />...
