Skip to content

Commit

Permalink
Merge branch 'wip-MDL-36113-master' of git://github.com/abgreeve/moodle
Browse files Browse the repository at this point in the history
Conflicts:
	lib/tests/csvclass_test.php
  • Loading branch information
danpoltawski committed Nov 7, 2012
2 parents defcb76 + 13041f2 commit 64f7d15
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/csvlib.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,15 @@ function load_csv_content(&$content, $encoding, $delimiter_name, $column_validat
// 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;

Expand Down
18 changes: 18 additions & 0 deletions lib/tests/csvclass_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class csvclass_testcase extends advanced_testcase {
var $teststring = '';
var $teststring2 = '';
var $teststring3 = '';
var $teststring4 = '';

protected function setUp(){

Expand Down Expand Up @@ -64,6 +65,16 @@ protected function setUp(){
$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
';
}

Expand Down Expand Up @@ -126,5 +137,12 @@ public function test_csv_functions() {
$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);
}
}

0 comments on commit 64f7d15

Please sign in to comment.