From: Coleman Watts Date: Fri, 6 Feb 2015 15:07:36 +0000 (-0500) Subject: Move testCustomFileField out of transactional class X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=b3c30fda462a9c6f3a1c62b88da054057cf39145;p=civicrm-core.git Move testCustomFileField out of transactional class --- diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index bffe25a7be..7e007b38db 100755 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -3277,4 +3277,20 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) } } + /** + * @param $exists + * @param array $apiResult + */ + protected function assertAttachmentExistence($exists, $apiResult) { + $fileId = $apiResult['id']; + $this->assertTrue(is_numeric($fileId)); + $this->assertEquals($exists, file_exists($apiResult['values'][$fileId]['path'])); + $this->assertDBQuery($exists ? 1 : 0, 'SELECT count(*) FROM civicrm_file WHERE id = %1', array( + 1 => array($fileId, 'Int'), + )); + $this->assertDBQuery($exists ? 1 : 0, 'SELECT count(*) FROM civicrm_entity_file WHERE id = %1', array( + 1 => array($fileId, 'Int'), + )); + } + } diff --git a/tests/phpunit/api/v3/AttachmentTest.php b/tests/phpunit/api/v3/AttachmentTest.php index cb3bd10471..830ffe239c 100644 --- a/tests/phpunit/api/v3/AttachmentTest.php +++ b/tests/phpunit/api/v3/AttachmentTest.php @@ -552,57 +552,6 @@ class api_v3_AttachmentTest extends CiviUnitTestCase { $this->assertAttachmentExistence(FALSE, $createResults['delme']['second']); } - /** - * - */ - public function testCustomFileField() { - $customGroup = $this->customGroupCreate(array('title' => 'attachment_test_group')); - $params = array( - 'custom_group_id' => $customGroup['id'], - 'name' => 'test_file_attachment', - 'label' => 'test_file_attachment', - 'html_type' => 'File', - 'data_type' => 'File', - 'is_active' => 1, - ); - $customField = $this->callAPISuccess('custom_field', 'create', $params); - $cfId = 'custom_' . $customField['id']; - - $cid = $this->individualCreate(); - - $attachment = $this->callAPISuccess('attachment', 'create', array( - 'name' => self::getFilePrefix() . 'testCustomFileField.txt', - 'mime_type' => 'text/plain', - 'content' => 'My test content', - 'field_name' => $cfId, - 'entity_id' => $cid, - )); - $this->assertAttachmentExistence(TRUE, $attachment); - - $result = $this->callAPISuccess('contact', 'getsingle', array( - 'id' => $cid, - 'return' => $cfId, - )); - - $this->assertEquals($attachment['id'], $result[$cfId]); - } - - /** - * @param $exists - * @param array $apiResult - */ - protected function assertAttachmentExistence($exists, $apiResult) { - $fileId = $apiResult['id']; - $this->assertTrue(is_numeric($fileId)); - $this->assertEquals($exists, file_exists($apiResult['values'][$fileId]['path'])); - $this->assertDBQuery($exists ? 1 : 0, 'SELECT count(*) FROM civicrm_file WHERE id = %1', array( - 1 => array($fileId, 'Int'), - )); - $this->assertDBQuery($exists ? 1 : 0, 'SELECT count(*) FROM civicrm_entity_file WHERE id = %1', array( - 1 => array($fileId, 'Int'), - )); - } - /** * @param $name * @return string diff --git a/tests/phpunit/api/v3/CustomFieldTest.php b/tests/phpunit/api/v3/CustomFieldTest.php index 9c4a61d405..0252bd18a6 100644 --- a/tests/phpunit/api/v3/CustomFieldTest.php +++ b/tests/phpunit/api/v3/CustomFieldTest.php @@ -46,10 +46,11 @@ class api_v3_CustomFieldTest extends CiviUnitTestCase { public function tearDown() { $tablesToTruncate = array( - 'civicrm_custom_group', - 'civicrm_custom_field', + 'civicrm_contact', + 'civicrm_file', + 'civicrm_entity_file', ); - // true tells quickCleanup to drop any tables that might have been created in the test + // true tells quickCleanup to drop custom_value tables that might have been created in the test $this->quickCleanup($tablesToTruncate, TRUE); } @@ -491,6 +492,43 @@ class api_v3_CustomFieldTest extends CiviUnitTestCase { } } + /** + * Test setting and getting a custom file field value. + * + * Uses the "attachment" api for setting value. + */ + public function testCustomFileField() { + $customGroup = $this->customGroupCreate(array('title' => 'attachment_test_group')); + $params = array( + 'custom_group_id' => $customGroup['id'], + 'name' => 'test_file_attachment', + 'label' => 'test_file_attachment', + 'html_type' => 'File', + 'data_type' => 'File', + 'is_active' => 1, + ); + $customField = $this->callAPISuccess('custom_field', 'create', $params); + $cfId = 'custom_' . $customField['id']; + + $cid = $this->individualCreate(); + + $attachment = $this->callAPISuccess('attachment', 'create', array( + 'name' => CRM_Utils_String::createRandom(5, CRM_Utils_String::ALPHANUMERIC) . '_testCustomFileField.txt', + 'mime_type' => 'text/plain', + 'content' => 'My test content', + 'field_name' => $cfId, + 'entity_id' => $cid, + )); + $this->assertAttachmentExistence(TRUE, $attachment); + + $result = $this->callAPISuccess('contact', 'getsingle', array( + 'id' => $cid, + 'return' => $cfId, + )); + + $this->assertEquals($attachment['id'], $result[$cfId]); + } + /** * @param $getFieldsResult *