. /** * Tests csv import and export functions * * @package core * @category phpunit * @copyright 2012 Adrian Greeve * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); global $CFG; require_once($CFG->dirroot . '/lib/csvlib.class.php'); class csvclass_testcase extends advanced_testcase { var $testdata = array(); var $teststring = ''; protected function setUp(){ $this->resetAfterTest(true); $csvdata = array(); $csvdata[0][] = 'fullname'; $csvdata[0][] = 'description of things'; $csvdata[0][] = 'beer'; $csvdata[1][] = 'William B Stacey'; $csvdata[1][] = '

A field that contains "double quotes"

'; $csvdata[1][] = 'Asahi'; $csvdata[2][] = 'Phillip Jenkins'; $csvdata[2][] = '

This field has

Multiple lines

and also contains "double quotes"

'; $csvdata[2][] = 'Yebisu'; $this->testdata = $csvdata; // Please note that each line needs a carriage return. $this->teststring = 'fullname,"description of things",beer "William B Stacey","

A field that contains ""double quotes""

",Asahi "Phillip Jenkins","

This field has

Multiple lines

and also contains ""double quotes""

",Yebisu '; } public function test_csv_functions() { $csvexport = new csv_export_writer(); $csvexport->set_filename('unittest'); foreach ($this->testdata as $data) { $csvexport->add_data($data); } $csvoutput = $csvexport->print_csv_data(true); $this->assertEquals($csvoutput, $this->teststring); $test_data = csv_export_writer::print_array($this->testdata, 'comma', '"', true); $this->assertEquals($test_data, $this->teststring); } }