public function testReportsExport() { $pid = Helper::getSomeProject(); Helper::initProjectModel($pid); // Create few MB csv $csvFile = Helper::getTemp()->createTmpFile(); $fp = fopen($csvFile, 'w'); fwrite($fp, "id,name" . PHP_EOL); for ($i = 1; $i < 200000; $i++) { fwrite($fp, "{$i}," . uniqid() . PHP_EOL); } shell_exec("mv {$csvFile} " . Helper::getTemp()->getTmpFolder() . "/categories.csv"); fclose($fp); $dirName = uniqid(); $webDav = new WebDav(KBGDC_USERNAME, KBGDC_PASSWORD); $webDav->createFolder($dirName); $webDav->upload(__DIR__ . '/../../data/products.csv', $dirName); $webDav->upload(Helper::getTemp()->getTmpFolder() . "/categories.csv", $dirName); $webDav->upload(__DIR__ . '/../../data/upload_info.json', $dirName); Helper::getClient()->getDatasets()->loadData($pid, $dirName); $uri = Helper::createReport($pid); $report = Helper::getClient()->get($uri); $reports = new Reports($this->client); $resultUri = $reports->export($pid, $report['report']['content']['definitions'][0]); $csvFile = Helper::getTemp()->getTmpFolder() . '/' . uniqid() . '.csv'; $this->client->getToFile($resultUri, $csvFile); $this->assertTrue(file_exists($csvFile)); $this->assertGreaterThan(4800000, filesize($csvFile)); }
public static function loadData($pid) { $dirName = uniqid(); $webDav = new WebDav(KBGDC_USERNAME, KBGDC_PASSWORD); $webDav->createFolder($dirName); $webDav->upload(__DIR__ . '/data/categories.csv', $dirName); $webDav->upload(__DIR__ . '/data/products.csv', $dirName); $webDav->upload(__DIR__ . '/data/upload_info.json', $dirName); $file = sys_get_temp_dir() . "/" . uniqid() . "-file.log"; $webDav->saveLogs($dirName, $file); if (file_exists($file)) { echo file_get_contents($file) . PHP_EOL . PHP_EOL; } self::getClient()->getDatasets()->loadData($pid, $dirName); }
public function testDatasetsLoadData() { $pid = Helper::getSomeProject(); Helper::initProjectModel($pid); Helper::loadData($pid); $timestamp = time(); $dirName = uniqid(); $webDav = new WebDav(KBGDC_USERNAME, KBGDC_PASSWORD); $webDav->createFolder($dirName); $webDav->upload(__DIR__ . '/../../data/categories.csv', $dirName); $webDav->upload(__DIR__ . '/../../data/products.csv', $dirName); $webDav->upload(__DIR__ . '/../../data/upload_info.json', $dirName); $this->client->getDatasets()->loadData($pid, $dirName); $result = $this->client->get("/gdc/md/{$pid}/data/sets"); $categoriesFound = false; $productsFound = false; foreach ($result['dataSetsInfo']['sets'] as $d) { if ($d['meta']['title'] == 'Categories') { $categoriesFound = true; $this->assertGreaterThan($timestamp, strtotime($d['lastUpload']['dataUploadShort']['date'])); } if ($d['meta']['title'] == 'Products') { $productsFound = true; $this->assertGreaterThan($timestamp, strtotime($d['lastUpload']['dataUploadShort']['date'])); } } $this->assertTrue($categoriesFound); $this->assertTrue($productsFound); }