From: Eileen McNaughton Date: Tue, 12 Apr 2016 06:30:15 +0000 (+1200) Subject: CRM-17859 unit test (#8113) X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=6827f128b2da042a68c40a43d8c3ffc6187757bf;p=civicrm-core.git CRM-17859 unit test (#8113) --- diff --git a/tests/phpunit/CRM/Import/DataSource/CsvTest.php b/tests/phpunit/CRM/Import/DataSource/CsvTest.php new file mode 100644 index 0000000000..510bca4a81 --- /dev/null +++ b/tests/phpunit/CRM/Import/DataSource/CsvTest.php @@ -0,0 +1,78 @@ + array( + 'name' => __DIR__ . '/' . $fileName, + ), + 'skipColumnHeader' => TRUE, + ); + + // Get the PEAR::DB object + $dao = new CRM_Core_DAO(); + $db = $dao->getDatabaseConnection(); + + $form = new CRM_Contact_Import_Form_DataSource(); + $form->controller = new CRM_Contact_Import_Controller(); + + $dataSource->postProcess($params, $db, $form); + $tableName = $form->get('importTableName'); + $this->assertEquals(4, + CRM_Core_DAO::singleValueQuery("SELECT LENGTH(last_name) FROM $tableName"), + $fileName . ' failed on last_name' + ); + $this->assertEquals(21, + CRM_Core_DAO::singleValueQuery("SELECT LENGTH(email) FROM $tableName"), + $fileName . ' failed on email' + ); + CRM_Core_DAO::executeQuery("DROP TABLE $tableName"); + } + + /** + * Get csv files to test. + * + * @return array + */ + public function getCsvFiles() { + return array(array('import.csv'), array('yogi.csv')); + } + +} diff --git a/tests/phpunit/CRM/Import/DataSource/import.csv b/tests/phpunit/CRM/Import/DataSource/import.csv new file mode 100644 index 0000000000..8786d6a211 --- /dev/null +++ b/tests/phpunit/CRM/Import/DataSource/import.csv @@ -0,0 +1,2 @@ +First Name,Last Name,email +Yogi,Bear ,yogi@yellowstone.park  diff --git a/tests/phpunit/CRM/Import/DataSource/yogi.csv b/tests/phpunit/CRM/Import/DataSource/yogi.csv new file mode 100644 index 0000000000..a8ccf3f832 --- /dev/null +++ b/tests/phpunit/CRM/Import/DataSource/yogi.csv @@ -0,0 +1,2 @@ +Last Name,email,First Name +Bear ,yogi@yellowstone.park ,Yogi