function testShouldExport() { $csv = "sku,name,active\n"; $csv .= "123,name1,1\n"; $csv .= "456,name2,0"; $importer = new Importer($this->db); $importer->importFromText($csv); $exporter = new Exporter($this->db); $text = $exporter->exportToText(); $this->assertEquals($csv, $text); }
function testShouldUseBatchQuery() { $profiler = $this->db->getProfiler(); $queryProfiles = $profiler->getQueryProfiles(); $beforeCount = count($queryProfiles); $csv = $this->generateCSV(100); $importer = new Importer($this->db); $importer->importFromText($csv); $queryProfiles = $profiler->getQueryProfiles(); $afterCount = count($queryProfiles); $this->assertLessThanOrEqual(15, $afterCount - $beforeCount, 'should use <=15 queries to import >=100 products'); }
function testShouldNotCreateDuplicateCategory() { $categoryMapper = new \Metator\Category\DataMapper($this->db); $id = $categoryMapper->save(['name' => 'test']); $csv = "sku,name,base_price,attributes,categories\n"; $csv .= '123,name,0,null,test'; $importer = new Importer($this->db); $importer->importFromText($csv); $categoryMapper = new \Metator\Category\DataMapper($this->db); $categories = $categoryMapper->findAll(); $this->assertEquals(1, count($categories), 'should not create duplicate categories'); }
function create($products, $categories) { $colors = ['red', 'blue', 'green']; $sizes = ['small', 'medium', 'large']; $csv = "sku,active,name,attributes,categories\n"; for ($i = 0; $i < $products; $i++) { $attributes = array(); if (rand(1, 2) == 1) { $attributes['size'] = $sizes[rand(0, 2)]; } if (rand(1, 2) == 1) { $attributes['color'] = $colors[rand(0, 2)]; } $attributes = \Zend\Json\Json::encode($attributes); $attributes = str_replace('"', '\\"', $attributes); $category = rand(1, $categories); $csv .= "sku-{$i},1,name-{$i},\"{$attributes}\",category-{$category}\n"; } $db = $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter'); $importer = new Importer($db); $importer->importFromText($csv); }
function testShouldUpdateNameOnReimport() { $csv = "sku,name\n"; $csv .= "123,name"; $importer = new Importer($this->db); $importer->importFromText($csv); $csv = "sku,name\n"; $csv .= "123,name-new"; $importer = new Importer($this->db); $importer->importFromText($csv); $products = $this->productDataMapper()->find(); $this->assertEquals('name-new', $products[0]->getName(), 'should update values on re-import'); }