<commit_before>====================
Generic editor tests
====================

Editor block tests
==================

This file contains tests for various simple blocks.


UnorderedList
-------------

Open editor:

>>> from zope.testbrowser.testing import Browser
>>> browser = Browser()
>>> browser.addHeader('Authorization', 'Basic user:userpw')
>>> browser.open('http://localhost:8080/++skin++vivi/repository/online'
...              '/2007/01/Somalia/@@checkout')
>>> browser.open('@@contents')
>>> browser.open('editable-body/@@contents')
>>> contents_url = browser.url

Apply default values for the article, so we don't run into validation errors on
checkin:

>>> article = getRootFolder()['workingcopy']['zope.user']['Somalia']
>>> import zeit.cms.browser.form
>>> import zeit.cms.testing
>>> from zeit.content.article.interfaces import IArticle
>>> with zeit.cms.testing.site(getRootFolder()):
...     zeit.cms.browser.form.apply_default_values(article, IArticle)

Add ul and let it render:

>>> article = getRootFolder()['workingcopy']['zope.user']['Somalia']
>>> for p in article.xml.body.division.getchildren():
...     article.xml.body.division.remove(p)
>>> article.xml.body.division.ul = ''
>>> article.xml.body.division.ul.li = ['eins', 'zwei']
>>> article._p_changed = True
>>> import transaction
>>> transaction.commit()
>>> browser.open('@@contents')
>>> print browser.contents
<...
    <div ...class="block type-ul...
    <ul><li...>eins</li><li...>zwei</li></ul>
    ...


OrderedList
-----------

Add ol and let it render:

>>> for p in article.xml.body.division.getchildren():
...     article.xml.body.division.remove(p)
>>> article.xml.body.division.ol = ''
>>> article.xml.body.division.ol.li = ['eins', 'zwei']
>>> article._p_changed = True
>>> transaction.commit()
>>> browser.open('@@contents')
>>> print browser.contents
<...
    <div ...class="block type-ol...
    <ol><li...>eins</li><li...>zwei</li></ol>
    ...

Intertitle
----------

>>> for p in article.xml.body.division.getchildren():
...     article.xml.body.division.remove(p)
>>> article.xml.body.division.intertitle = 'A B C'
>>> article._p_changed = True
>>> transaction.commit()
>>> browser.open('@@contents')
>>> print browser.contents
<...
    <div ...class="block type-intertitle...
    <h3...>A B C</h3>
    ...


Raw XML
-------

>>> for p in article.xml.body.division.getchildren():
...     article.xml.body.division.remove(p)
>>> article.xml.body.division.raw = ''
>>> article.xml.body.division.raw.set(
...     '{http://namespaces.zeit.de/CMS/cp}__name__', 'rxname')
>>> article._p_changed = True
>>> browser.open('@@contents')
>>> print browser.contents
<...
    <div class="rawxml">&lt;raw
    xmlns:py="http://codespeak.net/lxml/objectify/pytype"
    xmlns:ns0="http://namespaces.zeit.de/CMS/cp"
    py:pytype="str"
    ns0:__name__="rxname"&gt;&lt;/raw&gt;
    ...

Edit the xml:

>>> browser.getLink('Edit').click()
>>> print browser.getControl('XML').value,
<raw ... ns0:__name__="rxname"></raw>

The root tag is validated:

>>> browser.getControl('XML').value = '<foo/>'
>>> browser.getControl('Apply').click()
>>> print browser.contents
<...XML source: <span class="error">The root element must be &lt;raw&gt;.</span>...

With valid input the box closes:

>>> browser.getControl('XML').value = """
... <raw xmlns:ns0="http://namespaces.zeit.de/CMS/cp" ns0:__name__="rxname">
... <bla/></raw>"""
>>> browser.getControl('Apply').click()
>>> print browser.contents
<...self.close()...

The changed xml is displayed:

>>> browser.open('@@contents')
>>> print browser.contents
<...
    <div class="rawxml">&lt;raw xmlns:ns0="http://namespaces.zeit.de/CMS/cp" ns0:__name__="rxname"&gt;
  &lt;bla/&gt;
&lt;/raw&gt;
</div>
...


Citation
--------

>>> import lxml.objectify
>>> for p in article.xml.body.division.getchildren():
...     article.xml.body.division.remove(p)
>>> article.xml.body.division.append(lxml.objectify.Element('citation'))
>>> article.xml.body.division.citation.set(
...     '{http://namespaces.zeit.de/CMS/cp}__name__', 'name')<commit_msg>Re #9922: Fix other tests not to abuse StringifiedElements (as discovered in commit:e451d7c47ccb)<commit_after>====================
Generic editor tests
====================

Editor block tests
==================

This file contains tests for various simple blocks.


UnorderedList
-------------

Open editor:

