PageRenderTime 24ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/phpunit/api/v2/NoteTest.php

https://github.com/ksecor/civicrm
PHP | 302 lines | 168 code | 40 blank | 94 comment | 0 complexity | e8e9b0393fb0b511fdb60f5e51165106 MD5 | raw file
  1. <?php
  2. /*
  3. +--------------------------------------------------------------------+
  4. | CiviCRM version 3.1 |
  5. +--------------------------------------------------------------------+
  6. | Copyright CiviCRM LLC (c) 2004-2009 |
  7. +--------------------------------------------------------------------+
  8. | This file is a part of CiviCRM. |
  9. | |
  10. | CiviCRM is free software; you can copy, modify, and distribute it |
  11. | under the terms of the GNU Affero General Public License |
  12. | Version 3, 19 November 2007. |
  13. | |
  14. | CiviCRM is distributed in the hope that it will be useful, but |
  15. | WITHOUT ANY WARRANTY; without even the implied warranty of |
  16. | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
  17. | See the GNU Affero General Public License for more details. |
  18. | |
  19. | You should have received a copy of the GNU Affero General Public |
  20. | License along with this program; if not, contact CiviCRM LLC |
  21. | at info[AT]civicrm[DOT]org. If you have questions about the |
  22. | GNU Affero General Public License or the licensing of CiviCRM, |
  23. | see the CiviCRM license FAQ at http://civicrm.org/licensing |
  24. +--------------------------------------------------------------------+
  25. */
  26. require_once 'api/v2/Note.php';
  27. require_once 'tests/phpunit/CiviTest/CiviUnitTestCase.php';
  28. /**
  29. * Class contains api test cases for "civicrm_note"
  30. *
  31. */
  32. class api_v2_NoteTest extends CiviUnitTestCase
  33. {
  34. protected $_contactID;
  35. protected $_params;
  36. function __construct( ) {
  37. parent::__construct( );
  38. }
  39. function get_info( )
  40. {
  41. return array(
  42. 'name' => 'Note Create',
  43. 'description' => 'Test all Note Create API methods.',
  44. 'group' => 'CiviCRM API Tests',
  45. );
  46. }
  47. function setUp()
  48. {
  49. // Connect to the database
  50. parent::setUp();
  51. $this->_contactID = $this->organizationCreate( );
  52. $this->_params = array(
  53. 'entity_table' => 'civicrm_contact',
  54. 'entity_id' => $this->_contactID,
  55. 'note' => 'Hello!!! m testing Note',
  56. 'contact_id' => $this->_contactID,
  57. 'modified_date' => date('Ymd'),
  58. 'subject' => 'Test Note',
  59. );
  60. $this->_note = $this->noteCreate( $this->_contactID );
  61. $this->_noteID = $this->_note['id'];
  62. }
  63. function tearDown( )
  64. {
  65. }
  66. ///////////////// civicrm_note_get methods
  67. /**
  68. * check retrieve note with wrong params type
  69. * Error Expected
  70. */
  71. function testGetWithWrongParamsType( )
  72. {
  73. $params = 'a string';
  74. $result =& civicrm_note_get( $params );
  75. $this->assertEquals( $result['is_error'], 1,
  76. "In line " . __LINE__ );
  77. }
  78. /**
  79. * check retrieve note with empty parameter array
  80. * Error expected
  81. */
  82. function testGetWithEmptyParams( )
  83. {
  84. $params = array( );
  85. $note =& civicrm_note_get( $params );
  86. $this->assertEquals( $note['is_error'], 1 );
  87. $this->assertEquals( $note['error_message'], 'No input parameters present' );
  88. }
  89. /**
  90. * check retrieve note with missing patrameters
  91. * Error expected
  92. */
  93. function testGetWithoutEntityId( )
  94. {
  95. $params = array( 'entity_table' => 'civicrm_contact' );
  96. $note =& civicrm_note_get( $params );
  97. $this->assertEquals( $note['is_error'], 1 );
  98. $this->assertEquals( $note['error_message'], 'Invalid entity ID' );
  99. }
  100. /**
  101. * check civicrm_note_get
  102. */
  103. function testGet( )
  104. {
  105. $entityId = $this->_note['entity_id'];
  106. $params = array(
  107. 'entity_table' => 'civicrm_contact',
  108. 'entity_id' => $entityId
  109. );
  110. $result = civicrm_note_get( $params );
  111. $this->assertEquals( $result['is_error'], 0 );
  112. }
  113. ///////////////// civicrm_note_create methods
  114. /**
  115. * Check create with wrong parameter
  116. * Error expected
  117. */
  118. function testCreateWithWrongParamsType( )
  119. {
  120. $params = 'a string';
  121. $result =& civicrm_note_create( $params );
  122. $this->assertEquals( $result['is_error'], 1,
  123. "In line " . __LINE__ );
  124. $this->assertEquals( $result['error_message'], 'Params is not an array' );
  125. }
  126. /**
  127. * Check create with empty parameter array
  128. * Error Expected
  129. */
  130. function testCreateWithEmptyParams( )
  131. {
  132. $params = array( );
  133. $result = civicrm_note_create( $params );
  134. $this->assertEquals( $result['is_error'], 1 );
  135. $this->assertEquals( $result['error_message'], 'Required parameter missing' );
  136. }
  137. /**
  138. * Check create with partial params
  139. * Error expected
  140. */
  141. function testCreateWithoutEntityId( )
  142. {
  143. unset($this->_params['entity_id']);
  144. $result = civicrm_note_create( $this->_params );
  145. $this->assertEquals( $result['is_error'], 1 );
  146. $this->assertEquals( $result['error_message'], 'Required parameter missing' );
  147. }
  148. /**
  149. * Check civicrm_note_create
  150. */
  151. function testCreate( )
  152. {
  153. $result = civicrm_note_create( $this->_params );
  154. $this->assertEquals( $result['note'], 'Hello!!! m testing Note');
  155. $this->assertArrayHasKey( 'entity_id', $result );
  156. $this->assertEquals( $result['is_error'], 0 );
  157. $note = array('id' => $result['id'] );
  158. $this->noteDelete( $note );
  159. }
  160. ///////////////// civicrm_note_update methods
  161. /**
  162. * Check update note with wrong params type
  163. * Error expected
  164. */
  165. function testUpdateWithWrongParamsType( )
  166. {
  167. $params = 'a string';
  168. $result =& civicrm_note_update( $params );
  169. $this->assertEquals( $result['is_error'], 1,
  170. "In line " . __LINE__ );
  171. }
  172. /**
  173. * Check update with empty parameter array
  174. * Error expected
  175. */
  176. function testUpdateWithEmptyParams( )
  177. {
  178. $params = array();
  179. $note =& civicrm_note_update( $params );
  180. $this->assertEquals( $note['is_error'], 1 );
  181. $this->assertEquals( $note['error_message'], 'Required parameter missing' );
  182. }
  183. /**
  184. * Check update with missing parameter (contact id)
  185. * Error expected
  186. */
  187. function testUpdateWithoutContactId( )
  188. {
  189. $params = array(
  190. 'entity_id' => $this->_contactID,
  191. 'entity_table' => 'civicrm_contact'
  192. );
  193. $note =& civicrm_note_update( $params );
  194. $this->assertEquals( $note['is_error'], 1 );
  195. $this->assertEquals( $note['error_message'], 'Required parameter missing' );
  196. }
  197. /**
  198. * Check civicrm_note_update
  199. */
  200. function testUpdate( )
  201. {
  202. $params = array(
  203. 'id' => $this->_noteID,
  204. 'contact_id' => $this->_contactID,
  205. 'entity_id' => $this->_contactID,
  206. 'entity_table' => 'civicrm_contribution',
  207. 'note' => 'Note1',
  208. 'subject' => 'Hello World'
  209. );
  210. //Update Note
  211. $note =& civicrm_note_update( $params );
  212. $this->assertEquals( $note['id'],$this->_noteID );
  213. $this->assertEquals( $note['entity_id'],$this->_contactID );
  214. $this->assertEquals( $note['entity_table'],'civicrm_contribution' );
  215. }
  216. ///////////////// civicrm_note_delete methods
  217. /**
  218. * Check delete note with wrong params type
  219. * Error expected
  220. */
  221. function testDeleteWithWrongParamsType( )
  222. {
  223. $params = 'a string';
  224. $result =& civicrm_note_delete( $params );
  225. $this->assertEquals( $result['is_error'], 1,
  226. "In line " . __LINE__ );
  227. }
  228. /**
  229. * Check delete with empty parametes array
  230. * Error expected
  231. */
  232. function testDeleteWithEmptyParams( )
  233. {
  234. $params = array();
  235. $deleteNote = & civicrm_note_delete( $params );
  236. $this->assertEquals( $deleteNote['is_error'], 1 );
  237. $this->assertEquals( $deleteNote['error_message'], 'Invalid or no value for Note ID');
  238. }
  239. /**
  240. * Check delete with wrong id
  241. * Error expected
  242. */
  243. function testDeleteWithWrongID( )
  244. {
  245. $params = array( 'id' => 0 );
  246. $deleteNote = & civicrm_note_delete( $params );
  247. $this->assertEquals( $deleteNote['is_error'], 1 );
  248. $this->assertEquals( $deleteNote['error_message'], 'Invalid or no value for Note ID');
  249. }
  250. /**
  251. * Check civicrm_note_delete
  252. */
  253. function testDelete( )
  254. {
  255. $params = array( 'id' => $this->_noteID,
  256. 'entity_id' => $this->_note['entity_id']
  257. );
  258. $deleteNote =& civicrm_note_delete( $params );
  259. $this->assertEquals( $deleteNote['is_error'], 0 );
  260. $this->assertEquals( $deleteNote['result'], 1 );
  261. }
  262. }