<commit_before><?php
/* This class is part of the XP framework
 *
 * $Id$
 */
 
  uses(
    'xml.DomXSLProcessor',
    'net.xp_framework.unittest.xml.AbstractProcessorTest'
  );

  /**
   * ProcessorTest implementation that tests the DomXSL processor
   *
   * @see      xp://xml.DomXSLProcessor
   * @ext      domxml
   * @purpose  Unit Test
   */
  class DomXslProcessorTest extends AbstractProcessorTest {

    /**
     * Returns the PHP extension needed for this processor test to work
     *
     * @return  string
     */
    public function neededExtension() { 
      return 'dom';
    }
  
    /**
     * Returns the XSL processor instance to be used
     *
     * @return  &xml.IXSLProcessor
     */
    public function processorInstance() {
      return new DomXSLProcessor();
    }

    /**
     * Returns the XSL processor's default output charset
     *
     * @return  string
     */
    public function processorCharset() { 
      return 'utf-8';
    }
    
    public function nonXslMethod() {
      return '@@ILLEGAL@@';
    }
    
    #[@xslmethod]
    public function XslMethod() {
      return '@@SUCCESS@@';
    }
    
    /**
     * Test 
     *
     */
    #[@test]
    public function callXslHook() {
      $this->processor->registerInstance('proc', $this);
      $this->processor->setXMLBuf('<document/>');
      $this->processor->setXslBuf('<?xml version="1.0"?>
        <xsl:stylesheet
         version="1.0"
         xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
         xmlns:php="http://php.net/xsl"
        >
          <xsl:template match="/">
            <xsl:value-of select="php:function(\'XSLCallback::invoke\', \'proc\', \'XslMethod\')"/>
          </xsl:template>
        </xsl:stylesheet>
      ');
      $this->processor->run();
    }
    
    /**
     * Test
     *
     */
    #[@test, @expect('lang.IllegalArgumentException')]
    public function callNonXslHook() {
      $this->processor->registerInstance('proc', $this);
      $this->processor->setXMLBuf('<document/>');
      $this->processor->setXslBuf('<?xml version="1.0"?>
        <xsl:stylesheet
         version="1.0"
         xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
         xmlns:php="http://php.net/xsl"
        >
          <xsl:template match="/">
            <xsl:value-of select="php:function(\'XSLCallback::invoke\', \'proc\', \'nonXslMethod\')"/>
          </xsl:template>
        </xsl:stylesheet>
      ');
      $this->processor->run();
    }
    
    /**
     * Test
     *
     */
    #[@test, @expect('lang.IllegalArgumentException')]
    public function callNonRegisteredInstance() {
      $this->processor->setXMLBuf('<document/>');
      $this->processor->setXslBuf('<?xml version="1.0"?>
        <xsl:stylesheet
         version="1.0"
         xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
         xmlns:php="http://php.net/xsl"
        >
          <xsl:template match="/">
            <xsl:value-of select="php:function(\'XSLCallback::invoke\', \'notregistered\')"/>
          </xsl:template>
        </xsl:stylesheet>
      ');
      $this->processor->run();
    }
    
  }
?><commit_msg>- improve error handling tests<commit_after><?php
/* This class is part of the XP framework
 *
 * $Id$
 */
 
  uses(
    'xml.DomXSLProcessor',
    'net.xp_framework.unittest.xml.AbstractProcessorTest'
  );

  /**
   * ProcessorTest implementation that tests the DomXSL processor
   *
   * @see      xp://xml.DomXSLProcessor
   * @ext      domxml
   * @purpose  Unit Test
   */
  class DomXslProcessorTest extends AbstractProcessorTest {

    /**
     * Returns the PHP extension needed for this processor test to work
     *
     * @return  string
     */
    public function neededExtension() { 
      return 'dom';
    }
  
    /**
     * Returns the XSL processor instance to be used
     *
     * @return  &xml.IXSLProcessor
     */
    public function processorInstance() {
      return new DomXSLProcessor();
    }

    /**
     * Returns the XSL processor's default output charset
     *
     * @return  string
     */
    public function processorCharset() { 
      return 'utf-8';
    }
    
    public function nonXslMethod() {
      return '@@ILLEGAL@@';
    }
    
    #[@xslmethod]
    public function XslMethod() {
      return '@@SUCCESS@@';
    }
    
    /**
     * Test 
     *
     */
    #[@test]
    public function callXslHook() {
      $this->processor->registerInstance('proc', $this);
      $this->processor->setXMLBuf('<document/>');
      $this->processor->setXslBuf('<?xml version="1.0"?>
        <xsl:stylesheet
         version="1.0"
         xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
         xmlns:php="http://php.net/xsl"
        >
          <xsl:template match="/">
            <xsl:value-of select="php:function(\'XSLCallback::invoke\', \'proc\', \'XslMethod\')"/>
          </xsl:template>
        </xsl:stylesheet>
      ');
      $this->processor->run();
    }
    
    /**
     * Test
     *
     */
    #[@test, @expect('lang.IllegalArgumentException')]
    public function callNonXslHook() {
      $this->processor->registerInstance('proc', $this);
      $this->processor->setXMLBuf('<document/>');
      $this->processor->setXslBuf('<?xml version="1.0"?>
        <xsl:stylesheet
         version="1.0"
         xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
         xmlns:php="http://php.net/xsl"
        >
          <xsl:template match="/">
            <xsl:value-of select="php:function(\'XSLCallback::invoke\', \'proc\', \'nonXslMethod\')"/>
          </xsl:template>
        </xsl:stylesheet>
      ');
      $this->processor->run();
    }
    
    /**
     * Test
     *
     */
    #[@test, @expect('lang.IllegalArgumentException')]
    public function callNonRegisteredInstance() {
      $this->processor->setXMLBuf('<document/>');
      $this->processor->setXslBuf('<?xml version="1.0"?>
        <xsl:stylesheet
         version="1.0"
         xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
         xmlns:php="http://php.net/xsl"
        >
          <xsl:template match="/">
            <xsl:value-of select="php:function(\'XSLCallback::invoke\', \'notregistered\')"/>
          </xsl:template>
        </xsl:stylesheet>
      ');
      $this->processor->run();
    }
    
    /**
     * Test error handling
     *
     */
    #[@test, @expect('xml.TransformerException')]
    public function malformedXML() {
      $this->processor->setXMLBuf('@@MALFORMED@@');
    }
    
    /**
     * Test error handling
     *
     */
    #[@test, @expect('xml.TransformerException')]
    public function malformedXSL() {
      $this->processor->setXSLBuf('@@MALFORMED@@');
    }
    
    /**
     * Test that errors in libxml error stack are caught at first
     * possible point - in the constructor. Make process bail out as
     * early as possible to make error trackdown more easy.
     *
     */
    #[@test, @expect('xml.TransformerException')]
    public function preventErrorLeaking() {
    
      // Fill up error stack artificially
      $doc= new DOMDocument();
      $doc->loadXML('@@MALFORMED@@');
      
      // Should give an exception
      $this->processorInstance();
    }
  }
?>
{'fraction_non_alphanumeric': 0.1653663973251602, 'fraction_numerical': 0.00780161604903873, 'mean_word_length': 2.114533622559653, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 6, '>': 97, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 32}, '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': '2278686', 'n_tokens_mistral': 2308, 'n_tokens_neox': 2188, 'n_words': 387}