mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
Merge branch 'wip-MDL-36113-master' of git://github.com/abgreeve/moodle
Conflicts: lib/tests/csvclass_test.php
This commit is contained in:
commit
64f7d154db
@ -110,7 +110,15 @@ class csv_import_reader {
|
||||
// str_getcsv doesn't iterate through the csv data properly. It has
|
||||
// problems with line returns.
|
||||
while ($fgetdata = fgetcsv($fp, 0, $csv_delimiter, $enclosure)) {
|
||||
$columns[] = $fgetdata;
|
||||
// Check to see if we have an empty line.
|
||||
if (count($fgetdata) == 1) {
|
||||
if ($fgetdata[0] !== null) {
|
||||
// The element has data. Add it to the array.
|
||||
$columns[] = $fgetdata;
|
||||
}
|
||||
} else {
|
||||
$columns[] = $fgetdata;
|
||||
}
|
||||
}
|
||||
$col_count = 0;
|
||||
|
||||
|
@ -34,6 +34,7 @@ class csvclass_testcase extends advanced_testcase {
|
||||
var $teststring = '';
|
||||
var $teststring2 = '';
|
||||
var $teststring3 = '';
|
||||
var $teststring4 = '';
|
||||
|
||||
protected function setUp(){
|
||||
|
||||
@ -64,6 +65,16 @@ class csvclass_testcase extends advanced_testcase {
|
||||
$this->teststring2 = 'fullname,"description of things",beer
|
||||
"Fred Flint","<p>Find the stone inside the box</p>",Asahi,"A fourth column"
|
||||
"Sarah Smith","<p>How are the people next door?</p>,Yebisu,"Forget the next"
|
||||
';
|
||||
|
||||
$this->teststring4 = 'fullname,"description of things",beer
|
||||
"Douglas Dirk","<p>I am fine, thankyou.</p>",Becks
|
||||
|
||||
"Addelyn Francis","<p>Thanks for the cake</p>",Becks
|
||||
"Josh Frankson","<p>Everything is fine</p>",Asahi
|
||||
|
||||
|
||||
"Heath Forscyth","<p>We are going to make you lose your mind</p>",Fosters
|
||||
';
|
||||
}
|
||||
|
||||
@ -126,5 +137,12 @@ class csvclass_testcase extends advanced_testcase {
|
||||
$contentcount = $csvimport->load_csv_content($tabdata, 'utf-8', 'tab');
|
||||
// This should import four rows including the headings.
|
||||
$this->assertEquals($contentcount, 4);
|
||||
|
||||
// Testing for empty lines.
|
||||
$iid = csv_import_reader::get_new_iid('blanklines');
|
||||
$csvimport = new csv_import_reader($iid, 'blanklines');
|
||||
$contentcount = $csvimport->load_csv_content($this->teststring4, 'utf-8', 'comma');
|
||||
// Five lines including the headings should be imported.
|
||||
$this->assertEquals($contentcount, 5);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user