Fixed bug with CsvBulkLoader

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@61136 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Saophalkun Ponlu 2008-08-20 04:01:41 +00:00
parent f6754178d9
commit cad9147916

View File

@ -20,14 +20,13 @@ class CsvBulkLoaderTest extends SapphireTest {
$results = $loader->load($filepath); $results = $loader->load($filepath);
// Test that right amount of columns was imported // Test that right amount of columns was imported
$this->assertEquals($results->Count(), $compareCount-1, 'Test correct count of imported data'); $this->assertEquals($results, $compareCount-1, 'Test correct count of imported data');
// Test that columns were correctly imported // Test that columns were correctly imported
$obj = DataObject::get_by_id('CsvBulkLoaderTest_Player', $results->First()->id); $obj = Dataobject::get_one("CsvBulkLoaderTest_Player", "FirstName = 'John'");
$this->assertEquals($compareRow[0], $obj->FirstName); $this->assertNotNull($obj);
$this->assertEquals($compareRow[1], $obj->Biography); $this->assertEquals("He's a good guy", $obj->Biography);
$date = DBField::create('Date', $compareRow[2])->RAW(); $this->assertEquals("1988-01-31", $obj->Birthday);
$this->assertEquals($date, $obj->Birthday);
fclose($file); fclose($file);
} }
@ -50,14 +49,13 @@ class CsvBulkLoaderTest extends SapphireTest {
$results = $loader->load($filepath); $results = $loader->load($filepath);
// Test that right amount of columns was imported // Test that right amount of columns was imported
$this->assertEquals($results->Count(), $compareCount, 'Test correct count of imported data'); $this->assertEquals($results, $compareCount, 'Test correct count of imported data');
// Test that columns were correctly imported // Test that columns were correctly imported
$obj = DataObject::get_by_id('CsvBulkLoaderTest_Player', $results->First()->id); $obj = Dataobject::get_one("CsvBulkLoaderTest_Player", "FirstName = 'John'");
$this->assertEquals($compareRow[0], $obj->FirstName); $this->assertNotNull($obj);
$this->assertEquals($compareRow[1], $obj->Biography); $this->assertEquals("He's a good guy", $obj->Biography);
$date = DBField::create('Date', $compareRow[3])->RAW(); $this->assertEquals("1988-01-31", $obj->Birthday);
$this->assertEquals($date, $obj->Birthday);
fclose($file); fclose($file);
} }
@ -91,7 +89,7 @@ class CsvBulkLoaderTest extends SapphireTest {
$results = $loader->load($filepath); $results = $loader->load($filepath);
// Test that right amount of columns was imported // Test that right amount of columns was imported
$this->assertEquals($results->Count(), $compareCount-1, 'Test correct count of imported data'); $this->assertEquals($results, $compareCount-1, 'Test correct count of imported data');
// Test of augumenting existing relation (created by fixture) // Test of augumenting existing relation (created by fixture)
$testTeam = DataObject::get_one('CsvBulkLoaderTest_Team', null, null, 'Created DESC'); $testTeam = DataObject::get_one('CsvBulkLoaderTest_Team', null, null, 'Created DESC');
@ -99,17 +97,13 @@ class CsvBulkLoaderTest extends SapphireTest {
// Test of creating relation // Test of creating relation
$testContract = DataObject::get_one('CsvBulkLoaderTest_PlayerContract'); $testContract = DataObject::get_one('CsvBulkLoaderTest_PlayerContract');
$testPlayer = DataObject::get_by_id('CsvBulkLoaderTest_Player', $results->First()->id); $testPlayer = Dataobject::get_one("CsvBulkLoaderTest_Player", "FirstName = 'John'");
$this->assertEquals($testPlayer->ContractID, $testContract->ID, 'Creating new has_one relation works'); $this->assertEquals($testPlayer->ContractID, $testContract->ID, 'Creating new has_one relation works');
// Test nested setting of relation properties // Test nested setting of relation properties
$contractAmount = DBField::create('Currency', $compareRow[5])->RAW(); $contractAmount = DBField::create('Currency', $compareRow[5])->RAW();
$testPlayer = DataObject::get_by_id('CsvBulkLoaderTest_Player', $results->First()->id);
$this->assertEquals($testPlayer->Contract()->Amount, $contractAmount, 'Setting nested values in a relation works'); $this->assertEquals($testPlayer->Contract()->Amount, $contractAmount, 'Setting nested values in a relation works');
// Test that columns were correctly imported
$obj = DataObject::get_by_id('CsvBulkLoaderTest_Player', $results->First()->id);
fclose($file); fclose($file);
} }