public function testAddFilesFromDirPattern() { // create files data for testing $testFileContentTpl = '<html><h1>Toto %s</h1></html>'; $testFileExt = 'html'; $testFileExtExcluded = 'php'; $testFiles = array($this->_getTmpFile('.' . $testFileExt, 'subdir1/') => array(), $this->_getTmpFile('.' . $testFileExt, 'subdir1/') => array(), $this->_getTmpFile('.' . $testFileExtExcluded, 'subdir1/') => array()); // create test files list and properties for checking foreach ($testFiles as $testFile => &$testFileData) { $testFileContent = sprintf($testFileContentTpl, $testFile); file_put_contents($testFile, $testFileContent); $testFileData = array('name' => '/' . basename($testFile), 'data' => $testFileContent, 'ext' => pathinfo($testFile, PATHINFO_EXTENSION), 'length' => mb_strlen($testFileContent)); $dirPath = dirname($testFile); } // create archive $archiveFilePath = $this->_getTmpFile('.tar'); $newArchive = BaseZF_Archive::newArchive('tar', $archiveFilePath); $newArchive->addFiles($dirPath . '/*.' . $testFileExt); $newArchive->createArchive(); // extract archive && test archive format detection $readArchive = BaseZF_Archive::extractArchive($archiveFilePath); // check file after extract $archiveFiles = $readArchive->getFiles(); // checking integrety of data and check file did no have testFileExtExcluded value foreach ($archiveFiles as $archiveFile => $archiveFileData) { $testFile = $testFiles[$dirPath . $archiveFileData['name']]; $this->assertEquals($archiveFileData['name'], $testFile['name']); // test file name extraction $this->assertEquals($archiveFileData['data'], $testFile['data']); // test file data extraction $this->assertEquals($archiveFileData['ext'], $testFile['ext']); // test file ext $this->assertNotEquals($archiveFileData['ext'], $testFileExtExcluded); // excluded file extentions $this->assertEquals($archiveFileData['stat'][7], $testFile['length']); // test file size } }
public function exportPoFiles(array $locales, array $domains = null, $archiveFormat = 'zip') { //@todo $domainsPaths = $this->getDomainsPaths($domains); // new archive $archive = BaseZF_Archive::newArchive($archiveFormat); $poDomainFiles = array(); foreach ($locales as $locale) { foreach ($domainsPaths as $domain => $paths) { $poDomainFile = $this->getPoFileForLocaleDomain($locale, $domain); $archive->addFile($poDomainFile, $locale . '/' . $domain . '.po'); } } // create and download $archive->createArchive(); $archive->setOption('path', 'export_language-' . date('dmY') . '-(' . implode('_', $locales) . ').zip'); $archive->downloadFile(); return $archive; }