"\"3/26/2011 10:02am\",\"Doe\"", 1 => "\"2011-3-26 10:2 am\",\"Doe\"", 2 => "\"3.26.2011 10.02\",\"Doe\"", ); public function setUp() { $beanList = array(); $beanFiles = array(); require('include/modules.php'); $GLOBALS['beanList'] = $beanList; $GLOBALS['beanFiles'] = $beanFiles; $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser(); $this->_importModule = 'Contacts'; $this->_importObject = 'Contact'; } public function tearDown() { $GLOBALS['db']->query("DELETE FROM contacts where created_by='{$GLOBALS['current_user']->id}'"); SugarTestUserUtilities::removeAllCreatedAnonymousUsers(); } public function providerCsvData() { return array( array(0, '2011-03-26 10:02:00', 'm/d/Y', 'h:ia'), array(1, '2011-03-26 10:02:00', 'Y-m-d', 'h:ia'), array(2, '2011-03-26 10:02:00', 'm.d.Y', 'H.i'), ); } /** * @dataProvider providerCsvData */ public function testDateTimeImport($content_idx, $expected_datetime, $date_format, $time_format) { $file = $GLOBALS['sugar_config']['upload_dir'].'test.csv'; $ret = file_put_contents($file, self::$CsvContent[$content_idx]); $this->assertGreaterThan(0, $ret, 'Failed to write to '.$file .' for content '.$content_idx); $importSource = new ImportFile($file, ',', '"'); $bean = loadBean($this->_importModule); $_REQUEST['columncount'] = 2; $_REQUEST['colnum_0'] = 'date_entered'; $_REQUEST['colnum_1'] = 'last_name'; $_REQUEST['import_module'] = 'Contacts'; $_REQUEST['importlocale_charset'] = 'UTF-8'; $_REQUEST['importlocale_dateformat'] = $date_format; $_REQUEST['importlocale_timeformat'] = $time_format; $_REQUEST['importlocale_timezone'] = 'GMT'; $_REQUEST['importlocale_default_currency_significant_digits'] = '2'; $_REQUEST['importlocale_currency'] = '-99'; $_REQUEST['importlocale_dec_sep'] = '.'; $_REQUEST['importlocale_currency'] = '-99'; $_REQUEST['importlocale_default_locale_name_format'] = 's f l'; $_REQUEST['importlocale_num_grp_sep'] = ','; $importer = new Importer($importSource, $bean); $importer->import(); $query = "SELECT date_entered from contacts where created_by='{$GLOBALS['current_user']->id}'"; $result = $GLOBALS['db']->query($query); $row = $GLOBALS['db']->fetchByAssoc($result); $this->assertEquals($expected_datetime, $row['date_entered'], 'Got incorrect date_entered.'); } }