/tests/unit/backend/services/ContentTest.php

https://bitbucket.org/ferOnti/processmaker · PHP · 174 lines · 109 code · 41 blank · 24 comment · 4 complexity · 144302d4b97b53172594c41b3c9302be MD5 · raw file

  1. <?php
  2. if (!defined('PATH_SEP')) {
  3. define('PATH_SEP', '/');
  4. }
  5. require_once PATH_HOME . 'engine/services/rest/crud/Content.php';
  6. require_once("Rest/JsonMessage.php");
  7. require_once("Rest/XmlMessage.php");
  8. require_once("Rest/RestMessage.php");
  9. class ContentTest extends PHPUnit_Extensions_Database_TestCase
  10. {
  11. public function setup()
  12. {
  13. }
  14. protected function getTearDownOperation()
  15. {
  16. return PHPUnit_Extensions_Database_Operation_Factory::DELETE_ALL();
  17. }
  18. /**
  19. * @return PHPUnit_Extensions_Database_DB_IDatabaseConnection
  20. */
  21. // only instantiate pdo once for test clean-up/fixture load
  22. static private $pdo = null;
  23. // only instantiate PHPUnit_Extensions_Database_DB_IDatabaseConnection once per test
  24. private $conn = null;
  25. public function getConnection()
  26. {
  27. if ($this->conn === null) {
  28. $dsn = 'mysql:dbname=' . $_SERVER['PM_UNIT_DB_NAME'] . ';host='. $_SERVER['PM_UNIT_DB_HOST'];
  29. if (self::$pdo == null) {
  30. self::$pdo = new PDO(
  31. $dsn,
  32. $_SERVER['PM_UNIT_DB_USER'],
  33. $_SERVER['PM_UNIT_DB_PASS'] );
  34. }
  35. $this->conn = $this->createDefaultDBConnection(self::$pdo, $_SERVER['PM_UNIT_DB_NAME']);
  36. }
  37. return $this->conn;
  38. }
  39. /**
  40. *@return PHPUnit_Extensions_Database_DataSet_IDataSet
  41. */
  42. public function getDataSet()
  43. {
  44. return $this->createXMLDataSet('tests/unit/backend/services/Rest/fixtures/application.xml');
  45. }
  46. public function testGet()
  47. {
  48. $msg = array( 'user'=>'admin' , 'password'=>'admin');
  49. $method = "login";
  50. $jsonm = new JsonMessage();
  51. $jsonm->send($method,$msg);
  52. //$jsonm->displayResponse();
  53. $xmlm = new XmlMessage();
  54. $xmlm->send($method, $msg);
  55. //$xmlm->displayResponse();
  56. $key = array( "PRO_TITLE", "", "6548800755065a63d67f727063273525", "en");
  57. $key1 = array( "PRO_DESCRIPTION", "", "4880075", "en");
  58. $table = "CONTENT";
  59. $rest = new RestMessage();
  60. $resp = $rest->sendGET($table,$key);
  61. $rest->sendGET($table,$key1);
  62. //$rest->displayResponse();
  63. $queryTable = $this->getConnection()->createQueryTable(
  64. 'CONTENT', 'SELECT * FROM CONTENT WHERE CON_CATEGORY = "PRO_TITLE" AND CON_ID = "6548800755065a63d67f727063273525"'
  65. );
  66. //$this->assertEquals($resp, $queryTable, "ERROR getting data");
  67. }
  68. public function testPost()
  69. {
  70. $msg = array( 'user'=>'admin' , 'password'=>'admin');
  71. $method = "login";
  72. $jsonm = new JsonMessage();
  73. $jsonm->send($method,$msg);
  74. //$jsonm->displayResponse();
  75. $xmlm = new XmlMessage();
  76. $xmlm->send($method, $msg);
  77. //$xmlm->displayResponse();
  78. $key = array( "PRO_TITLE", "", "6666000755065a63d67f727063273222", "en", "SAMPLE");
  79. $table = "CONTENT";
  80. $rest = new RestMessage();
  81. $rest->sendPOST($table,$key);
  82. //$rest->displayResponse();
  83. $key1 = array("PRO_TITLE", "", "6666000755065a63d67f727063273222", "en");
  84. $resp = $rest->sendGET($table,$key1);
  85. $queryTable = $this->getConnection()->createQueryTable(
  86. 'CONTENT', 'SELECT * FROM CONTENT WHERE CON_CATEGORY = "PRO_TITLE" AND CON_ID = "6666000755065a63d67f727063273222"'
  87. );
  88. //$this->assertEquals($queryTable, $resp, "ERROR inserting data");
  89. }
  90. public function testPut()
  91. {
  92. $msg = array( 'user'=>'admin' , 'password'=>'admin');
  93. $method = "login";
  94. $jsonm = new JsonMessage();
  95. $jsonm->send($method,$msg);
  96. //$jsonm->displayResponse();
  97. $xmlm = new XmlMessage();
  98. $xmlm->send($method, $msg);
  99. //$xmlm->displayResponse();
  100. $key = array( "PRO_TITLE", "", "6666000755065a63d67f727063273222", "en", "XAMPLE");
  101. $table = "CONTENT";
  102. $rest = new RestMessage();
  103. $rest->sendPUT($table,$key);
  104. //$rest->displayResponse();
  105. $key1 = array("PRO_TITLE", "", "6666000755065a63d67f727063273222", "en");
  106. $resp = $rest->sendGET($table,$key1);
  107. $queryTable = $this->getConnection()->createQueryTable(
  108. 'CONTENT', 'SELECT * FROM CONTENT WHERE CON_CATEGORY = "PRO_TITLE" AND CON_ID = "6666000755065a63d67f727063273222"'
  109. );
  110. //$this->assertEquals($queryTable, $resp, "ERROR updating data");
  111. }
  112. public function testDelete()
  113. {
  114. $msg = array( 'user'=>'admin' , 'password'=>'admin');
  115. $method = "login";
  116. $jsonm = new JsonMessage();
  117. $jsonm->send($method,$msg);
  118. //$jsonm->displayResponse();
  119. $xmlm = new XmlMessage();
  120. $xmlm->send($method, $msg);
  121. //$xmlm->displayResponse();
  122. $key = array( "PRO_TITLE", "", "6666000755065a63d67f727063273222", "en");
  123. $table = "CONTENT";
  124. $rest = new RestMessage();
  125. $rest->sendDELETE($table,$key);
  126. //$rest->displayResponse();
  127. $resp = $rest->sendGET($table,$key);
  128. $queryTable = $this->getConnection()->createQueryTable(
  129. 'CONTENT', 'SELECT * FROM CONTENT WHERE CON_CATEGORY = "PRO_TITLE" AND CON_ID = "6666000755065a63d67f727063273222"'
  130. );
  131. //$this->assertEquals($queryTable, $resp, "ERROR deleting data");
  132. }
  133. }