Merge branch 'wip-MDL-36365-master' of git://github.com/abgreeve/moodle

This commit is contained in:
Dan Poltawski
2012-11-07 14:09:25 +08:00
3 changed files with 25 additions and 1 deletions
+6 -1
View File
@@ -91,7 +91,12 @@ class csv_import_reader {
// Fix mac/dos newlines
$content = preg_replace('!\r\n?!', "\n", $content);
// Remove any spaces or new lines at the end of the file.
$content = trim($content);
if ($delimiter_name == 'tab') {
// trim() by default removes tabs from the end of content which is undesirable in a tab separated file.
$content = trim($content, chr(0x20) . chr(0x0A) . chr(0x0D) . chr(0x00) . chr(0x0B));
} else {
$content = trim($content);
}
$csv_delimiter = csv_import_reader::get_delimiter($delimiter_name);
// $csv_encode = csv_import_reader::get_encoded_delimiter($delimiter_name);
+13
View File
@@ -68,6 +68,7 @@ class csvclass_testcase extends advanced_testcase {
}
public function test_csv_functions() {
global $CFG;
$csvexport = new csv_export_writer();
$csvexport->set_filename('unittest');
foreach ($this->testdata as $data) {
@@ -113,5 +114,17 @@ class csvclass_testcase extends advanced_testcase {
$csvimport->cleanup();
$csvimport->close();
$this->assertEquals($importerror, $errortext);
// Testing for a tab separated file.
// The tab separated file has a trailing tab and extra blank lines at the end of the file.
$filename = $CFG->dirroot . '/lib/tests/fixtures/tabfile.csv';
$fp = fopen($filename, 'r');
$tabdata = fread($fp, filesize($filename));
fclose($fp);
$iid = csv_import_reader::get_new_iid('tab');
$csvimport = new csv_import_reader($iid, 'tab');
$contentcount = $csvimport->load_csv_content($tabdata, 'utf-8', 'tab');
// This should import four rows including the headings.
$this->assertEquals($contentcount, 4);
}
}
+6
View File
@@ -0,0 +1,6 @@
name url "Description of map" Grade
"George Fitz" "http://www.myblog.com" "This is a small map, that could be used in anything."
"Jim Brown" "http://www.blank.ne.jp" "Difficult to follow for the first five km.
Then things get easier." 1
"Tanya Keisel" "www.google.com" "No joke, it's just all burn't up. You can't ""understand"" any of it."
1 name url Description of map Grade
2 George Fitz http://www.myblog.com This is a small map, that could be used in anything.
3 Jim Brown http://www.blank.ne.jp Difficult to follow for the first five km. Then things get easier. 1
4 Tanya Keisel www.google.com No joke, it's just all burn't up. You can't "understand" any of it.