From 6827f128b2da042a68c40a43d8c3ffc6187757bf Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 12 Apr 2016 18:30:15 +1200 Subject: [PATCH] CRM-17859 unit test (#8113) --- .../phpunit/CRM/Import/DataSource/CsvTest.php | 78 +++++++++++++++++++ .../phpunit/CRM/Import/DataSource/import.csv | 2 + tests/phpunit/CRM/Import/DataSource/yogi.csv | 2 + 3 files changed, 82 insertions(+) create mode 100644 tests/phpunit/CRM/Import/DataSource/CsvTest.php create mode 100644 tests/phpunit/CRM/Import/DataSource/import.csv create mode 100644 tests/phpunit/CRM/Import/DataSource/yogi.csv 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 -- 2.25.1