/Feed/tests/regression_test.php

https://github.com/F5/zetacomponents · PHP · 196 lines · 163 code · 4 blank · 29 comment · 23 complexity · 0f37d45b3e772b8b9868b905e4cae3ef MD5 · raw file

  1. <?php
  2. /**
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one
  5. * or more contributor license agreements. See the NOTICE file
  6. * distributed with this work for additional information
  7. * regarding copyright ownership. The ASF licenses this file
  8. * to you under the Apache License, Version 2.0 (the
  9. * "License"); you may not use this file except in compliance
  10. * with the License. You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing,
  15. * software distributed under the License is distributed on an
  16. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17. * KIND, either express or implied. See the License for the
  18. * specific language governing permissions and limitations
  19. * under the License.
  20. *
  21. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  22. * @version //autogentag//
  23. * @filesource
  24. * @package Feed
  25. * @subpackage Tests
  26. */
  27. /**
  28. * @package Feed
  29. * @subpackage Tests
  30. */
  31. class ezcFeedRegressionTest extends ezcTestRegressionTest
  32. {
  33. protected function createFeed( $type, $data )
  34. {
  35. $feed = new ezcFeed( $type );
  36. $supportedModules = ezcFeed::getSupportedModules();
  37. if ( is_array( $data ) )
  38. {
  39. foreach ( $data as $property => $value )
  40. {
  41. if ( is_array( $value ) )
  42. {
  43. foreach ( $value as $val )
  44. {
  45. if ( isset( $supportedModules[$property] ) )
  46. {
  47. $element = $feed->addModule( $property );
  48. }
  49. else
  50. {
  51. $element = $feed->add( $property );
  52. }
  53. if ( is_array( $val ) )
  54. {
  55. foreach ( $val as $subKey => $subValue )
  56. {
  57. if ( $subKey === '#' )
  58. {
  59. $element->set( $subValue );
  60. }
  61. else if ( $subKey === 'MULTI' )
  62. {
  63. $values = array();
  64. foreach ( $subValue as $multi )
  65. {
  66. foreach ( $multi as $subSubKey => $subSubValue )
  67. {
  68. if ( isset( $supportedModules[$subSubKey] ) )
  69. {
  70. $subElement = $element->addModule( $subSubKey );
  71. }
  72. else
  73. {
  74. if ( $property === 'skipDays' )
  75. {
  76. $values[] = $subSubValue;
  77. $element->days = $values;
  78. }
  79. else if ( $property === 'skipHours' )
  80. {
  81. $values[] = $subSubValue;
  82. $element->hours = $values;
  83. }
  84. else
  85. {
  86. $subElement = $element->add( $subSubKey );
  87. }
  88. }
  89. if ( $property !== 'skipDays'
  90. && $property !== 'skipHours' )
  91. {
  92. $subElement->set( $subSubValue );
  93. }
  94. }
  95. }
  96. }
  97. else
  98. {
  99. if ( is_array( $subValue ) )
  100. {
  101. if ( count( $subValue ) === 0 || !isset( $subValue[0] ) )
  102. {
  103. if ( isset( $supportedModules[$subKey] ) )
  104. {
  105. $subElement = $element->addModule( $subKey );
  106. }
  107. else
  108. {
  109. $subElement = $element->add( $subKey );
  110. }
  111. }
  112. foreach ( $subValue as $subSubKey => $subSubValue )
  113. {
  114. if ( $subSubKey === '#' )
  115. {
  116. $subElement->set( $subSubValue );
  117. }
  118. else
  119. {
  120. if ( is_array( $subSubValue ) )
  121. {
  122. if ( isset( $supportedModules[$subKey] ) )
  123. {
  124. $subElement = $element->addModule( $subKey );
  125. }
  126. else
  127. {
  128. $subElement = $element->add( $subKey );
  129. }
  130. foreach ( $subSubValue as $subSubSubKey => $subSubSubValue )
  131. {
  132. if ( $subSubSubKey === '#' )
  133. {
  134. $subElement->set( $subSubSubValue );
  135. }
  136. else
  137. {
  138. if ( is_array( $subSubSubValue ) )
  139. {
  140. foreach ( $subSubSubValue as $subSubSubSubKey => $subSubSubSubValue )
  141. {
  142. $subSubElement = $subElement->add( $subSubSubKey );
  143. foreach ( $subSubSubSubValue as $subSubSubSubSubKey => $subSubSubSubSubValue )
  144. {
  145. if ( $subSubSubSubSubKey === '#' )
  146. {
  147. $subSubElement->set( $subSubSubSubSubValue );
  148. }
  149. else
  150. {
  151. $subSubElement->$subSubSubSubSubKey = $subSubSubSubSubValue;
  152. }
  153. }
  154. }
  155. }
  156. else
  157. {
  158. $subElement->$subSubSubKey = $subSubSubValue;
  159. }
  160. }
  161. }
  162. }
  163. else
  164. {
  165. $subElement->$subSubKey = $subSubValue;
  166. }
  167. }
  168. }
  169. }
  170. else
  171. {
  172. $element->$subKey = $subValue;
  173. }
  174. }
  175. }
  176. }
  177. else
  178. {
  179. $element->set( $val );
  180. }
  181. }
  182. }
  183. else
  184. {
  185. $feed->$property = $value;
  186. }
  187. }
  188. }
  189. return $feed;
  190. }
  191. }
  192. ?>