Ejemplo n.º 1
0
 public function updateWorksheet(File $file)
 {
     $csvFile = new CsvFile($file->getPathname());
     $colCount = $csvFile->getColumnsCount();
     $rowCount = $this->countLines($csvFile);
     $worksheetsFeedXml = $this->getWorksheetsFeed($file->getGoogleId(), false);
     $crawler = new Crawler($worksheetsFeedXml);
     $entryIds = $crawler->filter('default|entry default|id');
     $entryXml = "";
     /** @var \DOMElement $eid */
     foreach ($entryIds as $eid) {
         if (strstr($eid->nodeValue, $file->getSheetId()) !== false) {
             $entry = $eid->parentNode;
             $entryXml = $entry->ownerDocument->saveXML($entry);
             break;
         }
     }
     // update colCount and rowCount
     $entryXml = preg_replace('/\\<gs\\:colCount\\>.*\\<\\/gs\\:colCount\\>/', '<gs:colCount>' . $colCount . '</gs:colCount>', $entryXml);
     $entryXml = preg_replace('/\\<gs\\:rowCount\\>.*\\<\\/gs\\:rowCount\\>/', '<gs:rowCount>' . $rowCount . '</gs:rowCount>', $entryXml);
     $entryXml = "<?xml version='1.0' encoding='UTF-8'?>" . PHP_EOL . preg_replace('/\\<entry.*\\>\\<id\\>/', "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gs='http://schemas.google.com/spreadsheets/2006'><id>", $entryXml);
     return $this->api->request(sprintf(self::SPREADSHEET_WORKSHEETS . '/%s/private/full/%s', $file->getGoogleId(), $file->getSheetId()), 'PUT', ['Accept' => 'application/atom+xml', 'Content-Type' => 'application/atom+xml', 'GData-Version' => '3.0', 'If-Match' => '*'], ['body' => $entryXml]);
 }
Ejemplo n.º 2
0
 public function testNoCache()
 {
     $filePath = './tests/data/noCache/out/tables/getPost.get';
     // first execution
     $output = shell_exec('php ./run.php --data=./tests/data/noCache');
     self::assertEquals('Extractor finished successfully.' . PHP_EOL, $output);
     $this->assertFileExists($filePath);
     $csv = new CsvFile($filePath);
     $this->assertEquals(1, $csv->getColumnsCount());
     $csv->next();
     $data = $csv->current();
     unset($csv);
     $firstDateTime = new \DateTime($data[0]);
     $this->rmDir('./tests/data/noCache/out');
     sleep(3);
     // second execution
     $output = shell_exec('php ./run.php --data=./tests/data/noCache');
     self::assertEquals('Extractor finished successfully.' . PHP_EOL, $output);
     $this->assertFileExists($filePath);
     $csv = new CsvFile($filePath);
     $this->assertEquals(1, $csv->getColumnsCount());
     $csv->next();
     $data = $csv->current();
     unset($csv);
     $secondDateTime = new \DateTime($data[0]);
     $this->assertTrue($firstDateTime < $secondDateTime);
     $this->rmDir('./tests/data/noCache/out');
 }
Ejemplo n.º 3
0
 public function testColumnsCount()
 {
     $csv = new CsvFile(__DIR__ . '/_data/test-input.csv');
     $this->assertEquals(9, $csv->getColumnsCount());
 }