Ejemplo n.º 1
0
 /**
  * @dataProvider providerCsvData
  */
 public function testGetCsvProperties($content_idx, $delimiter, $enclosure, $date, $time, $header)
 {
     $file = $GLOBALS['sugar_config']['tmp_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);
     $auto = new CsvAutoDetect($file);
     $del = $enc = $hasHeader = false;
     $ret = $auto->getCsvSettings($del, $enc);
     $this->assertEquals(true, $ret, 'Failed to parse and get csv properties');
     // delimiter
     $this->assertEquals($delimiter, $del, 'Incorrect delimiter');
     // enclosure
     $this->assertEquals($enclosure, $enc, 'Incorrect enclosure');
     // date format
     $date_format = $auto->getDateFormat();
     $this->assertEquals($date, $date_format, 'Incorrect date format');
     // time format
     $time_format = $auto->getTimeFormat();
     $this->assertEquals($time, $time_format, 'Incorrect time format');
     // header
     $ret = $auto->hasHeader($hasHeader, 'Contacts');
     $this->assertTrue($ret, 'Failed to detect header');
     $this->assertEquals($header, $hasHeader, 'Incorrect header');
     // remove temp file
     unlink($GLOBALS['sugar_config']['tmp_dir'] . 'test.csv');
 }
Ejemplo n.º 2
0
 /**
  * @ticket 45907
  */
 public function testCsvWithExtraInfo()
 {
     $sample_file = $GLOBALS['sugar_config']['upload_dir'] . '/Bug45907Test.csv';
     $file = 'tests/modules/Import/Bug45907Test.csv';
     copy($file, $sample_file);
     $auto = new CsvAutoDetect($file, 4);
     // parse only the first 4 lines
     $del = $enc = $hasHeader = false;
     // there is extra non csv info at the bottom of the file
     // but it should still parse ok because we only parse the first 4 lines
     $ret = $auto->getCsvSettings($del, $enc);
     $this->assertEquals(true, $ret, 'Failed to parse and get csv properties');
     // delimiter
     $this->assertEquals(',', $del, 'Incorrect delimiter');
     // enclosure
     $this->assertEquals('"', $enc, 'Incorrect enclosure');
     // header
     $ret = $auto->hasHeader($hasHeader, 'Accounts');
     $this->assertTrue($ret, 'Failed to detect header');
     $this->assertTrue($hasHeader, 'Incorrect header');
     // remove temp file
     unlink($sample_file);
 }