converter_docbook_html_xsl_test.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. /**
  3. * ezcDocumentConverterEzp3TpEzp4Tests
  4. *
  5. * Licensed to the Apache Software Foundation (ASF) under one
  6. * or more contributor license agreements. See the NOTICE file
  7. * distributed with this work for additional information
  8. * regarding copyright ownership. The ASF licenses this file
  9. * to you under the Apache License, Version 2.0 (the
  10. * "License"); you may not use this file except in compliance
  11. * with the License. You may obtain a copy of the License at
  12. *
  13. * http://www.apache.org/licenses/LICENSE-2.0
  14. *
  15. * Unless required by applicable law or agreed to in writing,
  16. * software distributed under the License is distributed on an
  17. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18. * KIND, either express or implied. See the License for the
  19. * specific language governing permissions and limitations
  20. * under the License.
  21. *
  22. * @package Document
  23. * @version //autogen//
  24. * @subpackage Tests
  25. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  26. */
  27. /**
  28. * Test suite for class.
  29. *
  30. * @package Document
  31. * @subpackage Tests
  32. */
  33. class ezcDocumentConverterDocbookToHtmlXsltTests extends ezcTestCase
  34. {
  35. protected static $testDocuments = null;
  36. public static function suite()
  37. {
  38. return new PHPUnit_Framework_TestSuite( __CLASS__ );
  39. }
  40. public static function getTestDocuments()
  41. {
  42. if ( self::$testDocuments === null )
  43. {
  44. // Get a list of all test files from the respektive folder
  45. $testFiles = glob( dirname( __FILE__ ) . '/files/docbook/xhtml_xslt/s_*.xml' );
  46. // Create array with the test file and the expected result file
  47. foreach ( $testFiles as $file )
  48. {
  49. self::$testDocuments[] = array(
  50. $file,
  51. substr( $file, 0, -3 ) . 'html'
  52. );
  53. }
  54. }
  55. return self::$testDocuments;
  56. return array_slice( self::$testDocuments, -1, 1 );
  57. }
  58. public function testExtensionMissingException()
  59. {
  60. if ( ezcBaseFeatures::hasExtensionSupport( 'xsl' ) )
  61. {
  62. $this->markTestSkipped( 'You need XSLT support disabled for this test.' );
  63. }
  64. try
  65. {
  66. $converter = new ezcDocumentDocbookToHtmlXsltConverter();
  67. $this->fail( 'Expected ezcBaseExtensionNotFoundException.' );
  68. }
  69. catch ( ezcBaseExtensionNotFoundException $e )
  70. { /* Expected */ }
  71. }
  72. /**
  73. * @group slow
  74. */
  75. public function testConversionFailure()
  76. {
  77. if ( !ezcBaseFeatures::hasExtensionSupport( 'xsl' ) )
  78. {
  79. $this->markTestSkipped( 'You need XSLT support for this test.' );
  80. }
  81. try
  82. {
  83. $doc = new ezcDocumentDocbook();
  84. $doc->loadFile( dirname( __FILE__ ) . '/files/docbook/xhtml_xslt/s_001_empty.xml' );
  85. $converter = new ezcDocumentDocbookToHtmlXsltConverter();
  86. $converter->options->failOnError = true;
  87. $converter->convert( $doc );
  88. $this->fail( 'Expected ezcDocumentErroneousXmlException.' );
  89. }
  90. catch ( ezcDocumentErroneousXmlException $e )
  91. {
  92. $this->assertTrue(
  93. count( $e->getXmlErrors() ) > 0,
  94. 'Expected some conversion errors / notices.'
  95. );
  96. }
  97. }
  98. /**
  99. * @dataProvider getTestDocuments
  100. * @group slow
  101. */
  102. public function testLoadXmlDocumentFromFile( $from, $to )
  103. {
  104. if ( !ezcBaseFeatures::hasExtensionSupport( 'xsl' ) )
  105. {
  106. $this->markTestSkipped( 'You need XSLT support for this test.' );
  107. }
  108. if ( !is_file( $to ) )
  109. {
  110. $this->markTestSkipped( "Comparision file '$to' not yet defined." );
  111. }
  112. $doc = new ezcDocumentDocbook();
  113. $doc->loadFile( $from );
  114. $converter = new ezcDocumentDocbookToHtmlXsltConverter();
  115. $created = $converter->convert( $doc );
  116. $this->assertTrue(
  117. $created instanceof ezcDocumentXhtml
  118. );
  119. // Replace creator string in generated document, as this may change too
  120. // often for proper testing.
  121. $dom = $created->getDomDocument();
  122. $domContent = $dom->saveXml();
  123. // Just test that some kind of HTML has been created - everything is up
  124. // to the used XSL and may change any time.
  125. $this->assertTrue(
  126. strpos( $domContent, '<html' ) !== false
  127. );
  128. // Remove tempdir, when nothing failed.
  129. $this->removeTempDir();
  130. }
  131. }
  132. ?>