Commit | Line | Data |
---|---|---|
6827f128 EM |
1 | <?php |
2 | /* | |
7d61e75f TO |
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 | +--------------------------------------------------------------------+ | |
6827f128 EM |
10 | */ |
11 | ||
12 | /** | |
13 | * Tests for the CRM_Import_Datasource_Csv class. | |
14 | */ | |
6a7ec119 | 15 | class CRM_Import_DataSource_CsvTest extends CiviUnitTestCase { |
6827f128 EM |
16 | |
17 | /** | |
18 | * Test the to csv function. | |
19 | * | |
20 | * @param string $fileName | |
21 | * | |
22 | * @dataProvider getCsvFiles | |
23 | */ | |
24 | public function testToCsv($fileName) { | |
3aa9d6ce | 25 | $dataSource = new CRM_Import_DataSource_CSV(); |
9099cab3 CW |
26 | $params = [ |
27 | 'uploadFile' => [ | |
6827f128 | 28 | 'name' => __DIR__ . '/' . $fileName, |
9099cab3 | 29 | ], |
6827f128 | 30 | 'skipColumnHeader' => TRUE, |
9099cab3 | 31 | ]; |
6827f128 EM |
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() { | |
9099cab3 | 59 | return [['import.csv'], ['yogi.csv']]; |
6827f128 EM |
60 | } |
61 | ||
62 | } |