options_test_case.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <?php
  2. /**
  3. * ezcDocTestConvertXhtmlDocbook
  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. abstract class ezcDocumentOptionsTestCase extends ezcTestCase
  34. {
  35. /**
  36. * Return class name of options class to test
  37. *
  38. * @return string
  39. */
  40. abstract protected function getOptionsClassName();
  41. /**
  42. * Return default values for the options
  43. *
  44. * Returned array should be in the format:
  45. *
  46. * <code>
  47. * array(
  48. * array(
  49. * 'optionname',
  50. * $value,
  51. * ),
  52. * ...
  53. * )
  54. * </code>
  55. *
  56. * @return array
  57. */
  58. public static function provideDefaultValues()
  59. {
  60. return array();
  61. }
  62. /**
  63. * Return valid data for options to test
  64. *
  65. * Returned array should be in the format:
  66. *
  67. * <code>
  68. * array(
  69. * array(
  70. * 'optionname',
  71. * array(
  72. * 'value 1', 'value 2', ...
  73. * ),
  74. * ),
  75. * ...
  76. * )
  77. * </code>
  78. *
  79. * @return array
  80. */
  81. public static function provideValidData()
  82. {
  83. return array();
  84. }
  85. /**
  86. * Return invalid data for options to test
  87. *
  88. * Returned array should be in the format:
  89. *
  90. * <code>
  91. * array(
  92. * array(
  93. * 'optionname',
  94. * array(
  95. * 'value 1', 'value 2', ...
  96. * ),
  97. * ),
  98. * ...
  99. * )
  100. * </code>
  101. *
  102. * @return array
  103. */
  104. public static function provideInvalidData()
  105. {
  106. return array();
  107. }
  108. /**
  109. * Test all options provided by the data provider
  110. *
  111. * @dataProvider provideDefaultValues
  112. */
  113. public function testOptionsDefaultValues( $property, $value )
  114. {
  115. $class = $this->getOptionsClassName();
  116. $option = new $class();
  117. if ( is_object( $option->$property ) )
  118. {
  119. $this->assertEquals(
  120. $value,
  121. $option->$property,
  122. "Default value in option class '$class' of property '$property' is wrong."
  123. );
  124. }
  125. else
  126. {
  127. $this->assertSame(
  128. $value,
  129. $option->$property,
  130. "Default value in option class '$class' of property '$property' is not '$value'."
  131. );
  132. }
  133. }
  134. /**
  135. * Test all options provided by the data provider
  136. *
  137. * @dataProvider provideValidData
  138. */
  139. public function testOptionsValidValues( $property, $values )
  140. {
  141. $class = $this->getOptionsClassName();
  142. $option = new $class();
  143. $this->assertSetProperty(
  144. $option,
  145. $property,
  146. $values
  147. );
  148. }
  149. /**
  150. * Test all options provided by the data provider
  151. *
  152. * @dataProvider provideInvalidData
  153. */
  154. public function testOptionsInvalidValues( $property, $values )
  155. {
  156. $class = $this->getOptionsClassName();
  157. $option = new $class();
  158. $this->assertSetPropertyFails(
  159. $option,
  160. $property,
  161. $values
  162. );
  163. }
  164. public function testUnknownValue()
  165. {
  166. $class = $this->getOptionsClassName();
  167. $option = new $class();
  168. try
  169. {
  170. $option->get_an_not_existing_property;
  171. $this->fail( 'Expected ezcBasePropertyNotFoundException.' );
  172. }
  173. catch ( ezcBasePropertyNotFoundException $e )
  174. { /* Expected */ }
  175. try
  176. {
  177. $option->get_an_not_existing_property = true;
  178. $this->fail( 'Expected ezcBasePropertyNotFoundException.' );
  179. }
  180. catch ( ezcBasePropertyNotFoundException $e )
  181. { /* Expected */ }
  182. }
  183. }
  184. ?>