document_rst_validation_test.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. /**
  3. * ezcDocumentRstParserTests
  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 ezcDocumentRstValidationTests extends ezcTestCase
  34. {
  35. public static function suite()
  36. {
  37. return new PHPUnit_Framework_TestSuite( __CLASS__ );
  38. }
  39. public function testSuccessfulDocumentStringValidation()
  40. {
  41. $xhtml = new ezcDocumentRst();
  42. $this->assertSame(
  43. true,
  44. $xhtml->validateString( file_get_contents( dirname( __FILE__ ) . '/files/rst/validation/valid.txt' ) ),
  45. 'Expected true as result of document validation'
  46. );
  47. }
  48. public function testSuccessfulDocumentFileValidation()
  49. {
  50. $xhtml = new ezcDocumentRst();
  51. $this->assertSame(
  52. true,
  53. $xhtml->validateFile( dirname( __FILE__ ) . '/files/rst/validation/valid.txt' ),
  54. 'Expected true as result of document validation'
  55. );
  56. }
  57. public function testDocumentFatalParseError()
  58. {
  59. $xhtml = new ezcDocumentRst();
  60. $errors = $xhtml->validateFile( dirname( __FILE__ ) . '/files/rst/validation/parser_fatal.txt' );
  61. $this->assertTrue(
  62. is_array( $errors ),
  63. 'Expected an array of errors to be returned'
  64. );
  65. $this->assertTrue(
  66. $errors[0] instanceof ezcDocumentValidationError,
  67. 'Expected an array of ezcDocumentValidationError objects to be returned'
  68. );
  69. $this->assertSame(
  70. 1,
  71. count( $errors ),
  72. 'Expected three errors to be found in validated document.'
  73. );
  74. $this->assertTrue(
  75. $errors[0]->getOriginalError() instanceof ezcDocumentParserException,
  76. 'Expected an array of ezcDocumentParserException objects to be returned'
  77. );
  78. $this->assertSame(
  79. 'Parse error: Fatal error: \'Unexpected indentation change from level 4 to 0.\' in line 4 at position 38.',
  80. (string) $errors[0]
  81. );
  82. }
  83. public function testDocumentParseNotices()
  84. {
  85. $xhtml = new ezcDocumentRst();
  86. $errors = $xhtml->validateFile( dirname( __FILE__ ) . '/files/rst/validation/parser_notice.txt' );
  87. $this->assertTrue(
  88. is_array( $errors ),
  89. 'Expected an array of errors to be returned'
  90. );
  91. $this->assertSame(
  92. 2,
  93. count( $errors ),
  94. 'Expected three errors to be found in validated document.'
  95. );
  96. }
  97. public function testDocumentVisitorNotices()
  98. {
  99. $xhtml = new ezcDocumentRst();
  100. $errors = $xhtml->validateFile( dirname( __FILE__ ) . '/files/rst/validation/visitor_warning.txt' );
  101. $this->assertTrue(
  102. $errors[0] instanceof ezcDocumentValidationError,
  103. 'Expected an array of ezcDocumentValidationError objects to be returned'
  104. );
  105. $this->assertSame(
  106. 1,
  107. count( $errors ),
  108. 'Expected three errors to be found in validated document.'
  109. );
  110. $this->assertTrue(
  111. $errors[0]->getOriginalError() instanceof ezcDocumentVisitException,
  112. 'Expected an array of ezcDocumentVisitException objects to be returned'
  113. );
  114. $this->assertSame(
  115. 'Visitor error: Warning: \'Too few anonymous reference targets.\' in line 0 at position 0.',
  116. (string) $errors[0]
  117. );
  118. }
  119. }
  120. ?>