PageRenderTime 26ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/Test/control/PU_test_dcp_importfamily.php

https://github.com/CircleCode/dynacase-core
PHP | 353 lines | 310 code | 8 blank | 35 comment | 1 complexity | b226d9553f263013820af580b2909ecf MD5 | raw file
  1. <?php
  2. /*
  3. * @author Anakeen
  4. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License
  5. * @package Dcp\Pu
  6. */
  7. namespace Dcp\Pu;
  8. require_once 'PU_testcase_dcp_document.php';
  9. class TestImportFamily extends TestCaseDcpDocument
  10. {
  11. protected static $outputDir;
  12. /**
  13. * @dataProvider dataBadFamilyFiles
  14. */
  15. public function testErrorImportFamily($familyFile, $expectedErrors)
  16. {
  17. $err = '';
  18. try {
  19. $this->importDocument($familyFile);
  20. }
  21. catch(\Exception $e) {
  22. $err = $e->getMessage();
  23. }
  24. $this->assertNotEmpty($err, "no import error detected");
  25. if (!is_array($expectedErrors)) $expectedErrors = array(
  26. $expectedErrors
  27. );
  28. foreach ($expectedErrors as $expectedError) {
  29. $this->assertContains($expectedError, $err, sprintf("not the correct error reporting : %s", $err));
  30. }
  31. }
  32. /**
  33. * test sql view create
  34. * @dataProvider dataGoodFamilyFiles
  35. */
  36. public function testSqlViewFamily($familyFile, $familyName)
  37. {
  38. $err = '';
  39. try {
  40. $this->importDocument($familyFile);
  41. }
  42. catch(\Exception $e) {
  43. $err = $e->getMessage();
  44. }
  45. $this->assertEmpty($err, "import error detected $err");
  46. $doc = createDoc("", $familyName);
  47. $this->assertTrue(is_object($doc));
  48. $err = $doc->store();
  49. $this->assertEmpty($err, "cannot create good doc");
  50. $id = $this->_DBGetValue(sprintf("select id from family.%s limit 1", strtolower($familyName)));
  51. $this->assertGreaterThan(1000, $id, "not found by view");
  52. }
  53. /**
  54. * @dataProvider dataBadUpdateFamilyFiles
  55. */
  56. public function testBadUpdateFamily($installFamilyFile, $updateFamilyFile, $expectedError)
  57. {
  58. //print "log:".ini_get("error_log").".\n";
  59. $this->importDocument($installFamilyFile);
  60. $err = '';
  61. try {
  62. $this->importDocument($updateFamilyFile);
  63. }
  64. catch(\Exception $e) {
  65. $err = $e->getMessage();
  66. }
  67. $this->assertNotEmpty($err, "no update error detected");
  68. $this->assertContains($expectedError, $err, sprintf("not the correct error reporting : %s", $err));
  69. }
  70. public function dataBadUpdateFamilyFiles()
  71. {
  72. return array(
  73. // test attribute too long
  74. array(
  75. "PU_data_dcp_initfamily1.ods",
  76. "PU_data_dcp_updatefamily1.ods",
  77. "TST_TITLE"
  78. ) ,
  79. array(
  80. "PU_data_dcp_initfamily2.ods",
  81. "PU_data_dcp_updatefamily2.ods",
  82. "TST_TITLE"
  83. )
  84. );
  85. }
  86. public function dataBadFamilyFiles()
  87. {
  88. return array(
  89. // type modattr
  90. array(
  91. "PU_data_dcp_badmodattr1.ods",
  92. array(
  93. "ATTR0604",
  94. "TST_BADMODFAM_2",
  95. "attr_int",
  96. '"int"',
  97. "TST_BADMODFAM_3",
  98. "attr_date",
  99. '"date"'
  100. )
  101. ) ,
  102. // enum redfinition
  103. array(
  104. "PU_data_dcp_badmodattr2.ods",
  105. array(
  106. "ATTR0606",
  107. "attr_enum_a",
  108. "TST_BADMODFAM_4"
  109. )
  110. ) ,
  111. // undefined modattr
  112. array(
  113. "PU_data_dcp_badmodattr3.ods",
  114. array(
  115. "ATTR0605",
  116. "attr_undefined"
  117. )
  118. ) ,
  119. // test attribute too long
  120. array(
  121. "PU_data_dcp_badattr1.ods",
  122. array(
  123. "ATTR0100",
  124. "aaaaaa",
  125. "ATTR0102",
  126. "tst number",
  127. "ATTR0101",
  128. "select",
  129. "ATTR0103",
  130. "title",
  131. "ATTR0200",
  132. "tst_orphean",
  133. "ATTR0201",
  134. "tst_invstruct",
  135. "not defined",
  136. "ATTR0202",
  137. "tst_same",
  138. "ATTR0206",
  139. "none_tab"
  140. )
  141. ) ,
  142. // test method not found
  143. array(
  144. "PU_data_dcp_badattr2.ods",
  145. array(
  146. "Method.NotFound"
  147. )
  148. ) ,
  149. // test order needed
  150. array(
  151. "PU_data_dcp_badattr3.ods",
  152. array(
  153. "ATTR0700",
  154. "tst_noorder",
  155. "ATTR0702",
  156. "tst_errorder"
  157. )
  158. ) ,
  159. // test type
  160. array(
  161. "PU_data_dcp_badattr4.ods",
  162. array(
  163. "ATTR0600",
  164. "tst_typetest",
  165. "ATTR0601",
  166. "ATTR0602",
  167. "tst_errtype",
  168. "tst_notype"
  169. )
  170. ) ,
  171. // test visibility
  172. array(
  173. "PU_data_dcp_badattr5.ods",
  174. array(
  175. "ATTR0800",
  176. "tst_novis",
  177. "ATTR0801",
  178. "tst_errvis",
  179. "ZS",
  180. "ATTR0802",
  181. "tst_noarray"
  182. )
  183. ) ,
  184. // test isTitle isAbstract isNeeded
  185. array(
  186. "PU_data_dcp_badattr6.ods",
  187. array(
  188. "ATTR0500",
  189. "tst_noabstract",
  190. "ATTR0501",
  191. "tst_t_abstract",
  192. "ATTR0400",
  193. "tst_notitle",
  194. "ATTR0401",
  195. "tst_t_title",
  196. "ATTR0900",
  197. "tst_two",
  198. "ATTR0901",
  199. "tst_noneed"
  200. )
  201. ) ,
  202. // input help
  203. array(
  204. "PU_data_dcp_badattr7.ods",
  205. array(
  206. "ATTR1100",
  207. "tstNoHelp.php",
  208. "ATTR1101",
  209. "ATTR1200",
  210. "ATTR1201",
  211. "tst_nphelp",
  212. "noParenthesis",
  213. "ATTR1202",
  214. "ATTR1203",
  215. "testNoExistsReally",
  216. "ATTR1209",
  217. "is_a",
  218. "ATTR1210",
  219. "addLogMsg"
  220. )
  221. ) ,
  222. // options syntax
  223. array(
  224. "PU_data_dcp_badattr8.ods",
  225. array(
  226. "ATTR1500",
  227. "optionerror",
  228. "ATTR1501",
  229. "wrong error"
  230. )
  231. ) ,
  232. // options syntax
  233. array(
  234. "PU_data_dcp_badattr9.ods",
  235. array(
  236. "ATTR1250",
  237. "tst_number1",
  238. "ATTR1252",
  239. "ATTR1251",
  240. "tst_number2",
  241. "bad Compute1",
  242. "ATTR1400",
  243. "tst_number3",
  244. "ATTR1255",
  245. "tst_number4"
  246. )
  247. ) ,
  248. // method control in the end
  249. array(
  250. "PU_data_dcp_badattr10.ods",
  251. array(
  252. "ATTR1260",
  253. "badCompute1",
  254. "tst_number1",
  255. "ATTR1261",
  256. "tst_number2",
  257. "goodCompute2",
  258. "tst_number3",
  259. "ATTR1401",
  260. "tst_number4",
  261. "ATTR1402",
  262. "DFLT0004",
  263. "DFLT0005",
  264. "tst_notfound",
  265. "badCall",
  266. "ATTR1001",
  267. "ATTR1002",
  268. "goodCompute1",
  269. "DFLT0006",
  270. "notjson",
  271. "INIT0005",
  272. "tst_p2"
  273. )
  274. ) ,
  275. // method control in the end
  276. array(
  277. "PU_data_dcp_badattr11.ods",
  278. array(
  279. "ATTR0203",
  280. "tst_number2",
  281. "ATTR0204",
  282. "tst_number1",
  283. "ATTR0205",
  284. "tst_number4",
  285. "ATTR0207",
  286. "tst_frame2",
  287. "ATTR0902",
  288. "tst_colneed"
  289. )
  290. ) ,
  291. // static enum
  292. array(
  293. "PU_data_dcp_badattr12.ods",
  294. array(
  295. "ATTR1270",
  296. "tst_badeenum",
  297. "tst_badnenum",
  298. "ATTR1271",
  299. "tst_badkenum",
  300. "DFLT0001",
  301. "tst syntax",
  302. "DFLT0002",
  303. "DFLT0003"
  304. )
  305. ) ,
  306. // format string
  307. array(
  308. "PU_data_dcp_badattr13.ods",
  309. array(
  310. "ATTR0603",
  311. "tst_badformat2"
  312. )
  313. ) ,
  314. // format string
  315. array(
  316. "PU_data_dcp_badattr14.ods",
  317. array(
  318. "ATTR1701"
  319. )
  320. )
  321. );
  322. }
  323. public function dataGoodFamilyFiles()
  324. {
  325. return array(
  326. // test simple family
  327. array(
  328. "PU_data_dcp_goodfamily1.ods",
  329. "TST_GOODFAMIMP1",
  330. false
  331. ) , // with method file
  332. array(
  333. "PU_data_dcp_goodfamily2.ods",
  334. "TST_GOODFAMIMP2",
  335. false
  336. ) , // with class file
  337. array(
  338. "PU_data_dcp_goodfamily4.ods",
  339. "TST_GOODFAMIMP4",
  340. false
  341. )
  342. );
  343. }
  344. }
  345. ?>