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

<!-- tests prepend command successfully prepends the contents of a div tag with all matched 
span tags in the content --> 
<deliverance-test>
  <rules xmlns="http://www.plone.org/deliverance">
    <prepend theme=".//div[@id='foo']" content=".//span[@class='bar']" />
  </rules>

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

  <content> 
    <html><body><div class="bar">Real Content</div><span class="bar">1</span><span class="quux">2</span><p>zzz</p><span class="bar">3</span></body></html>
  </content>
  
  <output>
    <html><head><title>Blah</title></head><body><div></div>
	<div id="foo"><span class="bar">1</span><span class="bar">3</span>Dummy Content<p>HI!</p></div></body></html>
  </output> 
</deliverance-test>


<!-- tests that an error is raised if prepend command does not find a target element in the theme --> 
<deliverance-test>
  <rules xmlns="http://www.plone.org/deliverance">
    <prepend theme=".//div[@id='foo']" content=".//div[@id='bar']" />
  </rules>

  <theme base="http://example.com"> 
    <html><head><title>Blah</title></head><body></body></html>
  </theme>

  <content> 
    <html><body><div id="bar">Real Content</div></body></html>
  </content>
  
  <output>
    <html>
      <head>
	<title>Blah</title>
      </head>
      <body>
	<div class="deliverance-error">Deliverance error: no element found in theme<br/>
	  rule: &lt;prepend theme=".//div[@id='foo']" content=".//div[@id='bar']"/&gt;
	</div>
      </body>
    </html>
  </output> 
</deliverance-test>


<!-- tests that an error is raised if prepend command finds more than one target element in the theme --> 
<deliverance-test>
  <rules xmlns="http://www.plone.org/deliverance">
    <prepend theme=".//div[@class='foo']" content=".//div[@id='bar']" />
  </rules>

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

  <content> 
    <html><body><div id="bar">Real Content</div></body></html>
  </content>
  
  <output>
<html>
  <head>
    <title>Blah</title>
  </head>
  <body>
    <div class="deliverance-error">Deliverance error: multiple elements found in theme<br/>rule: &lt;prepend theme=".//div[@class='foo']" content=".//div[@id='bar']"/&gt;
  <br/><textarea rows="24" cols="80" readonly="readonly">&lt;div class="foo"&gt;Dummy Content&lt;/div&gt;&lt;div class="foo"&gt;Dummy Content&lt;/div&gt;
</textarea></div>
    <div class="foo">Dummy Content</div>
    <div class="foo">Dummy Content</div>
  </body>
</html>

  </output> 
</deliverance-test>


<!-- tests prepend command successfully prepends the contents of a div tag with all contents of body tag, 
including unelemented text --> 
<deliverance-test>
  <rules xmlns="http://www.plone.org/deliverance">
    <prepend theme=".//div[@id='foo']" content="//body/child::node()" />
  </rules>

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

  <content> 
    <html><body>leading text <br/> more <p>inside p </p>trailing text</body> tail of body</html>
  </content>
  
  <output>
    <html><head><title>Blah</title></head><body><div id="foo">leading text <br/> more <p>inside p </p>trailing textDummy Content<p>HI!</p></div>
    </body></html>
  </output> 
</deliverance-test>


<!-- tests prepend command generates an error when no content is found -->
<deliverance-test>
  <rules xmlns="http://www.plone.org/deliverance">
    <prepend theme=".//div[@id='foo']" content="//div[@id='bar']" />
  </rules>

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

  <content> 
    <html><body>leading text <br/> more <p>inside p </p>trailing text</body> tail of body</html>
  </content>
  
  <output>
<html>
  <head>
    <title>Blah</title>
  </head>
  <body>
    <div class="deliverance-error">Deliverance error: no content matched<br/>rule: &lt;prepend theme=".//div[@id='foo']" content="//div[@id='bar']"/&gt;
  </div>
    <div/>
    <div id="foo">Dummy Content<p>HI!</p></div>
  </body>
</html>
  </output> 
</deliverance-test>


<!-- tests prepend command ignores error when no content is found 
and nocontent='ignore' is set-->
<deliverance-test>
  <rules xmlns="http://www.plone.org/deliverance">
    <prepend theme=".//div[@id='foo']" content="//div[@id='bar']" nocontent='ignore' />
  </rules>

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

  <content> 
    <html><body>leading text <br/> more <p>inside p </p>trailing text</body> tail of body</html>
  </content>
  
  <output>
<html>
  <head>
    <title>Blah</title>
  </head>
  <body>
    <div/>
    <div id="foo">Dummy Content<p>HI!</p></div>
  </body>
</html>
  </output> 
</deliverance-test>

</deliverance-test-suite>
