PageRenderTime 68ms CodeModel.GetById 40ms RepoModel.GetById 1ms app.codeStats 0ms

/Test/control/PU_test_dcp_documentlink.php

https://github.com/CircleCode/dynacase-core
PHP | 218 lines | 184 code | 14 blank | 20 comment | 1 complexity | 3e339d01b249e3004a52a7bcb661bddf 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_document.php';
  14. class TestLink extends TestCaseDcpDocument
  15. {
  16. protected static $outputDir;
  17. protected function setUp()
  18. {
  19. // nothing
  20. }
  21. protected function tearDown()
  22. {
  23. // nothing
  24. }
  25. public static function setUpBeforeClass()
  26. {
  27. parent::setUpBeforeClass();
  28. self::connectUser();
  29. self::beginTransaction();
  30. // family
  31. self::importDocument("PU_data_dcp_documentlink.ods");
  32. // three documents : linkOne, linkTwo and linkThree
  33. self::importDocument("PU_data_dcp_documentslink.xml");
  34. }
  35. public static function tearDownAfterClass()
  36. {
  37. self::rollbackTransaction();
  38. }
  39. /**
  40. * @dataProvider dataAttrLinks
  41. */
  42. public function testAttrLinkCompose($docName, $link, $expectedLink)
  43. {
  44. $doc = new_doc(self::$dbaccess, $docName);
  45. $this->assertTrue($doc->isAlive() , "document $docName is not alive");
  46. $url = $doc->urlWhatEncode($link);
  47. $this->assertEquals($expectedLink, $url, "url link is not correctly encoded");
  48. }
  49. /**
  50. * @dataProvider dataParamLinks
  51. */
  52. public function testParamLinkCompose($docName, $link, array $params, $expectedLink)
  53. {
  54. $doc = new_doc(self::$dbaccess, $docName);
  55. $this->assertTrue($doc->isAlive() , "document $docName is not alive");
  56. foreach ($params as $k => $v) {
  57. $this->getApplication()->SetVolatileParam($k, $v);
  58. }
  59. $url = $doc->urlWhatEncode($link);
  60. $this->assertEquals($expectedLink, $url, "url link is not correctly encoded");
  61. }
  62. public function dataParamLinks()
  63. {
  64. return array(
  65. array(
  66. "linkOne",
  67. "http://www.test.com/{PU_TEST1}",
  68. array(
  69. "PU_TEST1" => "testOne"
  70. ) ,
  71. "http://www.test.com/testOne"
  72. ) ,
  73. array(
  74. "linkOne",
  75. "http://www.test.com/{PU_TEST2}",
  76. array(
  77. "PU_TEST2" => "test Two"
  78. ) ,
  79. "http://www.test.com/test%20Two"
  80. )
  81. );
  82. }
  83. public function dataAttrLinks()
  84. {
  85. return array(
  86. array(
  87. "linkOne",
  88. "http://www.test.com/",
  89. "http://www.test.com/"
  90. ) ,
  91. array(
  92. "linkThree",
  93. "http://test.com/%tst_title%/",
  94. "http://test.com/Test/"
  95. ) ,
  96. array(
  97. "linkThree",
  98. "http://test.com/?title=%tst_title%&long=%tst_longtext%",
  99. "http://test.com/?title=Test&long=Long"
  100. ) ,
  101. array(
  102. "linkOne",
  103. "http://test.com/?title=%tst_title%&long=%tst_longtext%",
  104. "http://test.com/?title=Arbre%20%2B%20Feuilles&long=La%20nature%20est%20jolie%20%3Cen%20automne%3E"
  105. ) ,
  106. array(
  107. "linkOne",
  108. "http://test.com/?title=%aa_one%",
  109. "http://test.com/?title=Un"
  110. ) ,
  111. array(
  112. "linkOne",
  113. "http://test.com/?title=%AA_ONE%",
  114. "http://test.com/?title=Un"
  115. ) ,
  116. array(
  117. "linkTwo",
  118. "http://test.com/?title=%tst_title%",
  119. "http://test.com/?title=Joe%20%26%20Jane"
  120. ) ,
  121. array(
  122. "linkTwo",
  123. "http://test.com/?long=%tst_longtext%",
  124. "http://test.com/?long=Premi%C3%A8re%20ligne%5CnEt%20deuxi%C3%A8me%20ligne"
  125. ) ,
  126. array(
  127. "linkTwo",
  128. "http://test.com/?date=%tst_coldate%",
  129. getLcDate() == 'iso' ? 'http://test.com/?date=2011-11-01%5Cn2011-11-02' : "http://test.com/?date=01%2F11%2F2011%5Cn02%2F11%2F2011"
  130. ) ,
  131. array(
  132. "linkTwo",
  133. "http://test.com/?date=%tst_nothing%",
  134. false
  135. ) ,
  136. array(
  137. "linkTwo",
  138. "http://test.com/?title=%title%",
  139. "http://test.com/?title=Joe%20%26%20Jane"
  140. ) ,
  141. array(
  142. "linkTwo",
  143. "http://test.com/?title=%TITLE%",
  144. "http://test.com/?title=Joe%20%26%20Jane"
  145. ) ,
  146. array(
  147. "linkTwo",
  148. "http://test.com/?title=%T%",
  149. "http://test.com/?title=Joe%20%26%20Jane"
  150. ) ,
  151. array(
  152. "linkTwo",
  153. "http://test.com/?title=%%2T",
  154. "http://test.com/?title=%2T"
  155. ) ,
  156. array(
  157. "linkTwo",
  158. "http://test.com/?title=%3A",
  159. "http://test.com/?title=%3A"
  160. ) ,
  161. array(
  162. "linkTwo",
  163. "http://test.com/?title=%3A%3ATest%28%29",
  164. "http://test.com/?title=%3A%3ATest%28%29"
  165. ) ,
  166. array(
  167. "linkTwo",
  168. "http://test.com/?title=%3A%3A%T%%28%29",
  169. "http://test.com/?title=%3A%3AJoe%20%26%20Jane%28%29"
  170. ) ,
  171. array(
  172. "linkTwo",
  173. "http://test.com/?title=%TITLE%&option=%?OPTIONONE%",
  174. "http://test.com/?title=Joe%20%26%20Jane&option="
  175. ) ,
  176. array(
  177. "linkTwo",
  178. "http://test.com/?title=%TITLE%&option1=%?OPTIONONE%&hard=true&option2=%?OPTIONTWO%",
  179. "http://test.com/?title=Joe%20%26%20Jane&option1=&hard=true&option2="
  180. ) ,
  181. array(
  182. "linkTwo",
  183. "::linkOne()",
  184. "::linkOne()"
  185. ) ,
  186. array(
  187. "linkTwo",
  188. "%::linkOne()%",
  189. "http://www.test.net/"
  190. ) ,
  191. array(
  192. "linkTwo",
  193. "%::linkOne()%?a=%T%",
  194. "http://www.test.net/?a=Joe%20%26%20Jane"
  195. ) ,
  196. array(
  197. "linkTwo",
  198. "%::linkTwo()%",
  199. "http://www.test.net/?b=Joe%20%26%20Jane"
  200. )
  201. );
  202. }
  203. }
  204. ?>