1 | <?php |
||||
2 | |||||
3 | namespace SilverShop\Tests\Admin; |
||||
4 | |||||
5 | use SilverShop\Admin\ProductBulkLoader; |
||||
6 | use SilverShop\Page\Product; |
||||
7 | use SilverStripe\Dev\FunctionalTest; |
||||
8 | |||||
9 | class ProductBulkLoaderTest extends FunctionalTest |
||||
10 | { |
||||
11 | public static $fixture_file = __DIR__ . '/../Fixtures/shop.yml'; |
||||
12 | public static $disable_theme = true; |
||||
13 | protected static $use_draft_site = true; |
||||
14 | |||||
15 | public function testLoad() |
||||
16 | { |
||||
17 | $loader = new ProductBulkLoader(Product::class); |
||||
18 | |||||
19 | $ds = DIRECTORY_SEPARATOR; |
||||
20 | $filepath = realpath(__DIR__ . $ds . 'test_products.csv'); |
||||
21 | $file = fopen($filepath, 'r'); |
||||
22 | |||||
23 | fgetcsv($file); // pop header row |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
24 | $compareRow = fgetcsv($file); |
||||
0 ignored issues
–
show
|
|||||
25 | $results = $loader->load($filepath); |
||||
0 ignored issues
–
show
|
|||||
26 | |||||
27 | // Test that right amount of columns was imported |
||||
28 | //$this->assertEquals(4, $results->Count(), 'Test correct count of imported data'); |
||||
29 | |||||
30 | // Test that columns were correctly imported |
||||
31 | $obj = Product::get()->filter('Title', 'Socks')->first(); |
||||
32 | $this->assertNotNull($obj, "New product exists"); |
||||
33 | $this->assertEquals("<p>The comfiest pair of socks you'll ever own.</p>", $obj->Content, "Content matches"); |
||||
34 | $this->assertEquals(12, $obj->BasePrice, "Checking price matches."); |
||||
35 | //$this->assertEquals(124, $obj->ID,"Checking ID matches"); |
||||
36 | |||||
37 | fclose($file); |
||||
0 ignored issues
–
show
It seems like
$file can also be of type false ; however, parameter $handle of fclose() does only seem to accept resource , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
38 | |||||
39 | $this->markTestIncomplete('Incomplete'); |
||||
40 | } |
||||
41 | } |
||||
42 |