style_extractor_test.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 ezcDocumentOdtStyleExtractorTest extends ezcTestCase
  34. {
  35. protected $domDocument;
  36. public static function suite()
  37. {
  38. return new PHPUnit_Framework_TestSuite( __CLASS__ );
  39. }
  40. protected function setUp()
  41. {
  42. $this->domDocument = new DOMDocument();
  43. $this->domDocument->load( dirname( __FILE__ ) . '/../files/odt/tests/s_000_simple.fodt' );
  44. }
  45. public function testCtor()
  46. {
  47. $extr = $this->getExtractorFixture();
  48. $this->assertAttributeSame(
  49. $this->domDocument,
  50. 'odt',
  51. $extr
  52. );
  53. $this->assertInstanceOf(
  54. 'DOMXpath',
  55. $this->readAttribute( $extr, 'xpath' )
  56. );
  57. }
  58. public function testExtractStyleSuccess()
  59. {
  60. $extr = $this->getExtractorFixture();
  61. $style = $extr->extractStyle( 'paragraph', 'Text_20_body' );
  62. $this->assertInstanceOf(
  63. 'DOMElement',
  64. $style
  65. );
  66. $this->assertEquals(
  67. 'style',
  68. $style->localName
  69. );
  70. $this->assertEquals(
  71. 'Text_20_body',
  72. $style->getAttributeNS(
  73. ezcDocumentOdt::NS_ODT_STYLE,
  74. 'name'
  75. )
  76. );
  77. }
  78. public function testExtractDefaultStyleSuccess()
  79. {
  80. $extr = $this->getExtractorFixture();
  81. $style = $extr->extractStyle( 'paragraph' );
  82. $this->assertInstanceOf(
  83. 'DOMElement',
  84. $style
  85. );
  86. $this->assertEquals(
  87. 'default-style',
  88. $style->localName
  89. );
  90. $this->assertFalse(
  91. $style->hasAttributeNs(
  92. ezcDocumentOdt::NS_ODT_STYLE,
  93. 'name'
  94. )
  95. );
  96. $this->assertEquals(
  97. 'paragraph',
  98. $style->getAttributeNs(
  99. ezcDocumentOdt::NS_ODT_STYLE,
  100. 'family'
  101. )
  102. );
  103. }
  104. public function testExtractStyleFailure()
  105. {
  106. $extr = $this->getExtractorFixture();
  107. try
  108. {
  109. $extr->extractStyle( 'paragraph', 'foobar' );
  110. $this->fail( 'Exception not thrown on extraction of non-existent style.' );
  111. }
  112. catch ( RuntimeException $e ) {}
  113. }
  114. public function testExtractDefaultStyleFailure()
  115. {
  116. $extr = $this->getExtractorFixture();
  117. try
  118. {
  119. $extr->extractStyle( 'foobar' );
  120. $this->fail( 'Exception not thrown on extraction of non-existent default style.' );
  121. }
  122. catch ( RuntimeException $e ) {}
  123. }
  124. public function testExtractListStyleSuccess()
  125. {
  126. $extr = $this->getExtractorFixture();
  127. $style = $extr->extractListStyle( 'L2' );
  128. $this->assertEquals(
  129. 'list-style',
  130. $style->localName
  131. );
  132. $this->assertEquals(
  133. 'L2',
  134. $style->getAttributeNS(
  135. ezcDocumentOdt::NS_ODT_STYLE,
  136. 'name'
  137. )
  138. );
  139. }
  140. public function testExtractListStyleFailure()
  141. {
  142. $extr = $this->getExtractorFixture();
  143. try
  144. {
  145. $extr->extractListStyle( 'foobar' );
  146. $this->fail( 'Exception not thrown on extraction of non-existent list style.' );
  147. }
  148. catch ( RuntimeException $e ) {}
  149. }
  150. protected function getExtractorFixture()
  151. {
  152. return new ezcDocumentOdtStyleExtractor( $this->domDocument );
  153. }
  154. }
  155. ?>