@@ 33-56 (lines=24) @@ | ||
30 | /** |
|
31 | * Does the importer correct CSV |
|
32 | */ |
|
33 | public function testLoad() |
|
34 | { |
|
35 | $loader = new CsvBulkLoader(Player::class); |
|
36 | $filepath = $this->csvPath . 'Player.csv'; |
|
37 | $file = fopen($filepath, 'r'); |
|
38 | $results = $loader->load($filepath); |
|
39 | ||
40 | $this->assertEquals( |
|
41 | 5, |
|
42 | $results->CreatedCount(), |
|
43 | 'Test correct count of imported data' |
|
44 | ); |
|
45 | ||
46 | $obj = DataObject::get_one( |
|
47 | Player::class, |
|
48 | [ "FirstName" => 'John' ] |
|
49 | ); |
|
50 | ||
51 | $this->assertNotNull($obj); |
|
52 | $this->assertEquals("He's a good guy", $obj->Biography); |
|
53 | $this->assertEquals("1988-01-31", $obj->Birthday); |
|
54 | $this->assertEquals("1", $obj->IsRegistered); |
|
55 | fclose($file); |
|
56 | } |
|
57 | ||
58 | /** |
|
59 | * Does the importer correct CSV when using a Field Label? |
|
@@ 61-84 (lines=24) @@ | ||
58 | /** |
|
59 | * Does the importer correct CSV when using a Field Label? |
|
60 | */ |
|
61 | public function testFieldLabel() |
|
62 | { |
|
63 | $loader = new CsvBulkLoader(Player::class); |
|
64 | $filepath = $this->csvPath . 'PlayerFieldLabel.csv'; |
|
65 | $file = fopen($filepath, 'r'); |
|
66 | $results = $loader->load($filepath); |
|
67 | ||
68 | $this->assertEquals( |
|
69 | 5, |
|
70 | $results->CreatedCount(), |
|
71 | 'Test correct count of imported data' |
|
72 | ); |
|
73 | ||
74 | $obj = DataObject::get_one( |
|
75 | Player::class, |
|
76 | [ "FirstName" => 'John' ] |
|
77 | ); |
|
78 | ||
79 | $this->assertNotNull($obj); |
|
80 | $this->assertEquals("He's a good guy", $obj->Biography); |
|
81 | $this->assertEquals("1988-01-31", $obj->Birthday); |
|
82 | $this->assertEquals("1", $obj->IsRegistered); |
|
83 | fclose($file); |
|
84 | } |
|
85 | ||
86 | /** |
|
87 | * Does the importer fail on a duplicate column? |