style_parser_test.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. /**
  3. * ezcDocumentOdtFormattingPropertiesTest.
  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 ezcDocumentOdtStyleParserTest extends ezcTestCase
  34. {
  35. protected $domDocument;
  36. protected $xpath;
  37. public static function suite()
  38. {
  39. return new PHPUnit_Framework_TestSuite( __CLASS__ );
  40. }
  41. protected function setUp()
  42. {
  43. $this->domDocument = new DOMDocument();
  44. $this->domDocument->load(
  45. dirname( __FILE__ ) . '/../files/odt/tests/s_000_simple.fodt'
  46. );
  47. $this->xpath = new DOMXpath( $this->domDocument );
  48. $this->xpath->registerNamespace( 'style', ezcDocumentOdt::NS_ODT_STYLE );
  49. $this->xpath->registerNamespace( 'text', ezcDocumentOdt::NS_ODT_TEXT );
  50. $this->parser = new ezcDocumentOdtStyleParser();
  51. }
  52. public function testParseStyleSuccess()
  53. {
  54. $name = 'Text_20_body';
  55. $family = 'paragraph';
  56. $dom = $this->xpath->query(
  57. '//style:style[@style:name="' . $name . '" and @style:family="' . $family . '"]'
  58. )->item( 0 );
  59. $style = $this->parser->parseStyle( $dom, $family, $name );
  60. $this->assertInstanceOf(
  61. 'ezcDocumentOdtStyle',
  62. $style
  63. );
  64. $this->assertEquals(
  65. $name,
  66. $style->name
  67. );
  68. $this->assertEquals(
  69. $family,
  70. $style->family
  71. );
  72. $this->assertTrue(
  73. $style->formattingProperties->hasProperties(
  74. ezcDocumentOdtFormattingProperties::PROPERTIES_PARAGRAPH
  75. )
  76. );
  77. $prop = $style->formattingProperties->getProperties(
  78. ezcDocumentOdtFormattingProperties::PROPERTIES_PARAGRAPH
  79. );
  80. $this->assertEquals(
  81. '0in',
  82. $prop['margin-top']
  83. );
  84. }
  85. public function testListStyleNumberSuccess()
  86. {
  87. $name = 'L3';
  88. $dom = $this->xpath->query(
  89. '//text:list-style[@style:name="' . $name . '"]'
  90. )->item( 0 );
  91. $style = $this->parser->parseListStyle( $dom, $name );
  92. $this->assertEquals(
  93. $name,
  94. $style->name
  95. );
  96. $this->assertEquals(
  97. 10,
  98. count( $style->listLevels )
  99. );
  100. $this->assertInstanceOf(
  101. 'ezcDocumentOdtListLevelStyleNumber',
  102. $style->listLevels[1]
  103. );
  104. $this->assertEquals(
  105. 'a',
  106. $style->listLevels[1]->numFormat
  107. );
  108. }
  109. public function testListStyleBulletSuccess()
  110. {
  111. $name = 'L2';
  112. $dom = $this->xpath->query(
  113. '//text:list-style[@style:name="' . $name . '"]'
  114. )->item( 0 );
  115. $style = $this->parser->parseListStyle( $dom, $name );
  116. $this->assertEquals(
  117. $name,
  118. $style->name
  119. );
  120. $this->assertEquals(
  121. 10,
  122. count( $style->listLevels )
  123. );
  124. $this->assertInstanceOf(
  125. 'ezcDocumentOdtListLevelStyleBullet',
  126. $style->listLevels[1]
  127. );
  128. $this->assertEquals(
  129. '•',
  130. $style->listLevels[1]->bulletChar
  131. );
  132. }
  133. }
  134. ?>