>>> from zope.testbrowser.testing import Browser
>>> browser = Browser()
>>> browser.addHeader('Authorization', 'Basic user:userpw')
>>> browser.open('http://localhost:8080/++skin++vivi/repository/online'
...              '/2007/01/Somalia/@@checkout')
>>> browser.open('@@contents')
>>> browser.open('editable-body/@@contents')
>>> contents_url = browser.url

Apply default values for the article, so we don't run into validation errors on
checkin:

>>> article = getRootFolder()['workingcopy']['zope.user']['Somalia']
>>> import zeit.cms.browser.form
>>> import zeit.cms.testing
>>> from zeit.content.article.interfaces import IArticle
>>> with zeit.cms.testing.site(getRootFolder()):
...     zeit.cms.browser.form.apply_default_values(article, IArticle)

Add ul and let it render:

>>> import lxml.objectify
>>> article = getRootFolder()['workingcopy']['zope.user']['Somalia']
>>> for p in article.xml.body.division.getchildren():
...     article.xml.body.division.remove(p)
>>> article.xml.body.division.append(lxml.objectify.Element('ul'))
>>> article.xml.body.division.ul.li = ['eins', 'zwei']
>>> article._p_changed = True
>>> import transaction
>>> transaction.commit()
>>> browser.open('@@contents')
>>> print browser.contents
<...
    <div ...class="block type-ul...
    <ul><li...>eins</li><li...>zwei</li></ul>
    ...


OrderedList
-----------

Add ol and let it render:

>>> for p in article.xml.body.division.getchildren():
...     article.xml.body.division.remove(p)
>>> article.xml.body.division.append(lxml.objectify.Element('ol'))
>>> article.xml.body.division.ol.li = ['eins', 'zwei']
>>> article._p_changed = True
>>> transaction.commit()
>>> browser.open('@@contents')
>>> print browser.contents
<...
    <div ...class="block type-ol...
    <ol><li...>eins</li><li...>zwei</li></ol>
    ...

Intertitle
----------

>>> for p in article.xml.body.division.getchildren():
...     article.xml.body.division.remove(p)
>>> article.xml.body.division.intertitle = 'A B C'
>>> article._p_changed = True
>>> transaction.commit()
>>> browser.open('@@contents')
>>> print browser.contents
<...
    <div ...class="block type-intertitle...
    <h3...>A B C</h3>
    ...


Raw XML
-------

>>> for p in article.xml.body.division.getchildren():
...     article.xml.body.division.remove(p)
>>> article.xml.body.division.append(lxml.objectify.Element('raw'))
>>> article.xml.body.division.raw.set(
...     '{http://namespaces.zeit.de/CMS/cp}__name__', 'rxname')
>>> article._p_changed = True
>>> browser.open('@@contents')
>>> print browser.contents
<...
    <div class="rawxml">&lt;raw
    xmlns:py="http://codespeak.net/lxml/objectify/pytype"
    xmlns:ns0="http://namespaces.zeit.de/CMS/cp"
    py:pytype="TREE"
    ns0:__name__="rxname"/&gt;
    ...

Edit the xml:

>>> browser.getLink('Edit').click()
>>> print browser.getControl('XML').value,
<raw ... ns0:__name__="rxname"/>

The root tag is validated:

>>> browser.getControl('XML').value = '<foo/>'
>>> browser.getControl('Apply').click()
>>> print browser.contents
<...XML source: <span class="error">The root element must be &lt;raw&gt;.</span>...

With valid input the box closes:

>>> browser.getControl('XML').value = """
... <raw xmlns:ns0="http://namespaces.zeit.de/CMS/cp" ns0:__name__="rxname">
... <bla/></raw>"""
>>> browser.getControl('Apply').click()
>>> print browser.contents
<...self.close()...

The changed xml is displayed:

>>> browser.open('@@contents')
>>> print browser.contents
<...
    <div class="rawxml">&lt;raw xmlns:ns0="http://namespaces.zeit.de/CMS/cp" ns0:__name__="rxname"&gt;
  &lt;bla/&gt;
&lt;/raw&gt;
</div>
...


Citation
--------

>>> for p in article.xml.body.division.getchildren():
...     article.xml.body.division.remove(p)
>>> article.xml.body.division.append(lxml.objectify.Element('citation'))
>>> article.xml.body.division.citation.set(
...     '{http://namespaces.zeit.de/CMS/cp}__name__', 'name')
{'fraction_non_alphanumeric': 0.2378652499396281, 'fraction_numerical': 0.005795701521371649, 'mean_word_length': 3.8924985233313643, 'pattern_counts': {'":': 0, '<': 72, '<?xml version=': 0, '>': 376, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 63}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3130014', 'n_tokens_mistral': 2806, 'n_tokens_neox': 2695, 'n_words': 471}