예제 #1
0
 public function testCreateFileWorks()
 {
     $csvPath = __DIR__ . "/Export/test.csv";
     $activeIds = array("430", "431", "432");
     $separator = ";";
     $csvCatMapper = new CsvCategoryMapper($this->dataProvider, $activeIds, $csvPath, $separator);
     $csvCatMapper->createFile();
     $this->assertFileExists($csvPath);
     $csvFile = new CsvFile($csvPath, $separator);
     $csvLines = $csvFile->getAll();
     $this->assertEquals(count($activeIds), count($csvLines));
     $this->assertEquals("0", $csvLines[0]->tri);
     $this->assertEquals("430", $csvLines[0]->id);
     $this->assertEquals("Blu-ray", $csvLines[0]->cat0);
     $this->assertEquals("BD-R", $csvLines[0]->cat1);
     $this->assertEquals("BD-R 25 Go", $csvLines[0]->cat2);
     $this->assertEquals("", $csvLines[0]->cat3);
     $this->assertEquals("", $csvLines[0]->cat4);
     $this->assertEquals("1", $csvLines[1]->tri);
     $this->assertEquals("432", $csvLines[1]->id);
     $this->assertEquals("Blu-ray", $csvLines[1]->cat0);
     $this->assertEquals("BD-R", $csvLines[1]->cat1);
     $this->assertEquals("BD-R 8 cm", $csvLines[1]->cat2);
     $this->assertEquals("", $csvLines[1]->cat3);
     $this->assertEquals("", $csvLines[1]->cat4);
     $this->assertEquals("2", $csvLines[2]->tri);
     $this->assertEquals("431", $csvLines[2]->id);
     $this->assertEquals("Blu-ray", $csvLines[2]->cat0);
     $this->assertEquals("BD-R", $csvLines[2]->cat1);
     $this->assertEquals("BD-R DL 50 Go", $csvLines[2]->cat2);
     $this->assertEquals("", $csvLines[2]->cat3);
     $this->assertEquals("", $csvLines[2]->cat4);
 }
예제 #2
0
 public function getAll()
 {
     if (($csvFileTemp = @fopen($this->productsCsvUrl, "r")) === false) {
         throw new \InvalidArgumentException("cannot open CSV file <{$this->productsCsvUrl}>");
     }
     if (@file_put_contents($this->intermediateCsvFile, $csvFileTemp) === false) {
         throw new \InvalidArgumentException("cannot save to <{$this->intermediateCsvFile}>");
     }
     $csvFile = new CsvFile($this->intermediateCsvFile, "\t");
     return $csvFile->getAll();
 }
 public function testPrepareData()
 {
     $dataProvider = new ProductsFeedDataProvider($this->db, $this->okChannel->getLanguageId(), __DIR__ . "/Data/okProducts.csv", __DIR__ . "/Data/savedCsv.csv", $this->logger);
     $dataProvider->prepareData();
     $okProducts = $dataProvider->getOkProducts();
     $csvFile = new CsvFile(__DIR__ . "/Data/okProducts.csv", ";");
     $csvLines = $csvFile->getAll();
     $this->assertEquals(count($csvLines) - 1, count($okProducts));
     $okManufacturers = $dataProvider->getOkManufacturers();
     $this->assertEquals(2, count($okManufacturers));
 }
예제 #4
0
 protected function setUp()
 {
     $this->db = TestsHelpers::getDb();
     //$this->db->setVerboseMode();
     $this->iniParams = TestsHelpers::getIniParams();
     $this->idPrefix = $this->iniParams->get("idPrefix");
     $this->okChannel = new OkChannel($this->iniParams->get("channelId"), $this->db);
     $this->logger = LoggerFactory::getFileLogger(TestsHelpers::getUserLog(), Logger::WARNING);
     TestsHelpers::cleanAllLogs();
     $csvFile = new CsvFile(__DIR__ . "/Data/okProducts.csv", "\t");
     $this->okProductsUpdatesArray = $csvFile->getAll();
     array_splice($this->okProductsUpdatesArray, 10);
     $this->xmlExporter = new ProductsUpdates($this->iniParams, $this->okProductsUpdatesArray, $this->logger);
     $this->fileName = __DIR__ . "/Data/Exports/ProductsUpdates.xml";
     if (file_exists($this->fileName)) {
         unlink($this->fileName);
     }
 }
예제 #5
0
 private function getOkProducts($productsCsvUrl, $limit = 50)
 {
     $csvFile = new CsvFile($productsCsvUrl, "\t");
     $this->okProductsArray = $csvFile->getAll();
     array_splice($this->okProductsArray, $limit);
     $this->okProductsArray = Encoding::toPrintableAscii($this->okProductsArray);
     return $this->okProductsArray;
 }
예제 #6
0
// =========== Variables ===========
// Pour limiter l'export aux catégories présentes dans un fichier flux CSV, indiquer ici son emplacement / URL
//$activeCatsCsvFilePath 	= "feeds/BfWork/client-2014-11-24_16-47.csv";
//$exportFilePath 		= __DIR__ . "/Export/ClientActiveCats.csv";
// Sinon, utiliser les variables ci-dessous
$activeCatsCsvFilePath = "";
$exportFilePath = __DIR__ . "/Export/ClientCatMapping.csv";
// =========== Setup context ===========
require 'bootstrap.php';
$argv = $GLOBALS["argv"];
$cliParams = new CliParams();
$cliParams->parse($argv);
$iniParams = new IniParams($cliParams->getConfigFilePath());
$logger = LoggerFactory::getNullLogger();
$db = new Db($iniParams->get("dbHostReadOnly"), $iniParams->get("dbNameReadOnly"), $iniParams->get("dbUserReadOnly"), $iniParams->get("dbPassReadOnly"), $logger);
// =========== Get active cat list from CSV ===========
$activeCatsIds = array();
if ($activeCatsCsvFilePath !== "") {
    $csvFile = new CsvFile($activeCatsCsvFilePath, "\t");
    $activeCatsIds = array();
    foreach ($csvFile->getAll() as $csvLine) {
        $activeCatsIds[] = $csvLine->categories_categories_id;
    }
    $activeCatsIds = array_unique($activeCatsIds);
}
// =========== Get and process categories, then create CSV ===========
$okCategoriesDataProvider = new OkCategoriesDataProvider($db, 1);
// 1 = français
$csvCatMapper = new CsvCategoryMapper($okCategoriesDataProvider, $activeCatsIds, $exportFilePath, "\t");
$csvCatMapper->createFile();
// @codeCoverageIgnoreEnd
 private function getOkProductsUpdates($limit = 50)
 {
     $productsCsvUrl = E7_PATH . "/tests/E7/ConnectorsSets/OkToBf/Data/okProducts.csv";
     $csvFile = new CsvFile($productsCsvUrl, "\t");
     $this->okProductsArray = $csvFile->getAll();
     array_splice($this->okProductsArray, $limit);
     $this->okProductsArray = Encoding::toPrintableAscii($this->okProductsArray);
     return $this->okProductsArray;
 }