3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * Tests for the CRM_Import_Datasource_Csv class.
15 class CRM_Import_DataSource_CsvTest
extends CiviUnitTestCase
{
18 * Test the to csv function.
20 * @param string $fileName
22 * @dataProvider getCsvFiles
24 public function testToCsv($fileName) {
25 $dataSource = new CRM_Import_DataSource_CSV();
28 'name' => __DIR__
. '/' . $fileName,
30 'skipColumnHeader' => TRUE,
33 // Get the PEAR::DB object
34 $dao = new CRM_Core_DAO();
35 $db = $dao->getDatabaseConnection();
37 $form = new CRM_Contact_Import_Form_DataSource();
38 $form->controller
= new CRM_Contact_Import_Controller();
40 $dataSource->postProcess($params, $db, $form);
41 $tableName = $form->get('importTableName');
42 $this->assertEquals(4,
43 CRM_Core_DAO
::singleValueQuery("SELECT LENGTH(last_name) FROM $tableName"),
44 $fileName . ' failed on last_name'
46 $this->assertEquals(21,
47 CRM_Core_DAO
::singleValueQuery("SELECT LENGTH(email) FROM $tableName"),
48 $fileName . ' failed on email'
50 CRM_Core_DAO
::executeQuery("DROP TABLE $tableName");
54 * Get csv files to test.
58 public function getCsvFiles() {
59 return [['import.csv'], ['yogi.csv']];