document_xhtml_validation_test.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 ezcDocumentXhtmlValidationTests 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 ezcDocumentXhtml();
  42. $this->assertSame(
  43. true,
  44. $xhtml->validateString( file_get_contents( dirname( __FILE__ ) . '/files/xhtml/validation/valid_markup.html' ) ),
  45. 'Expected true as result of document validation'
  46. );
  47. }
  48. public function testSuccessfulDocumentFileValidation()
  49. {
  50. $xhtml = new ezcDocumentXhtml();
  51. $this->assertSame(
  52. true,
  53. $xhtml->validateFile( dirname( __FILE__ ) . '/files/xhtml/validation/valid_markup.html' ),
  54. 'Expected true as result of document validation'
  55. );
  56. }
  57. public function testDocumentStringValidationErrors()
  58. {
  59. $xhtml = new ezcDocumentXhtml();
  60. $errors = $xhtml->validateString( file_get_contents( dirname( __FILE__ ) . '/files/xhtml/validation/invalid_markup.html' ) );
  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. 10,
  71. count( $errors ),
  72. 'Expected three errors to be found in validated document.'
  73. );
  74. $this->assertTrue(
  75. $errors[0]->getOriginalError() instanceof LibXMLError,
  76. 'Expected an array of LibXMLError objects to be returned'
  77. );
  78. $this->assertSame(
  79. 'Fatal error in 38:7: Opening and ending tag mismatch: a line 36 and h1.',
  80. (string) $errors[0]
  81. );
  82. }
  83. }
  84. ?>