<?xml version="1.0" encoding="UTF-8"?>
<deliverance-test-suite>

<!-- drop a simple div tag in theme --> 
<deliverance-test>
  <rules xmlns="http://www.plone.org/deliverance">
    <drop theme="//div[@id='foo']"/>
  </rules>

  <theme base="http://example.com"> 
     <html><head><title>Blah</title></head><body><div id="foo">Dummy Content</div></body></html>
  </theme>

  <content> 
     <html><body>Real Content</body></html>
  </content>
 
  <output>
     <html><head><title>Blah</title></head><body></body></html>
  </output> 
</deliverance-test>

<!-- drop 2 div tags in theme -->
<deliverance-test>
  <rules xmlns="http://www.plone.org/deliverance">
    <drop theme="//div[@id='foo']"/>
    <drop theme="//div[@id='bar']"/>
  </rules>

  <theme base="http://example.com"> 
     <html><body><div id="foo">foo</div><div id="bar">bar</div><div id="urn">urn</div></body></html>
  </theme>

  <content>
     <html><body>Real Content</body></html>
  </content>

  <output>
     <html><body><div id="urn">urn</div></body></html>
  </output>
</deliverance-test>

<!-- drop element from content -->
<deliverance-test>
  <rules xmlns="http://www.plone.org/deliverance">
    <drop content="//div[@id='foo']"/>
    <copy theme=".//body" content="//body/child::node()"/>
  </rules>

  <theme base="http://example.com"> 
     <html><body><div id="urn"></div></body></html>
  </theme>

  <content>
     <html>
       <body>
        <div id="foo">shouldn't appear</div>
        <div id="bar">should appear</div>
       </body>
     </html>
  </content>

  <output>
     <html><body><div id="bar">should appear</div></body></html>
  </output>
</deliverance-test>

<!-- drop element from both theme and content -->
<deliverance-test>
  <rules xmlns="http://www.plone.org/deliverance">
    <drop content="//div[@id='foo']"/>
    <drop theme="//div[@id='bar']"/>
    <copy theme=".//body" content="//body/child::node()"/>
  </rules>

  <theme base="http://example.com"> 
     <html>
       <body>
        <div id="bar">disappear</div>
       </body>
     </html>
  </theme>

  <content>
     <html>
       <body>
        <div id="foo">disappear</div>
        <div id="urn">appear</div>
       </body>
     </html>
  </content>

  <output>
     <html><body><div id="urn">appear</div></body></html>
  </output>
</deliverance-test>

<!-- dropping a tag drops itself and all its children -->
<deliverance-test>
  <rules xmlns="http://www.plone.org/deliverance">
    <drop theme="//div[@id='foo']"/>
  </rules>

  <theme base="http://example.com"> 
     <html>
       <body>
        <div id="foo"><p>none</p><p>of these<b>should appear</b></p></div>
       </body>
     </html>
  </theme>

  <content>
     <html><body>Real Content</body></html>
  </content>

  <output>
     <html><body></body></html>
  </output>
</deliverance-test>

<!-- dropping missing tag generates an error  -->
<deliverance-test>
  <rules xmlns="http://www.plone.org/deliverance">
    <drop theme="//div[@id='foo']"/>
  </rules>

  <theme base="http://example.com"> 
     <html><body>Dummy Content</body></html>
  </theme>

  <content>
     <html><body>Real Content</body></html>
  </content>

  <output>
     <html>
       <body>
         Dummy Content
         <div class="deliverance-error">Deliverance error: no theme matched<br/>rule: &lt;drop theme="//div[@id='foo']"/&gt;
         </div>
       </body>
     </html>
  </output>
</deliverance-test>

<!-- dropping missing tag in the content generates an error  -->
<deliverance-test>
  <rules xmlns="http://www.plone.org/deliverance">
    <drop content="//div[@id='foo']"/>
  </rules>

  <theme base="http://example.com"> 
     <html><body>Dummy Content</body></html>
  </theme>

  <content>
     <html><body>Real Content</body></html>
  </content>

  <output>
     <html>
       <body>
         Dummy Content
         <div class="deliverance-error">Deliverance error: no content matched<br/>rule: &lt;drop content="//div[@id='foo']"/&gt;
         </div>
       </body>
     </html>
  </output>
</deliverance-test>


<!-- dropping a tag that doesn't exist and ignoring errors
     should squash error messages -->
<deliverance-test>
  <rules xmlns="http://www.plone.org/deliverance">
    <drop theme="//div[@id='foo']" notheme='ignore'/>
  </rules>

  <theme base="http://example.com"> 
     <html><body>Dummy Content</body></html>
  </theme>

  <content>
     <html><body>Real Content</body></html>
  </content>

  <output>
     <html><body>Dummy Content</body></html>
  </output>
</deliverance-test>

<!-- drop a div tag but maintain the tails  --> 
<deliverance-test>
  <rules xmlns="http://www.plone.org/deliverance">
    <drop theme="//div[@id='foo']"/>
  </rules>

  <theme base="http://example.com"> 
     <html><head><title>Blah</title></head><body>before<div id="foo">Dummy Content</div>after</body></html>
  </theme>

  <content> 
     <html><body>Real Content</body></html>
  </content>
 
  <output>
     <html><head><title>Blah</title></head><body>beforeafter</body></html>
  </output> 
</deliverance-test>

</deliverance-test-suite>

