/Test/control/PU_test_dcp_newdoc.php

https://github.com/CircleCode/dynacase-core · PHP · 418 lines · 376 code · 12 blank · 30 comment · 7 complexity · d34ad27e43ecbb8abf53f8b60eda6f3d 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 FDL
  6. */
  7. namespace Dcp\Pu;
  8. /**
  9. * @author Anakeen
  10. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License
  11. * @package Dcp\Pu
  12. */
  13. require_once 'PU_testcase_dcp_commonfamily.php';
  14. class TestNewDoc extends TestCaseDcpCommonFamily
  15. {
  16. private static $ids = array();
  17. public static function setUpBeforeClass()
  18. {
  19. parent::setUpBeforeClass();
  20. $d = createDoc(self::$dbaccess, \Dcp\Family\Base::familyName);
  21. $d->setAttributeValue(\Dcp\AttributeIdentifiers\Base::ba_title, "x1-" . $d->revision);
  22. $d->store();
  23. $d->setLogicalName("TST_X1");
  24. self::$ids[$d->name][$d->revision] = array(
  25. "id" => $d->id,
  26. "title" => $d->getTitle()
  27. );
  28. $d = createDoc(self::$dbaccess, \Dcp\Family\Base::familyName);
  29. $d->setAttributeValue(\Dcp\AttributeIdentifiers\Base::ba_title, "x2-" . $d->revision);
  30. $d->store();
  31. $d->setLogicalName("TST_X2");
  32. self::$ids[$d->name][$d->revision] = array(
  33. "id" => $d->id,
  34. "title" => $d->getTitle()
  35. );
  36. $d->revise();
  37. $d->setAttributeValue(\Dcp\AttributeIdentifiers\Base::ba_title, "x2-" . $d->revision);
  38. $d->store();
  39. self::$ids[$d->name][$d->revision] = array(
  40. "id" => $d->id,
  41. "title" => $d->getTitle()
  42. );
  43. $d = createDoc(self::$dbaccess, \Dcp\Family\Base::familyName);
  44. $d->setAttributeValue(\Dcp\AttributeIdentifiers\Base::ba_title, "x3-" . $d->revision);
  45. $d->store();
  46. $d->setLogicalName("TST_X3");
  47. self::$ids[$d->name][$d->revision] = array(
  48. "id" => $d->id,
  49. "title" => $d->getTitle()
  50. );
  51. $d->revise();
  52. $d->setAttributeValue(\Dcp\AttributeIdentifiers\Base::ba_title, "x3-" . $d->revision);
  53. $d->store();
  54. self::$ids[$d->name][$d->revision] = array(
  55. "id" => $d->id,
  56. "title" => $d->getTitle()
  57. );
  58. $d->revise();
  59. $d->setAttributeValue(\Dcp\AttributeIdentifiers\Base::ba_title, "x3-" . $d->revision);
  60. self::$ids[$d->name][$d->revision] = array(
  61. "id" => $d->id,
  62. "title" => $d->getTitle()
  63. );
  64. $d->store();
  65. $d = createDoc(self::$dbaccess, \Dcp\Family\Base::familyName);
  66. $d->setAttributeValue(\Dcp\AttributeIdentifiers\Base::ba_title, "x4-" . $d->revision);
  67. $d->store();
  68. $d->setLogicalName("TST_X4");
  69. self::$ids[$d->name][$d->revision] = array(
  70. "id" => $d->id,
  71. "title" => $d->getTitle()
  72. );
  73. $d->revise();
  74. $d->setAttributeValue(\Dcp\AttributeIdentifiers\Base::ba_title, "x4-" . $d->revision);
  75. $d->store();
  76. self::$ids[$d->name][$d->revision] = array(
  77. "id" => $d->id,
  78. "title" => $d->getTitle()
  79. );
  80. $d->revise();
  81. $d->setAttributeValue(\Dcp\AttributeIdentifiers\Base::ba_title, "x4-" . $d->revision);
  82. self::$ids[$d->name][$d->revision] = array(
  83. "id" => $d->id,
  84. "title" => $d->getTitle()
  85. );
  86. $d->store();
  87. $d->locked = - 1;
  88. $d->modify(); // close document
  89. $dM = createDoc(self::$dbaccess, \Dcp\Family\Dir::familyName);
  90. // need to change its family BASE to DIR
  91. $dM->initid = $d->initid;
  92. $dM->name = $d->name;
  93. $dM->revision = $d->revision + 1;
  94. $dM->setAttributeValue(\Dcp\AttributeIdentifiers\Dir::ba_title, "x4M-" . $dM->revision);
  95. $dM->setAttributeValue(\Dcp\AttributeIdentifiers\Dir::fld_allbut, "1");
  96. $dM->store();
  97. self::$ids[$dM->name][$dM->revision] = array(
  98. "id" => $dM->id,
  99. "title" => $d->getTitle()
  100. );
  101. $dM->revise();
  102. $dM->setAttributeValue(\Dcp\AttributeIdentifiers\Dir::ba_title, "x4M-" . $dM->revision);
  103. $dM->setAttributeValue(\Dcp\AttributeIdentifiers\Dir::fld_allbut, "2");
  104. $dM->store();
  105. self::$ids[$dM->name][$dM->revision] = array(
  106. "id" => $dM->id,
  107. "title" => $dM->getTitle()
  108. );
  109. }
  110. /**
  111. * @dataProvider dataSimpleNewDoc
  112. */
  113. public function testSimpleNewDoc($docName, $expectedTitle)
  114. {
  115. $d = new_doc(self::$dbaccess, $docName);
  116. $this->assertTrue($d->isAffected() , "document $docName not found");
  117. $this->assertTrue($d->isAlive() , "document $docName not last revision\n" . print_r(self::$ids[$docName], true));
  118. $this->assertEquals($expectedTitle, $d->getTitle() , "wrong title for $docName\n" . print_r(self::$ids[$docName], true));
  119. // print_r("test".print_r(self::$ids[$docName], true) );
  120. }
  121. /**
  122. * @dataProvider dataReviseNewDoc
  123. */
  124. public function testReviseNewDoc($docName, $revision, $expectedTitle)
  125. {
  126. $id = self::$ids[$docName][$revision]["id"];
  127. $d = new_doc(self::$dbaccess, $id);
  128. $this->assertTrue($d->isAffected() , "document $docName not found");
  129. $this->assertEquals($d->id, $id, "document $docName (rev $revision) not match id");
  130. $this->assertEquals($expectedTitle, $d->getTitle() , "wrong title for $docName");
  131. }
  132. /**
  133. * @dataProvider dataLatestNewDoc
  134. */
  135. public function testLatestNewDoc($docName, $revision, $expectedTitle)
  136. {
  137. $id = self::$ids[$docName][$revision]["id"];
  138. $d = new_doc(self::$dbaccess, $id, true);
  139. $this->assertTrue($d->isAffected() , "document $docName not found");
  140. $this->assertTrue($d->isAlive() , "document $docName #$id not last revision" . print_r(self::$ids[$docName], true));
  141. $this->assertEquals($expectedTitle, $d->getTitle() , "wrong title for $docName");
  142. }
  143. /**
  144. * @dataProvider dataSimplegetTDoc
  145. */
  146. public function testSimpleGetTDoc($docName, $expectedValues)
  147. {
  148. $d = getTDoc(self::$dbaccess, $docName);
  149. foreach ($expectedValues as $attrid => $expectedValue) {
  150. $this->assertTrue(isset($d[strtolower($attrid) ]) , sprintf("attribut %s not found", $attrid));
  151. $this->assertEquals($expectedValue, $d[strtolower($attrid) ], sprintf("wrong value %s : %s", $attrid, print_r($d, true)));
  152. }
  153. $d = getLatestTDoc(self::$dbaccess, $d["initid"]);
  154. foreach ($expectedValues as $attrid => $expectedValue) {
  155. $this->assertTrue(isset($d[strtolower($attrid) ]) , sprintf("attribut for latest %s not found", $attrid));
  156. $this->assertEquals($expectedValue, $d[strtolower($attrid) ], sprintf("wrong value for latest %s : %s", $attrid, print_r($d, true)));
  157. }
  158. }
  159. /**
  160. * @dataProvider dataGetLatestRevisionNumber
  161. */
  162. public function testGetLatestRevisionNumber($docName, $expectedValues)
  163. {
  164. $d = getTDoc(self::$dbaccess, $docName);
  165. $this->assertEquals($expectedValues, getLatestRevisionNumber(self::$dbaccess, $d["initid"]) , "not good last revision number");
  166. }
  167. /**
  168. * @dataProvider dataGetRevTDoc
  169. */
  170. public function testGetRevTDoc($docName, $revision, $expectedValues)
  171. {
  172. $d = getTDoc(self::$dbaccess, $docName);
  173. $d = getRevTDoc(self::$dbaccess, $d["initid"], $revision);
  174. foreach ($expectedValues as $attrid => $expectedValue) {
  175. $this->assertTrue(isset($d[strtolower($attrid) ]) , sprintf("attribut for latest %s not found", $attrid));
  176. $this->assertEquals($expectedValue, $d[strtolower($attrid) ], sprintf("wrong value for latest %s : %s", $attrid, print_r($d, true)));
  177. }
  178. }
  179. public function dataLatestNewDoc()
  180. {
  181. return array(
  182. array(
  183. "TST_X1",
  184. 0,
  185. "x1-0"
  186. ) ,
  187. array(
  188. "TST_X2",
  189. 0,
  190. "x2-1"
  191. ) ,
  192. array(
  193. "TST_X2",
  194. 1,
  195. "x2-1"
  196. ) ,
  197. array(
  198. "TST_X3",
  199. 0,
  200. "x3-2"
  201. ) ,
  202. array(
  203. "TST_X3",
  204. 1,
  205. "x3-2"
  206. ) ,
  207. array(
  208. "TST_X3",
  209. 2,
  210. "x3-2"
  211. ) ,
  212. array(
  213. "TST_X4",
  214. 0,
  215. "x4M-4"
  216. ) ,
  217. array(
  218. "TST_X4",
  219. 1,
  220. "x4M-4"
  221. ) ,
  222. array(
  223. "TST_X4",
  224. 2,
  225. "x4M-4"
  226. ) ,
  227. array(
  228. "TST_X4",
  229. 3,
  230. "x4M-4"
  231. ) ,
  232. array(
  233. "TST_X4",
  234. 4,
  235. "x4M-4"
  236. )
  237. );
  238. }
  239. public function dataReviseNewDoc()
  240. {
  241. return array(
  242. array(
  243. "TST_X1",
  244. 0,
  245. "x1-0"
  246. ) ,
  247. array(
  248. "TST_X2",
  249. 0,
  250. "x2-0"
  251. ) ,
  252. array(
  253. "TST_X2",
  254. 1,
  255. "x2-1"
  256. ) ,
  257. array(
  258. "TST_X3",
  259. 2,
  260. "x3-2"
  261. ) ,
  262. array(
  263. "TST_X4",
  264. 2,
  265. "x4-2"
  266. ) ,
  267. array(
  268. "TST_X4",
  269. 3,
  270. "x4M-3"
  271. )
  272. );
  273. }
  274. public function dataGetLatestRevisionNumber()
  275. {
  276. return array(
  277. array(
  278. "TST_X1",
  279. 0
  280. ) ,
  281. array(
  282. "TST_X2",
  283. 1
  284. ) ,
  285. array(
  286. "TST_X3",
  287. 2
  288. ) ,
  289. array(
  290. "TST_X4",
  291. 4
  292. )
  293. );
  294. }
  295. public function dataSimplegetTDoc()
  296. {
  297. return array(
  298. array(
  299. "TST_X1",
  300. array(
  301. "title" => "x1-0"
  302. )
  303. ) ,
  304. array(
  305. "TST_X2",
  306. array(
  307. "title" => "x2-1"
  308. )
  309. ) ,
  310. array(
  311. "TST_X3",
  312. array(
  313. "title" => "x3-2"
  314. )
  315. ) ,
  316. array(
  317. "TST_X4",
  318. array(
  319. "title" => "x4M-4",
  320. "fld_allbut" => "2"
  321. )
  322. )
  323. );
  324. }
  325. public function dataGetRevTDoc()
  326. {
  327. return array(
  328. array(
  329. "TST_X1",
  330. 0,
  331. array(
  332. "title" => "x1-0"
  333. )
  334. ) ,
  335. array(
  336. "TST_X2",
  337. 1,
  338. array(
  339. "title" => "x2-1"
  340. )
  341. ) ,
  342. array(
  343. "TST_X3",
  344. 2,
  345. array(
  346. "title" => "x3-2"
  347. )
  348. ) ,
  349. array(
  350. "TST_X4",
  351. 0,
  352. array(
  353. "title" => "x4-0",
  354. "ba_title" => "x4-0"
  355. )
  356. ) ,
  357. array(
  358. "TST_X4",
  359. 2,
  360. array(
  361. "title" => "x4-2",
  362. "ba_title" => "x4-2"
  363. )
  364. ) ,
  365. array(
  366. "TST_X4",
  367. 3,
  368. array(
  369. "title" => "x4M-3",
  370. "ba_title" => "x4M-3",
  371. "fld_allbut" => "1"
  372. )
  373. ) ,
  374. array(
  375. "TST_X4",
  376. 4,
  377. array(
  378. "title" => "x4M-4",
  379. "ba_title" => "x4M-4",
  380. "fld_allbut" => "2"
  381. )
  382. )
  383. );
  384. }
  385. public function dataSimpleNewDoc()
  386. {
  387. return array(
  388. array(
  389. "TST_X1",
  390. "x1-0"
  391. ) ,
  392. array(
  393. "TST_X2",
  394. "x2-1"
  395. ) ,
  396. array(
  397. "TST_X3",
  398. "x3-2"
  399. ) ,
  400. array(
  401. "TST_X4",
  402. "x4M-4"
  403. )
  404. );
  405. }
  406. }