@@ 61-84 (lines=24) @@ | ||
58 | /** |
|
59 | * Does the importer fail on a duplicate column? |
|
60 | */ |
|
61 | public function testDuplicateColumn() |
|
62 | { |
|
63 | // Remove any existing records |
|
64 | Player::get()->removeAll(); |
|
65 | ||
66 | $loader = new CsvBulkLoader(Player::class); |
|
67 | $filepath = $this->csvPath . 'PlayerDuplicate.csv'; |
|
68 | $file = fopen($filepath, 'r'); |
|
69 | $results = $loader->load($filepath); |
|
70 | ||
71 | $this->assertEquals( |
|
72 | 1, |
|
73 | $results->ErrorCount(), |
|
74 | 'Test error count on duplicates' |
|
75 | ); |
|
76 | ||
77 | $obj = DataObject::get_one( |
|
78 | Player::class, |
|
79 | [ "FirstName" => 'John' ] |
|
80 | ); |
|
81 | ||
82 | $this->assertNull($obj); |
|
83 | fclose($file); |
|
84 | } |
|
85 | ||
86 | /** |
|
87 | * Does the importer fail on a duplicate column |
|
@@ 89-112 (lines=24) @@ | ||
86 | /** |
|
87 | * Does the importer fail on a duplicate column |
|
88 | */ |
|
89 | public function testMissingRequired() |
|
90 | { |
|
91 | // Remove any existing records |
|
92 | Player::get()->removeAll(); |
|
93 | ||
94 | $loader = new CsvBulkLoader(Player::class); |
|
95 | $filepath = $this->csvPath . 'PlayerMissingRequired.csv'; |
|
96 | $file = fopen($filepath, 'r'); |
|
97 | $results = $loader->load($filepath); |
|
98 | ||
99 | $this->assertEquals( |
|
100 | 1, |
|
101 | $results->ErrorCount(), |
|
102 | 'Test errors generated when required fields missing' |
|
103 | ); |
|
104 | ||
105 | $obj = DataObject::get_one( |
|
106 | Player::class, |
|
107 | ["FirstName" => 'Jane'] |
|
108 | ); |
|
109 | ||
110 | $this->assertNull($obj); |
|
111 | fclose($file); |
|
112 | } |
|
113 | } |
|
114 |