location_id_test.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /**
  3. * ezcDocumentPdfStyleInferenceTests
  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 ezcDocumentPcssLocationIdTests extends ezcTestCase
  34. {
  35. protected $document;
  36. protected $xpath;
  37. public static function suite()
  38. {
  39. return new PHPUnit_Framework_TestSuite( __CLASS__ );
  40. }
  41. public function setUp()
  42. {
  43. $this->document = new DOMDocument();
  44. $this->document->registerNodeClass( 'DOMElement', 'ezcDocumentLocateableDomElement' );
  45. $this->document->load( dirname( __FILE__ ) . '/../files/docbook/pdf/location_ids.xml' );
  46. $this->xpath = new DOMXPath( $this->document );
  47. $this->xpath->registerNamespace( 'doc', 'http://docbook.org/ns/docbook' );
  48. }
  49. public function testRootNodeLocationId()
  50. {
  51. $element = $this->xpath->query( '//doc:article' )->item( 0 );
  52. $this->assertEquals(
  53. '/article',
  54. $element->getLocationId()
  55. );
  56. }
  57. public function testSectionNodeLocationId()
  58. {
  59. $element = $this->xpath->query( '//doc:section' )->item( 0 );
  60. $this->assertEquals(
  61. '/article/section#paragraph_with_inline_markup',
  62. $element->getLocationId()
  63. );
  64. }
  65. public function testLocationIdFromStrangeElementId()
  66. {
  67. $element = $this->xpath->query( '//doc:sectioninfo' )->item( 0 );
  68. $this->assertEquals(
  69. '/article/section#paragraph_with_inline_markup/sectioninfo#some_strange_id_42',
  70. $element->getLocationId()
  71. );
  72. }
  73. public function testNodeLocationIdWithRole()
  74. {
  75. $element = $this->xpath->query( '//doc:emphasis' )->item( 1 );
  76. $this->assertEquals(
  77. '/article/section#paragraph_with_inline_markup/para/emphasis[Role=strong]',
  78. $element->getLocationId()
  79. );
  80. }
  81. public function testNodeLocationIdWithClass()
  82. {
  83. $element = $this->xpath->query( '//doc:para' )->item( 1 );
  84. $this->assertEquals(
  85. '/article/section#paragraph_with_inline_markup/para.note_warning',
  86. $element->getLocationId()
  87. );
  88. }
  89. public function testNodeLocationIdWithRoleNormalization()
  90. {
  91. $element = $this->xpath->query( '//doc:emphasis' )->item( 2 );
  92. $this->assertEquals(
  93. '/article/section#paragraph_with_inline_markup/para.note_warning/emphasis[Role=strong]',
  94. $element->getLocationId()
  95. );
  96. }
  97. }
  98. ?>