document_xml_base_test.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. /**
  3. * ezcDocTestConvertDocbookDocbook
  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 ezcDocumentXmlBaseTests extends ezcTestCase
  34. {
  35. public static function suite()
  36. {
  37. return new PHPUnit_Framework_TestSuite( __CLASS__ );
  38. }
  39. public function testLoadXmlDocumentFromFile()
  40. {
  41. $doc = new ezcDocumentDocbook();
  42. $doc->loadFile(
  43. dirname( __FILE__ ) . '/files/xhtml_sample_basic.xml'
  44. );
  45. $this->assertTrue(
  46. $doc->getDomDocument() instanceof DOMDocument,
  47. 'DOMDocument not created properly'
  48. );
  49. }
  50. public function testLoadXmlDocumentFromString()
  51. {
  52. $string = file_get_contents(
  53. dirname( __FILE__ ) . '/files/xhtml_sample_basic.xml'
  54. );
  55. $doc = new ezcDocumentDocbook();
  56. $doc->loadString( $string );
  57. $this->assertTrue(
  58. $doc->getDomDocument() instanceof DOMDocument,
  59. 'DOMDocument not created properly'
  60. );
  61. }
  62. public function testLoadErroneousXmlDocument()
  63. {
  64. $doc = new ezcDocumentDocbook();
  65. try
  66. {
  67. $doc->loadFile(
  68. dirname( __FILE__ ) . '/files/xhtml_sample_errnous.xml'
  69. );
  70. }
  71. catch ( ezcDocumentErroneousXmlException $e )
  72. {
  73. $errors = $e->getXmlErrors();
  74. $this->assertSame(
  75. 2,
  76. count( $errors ),
  77. 'Expected 2 XML errors.'
  78. );
  79. }
  80. $this->assertTrue(
  81. $doc->getDomDocument() instanceof DOMDocument,
  82. 'DOMDocument not created properly'
  83. );
  84. }
  85. public function testLoadErroneousXmlDocumentSilent()
  86. {
  87. $doc = new ezcDocumentDocbook();
  88. $doc->options->failOnError = false;
  89. $doc->loadFile(
  90. dirname( __FILE__ ) . '/files/xhtml_sample_errnous.xml'
  91. );
  92. $this->assertTrue(
  93. $doc->getDomDocument() instanceof DOMDocument,
  94. 'DOMDocument not created properly'
  95. );
  96. }
  97. public function testSerializeXml()
  98. {
  99. $doc = new ezcDocumentDocbook();
  100. $doc->loadFile(
  101. dirname( __FILE__ ) . '/files/xhtml_sample_basic.xml'
  102. );
  103. $this->assertEquals(
  104. file_get_contents( dirname( __FILE__ ) . '/files/xhtml_sample_basic.xml' ),
  105. $doc->save()
  106. );
  107. }
  108. public function testSerializeXmlFormat()
  109. {
  110. $doc = new ezcDocumentDocbook();
  111. $doc->options->indentXml = true;
  112. $doc->loadFile(
  113. dirname( __FILE__ ) . '/files/xhtml_sample_basic.xml'
  114. );
  115. $this->assertEquals(
  116. file_get_contents( dirname( __FILE__ ) . '/files/xhtml_sample_basic_indented.xml' ),
  117. $doc->save()
  118. );
  119. }
  120. }
  121. ?>