Merge pull request #17320 from totten/master-url-type
[civicrm-core.git] / tests / phpunit / CRM / Import / DataSource / CsvTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * Tests for the CRM_Import_Datasource_Csv class.
14 */
15 class CRM_Import_DataSource_CsvTest extends CiviUnitTestCase {
16
17 /**
18 * Test the to csv function.
19 *
20 * @param string $fileName
21 *
22 * @dataProvider getCsvFiles
23 */
24 public function testToCsv($fileName) {
25 $dataSource = new CRM_Import_DataSource_CSV();
26 $params = [
27 'uploadFile' => [
28 'name' => __DIR__ . '/' . $fileName,
29 ],
30 'skipColumnHeader' => TRUE,
31 ];
32
33 // Get the PEAR::DB object
34 $dao = new CRM_Core_DAO();
35 $db = $dao->getDatabaseConnection();
36
37 $form = new CRM_Contact_Import_Form_DataSource();
38 $form->controller = new CRM_Contact_Import_Controller();
39
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'
45 );
46 $this->assertEquals(21,
47 CRM_Core_DAO::singleValueQuery("SELECT LENGTH(email) FROM $tableName"),
48 $fileName . ' failed on email'
49 );
50 CRM_Core_DAO::executeQuery("DROP TABLE $tableName");
51 }
52
53 /**
54 * Get csv files to test.
55 *
56 * @return array
57 */
58 public function getCsvFiles() {
59 return [['import.csv'], ['yogi.csv']];
60 }
61
62 }