make archive test cases work again

This commit is contained in:
Robin Appelman 2012-10-05 22:24:36 +02:00
parent a53999e94e
commit c4c8dd4e3a
3 changed files with 31 additions and 39 deletions

View File

@ -22,46 +22,46 @@ abstract class Test_Archive extends UnitTestCase {
* @return OC_Archive
*/
abstract protected function getNew();
public function testGetFiles() {
$this->instance=$this->getExisting();
$allFiles=$this->instance->getFiles();
$expected=array('lorem.txt','logo-wide.png','dir/','dir/lorem.txt');
$this->assertEqual(4,count($allFiles),'only found '.count($allFiles).' out of 4 expected files');
foreach($expected as $file) {
$this->assertNotIdentical(false,array_search($file,$allFiles),'cant find '.$file.' in archive');
$this->assertContains($file, $allFiles, 'cant find '. $file . ' in archive');
$this->assertTrue($this->instance->fileExists($file),'file '.$file.' does not exist in archive');
}
$this->assertFalse($this->instance->fileExists('non/existing/file'));
$rootContent=$this->instance->getFolder('');
$expected=array('lorem.txt','logo-wide.png','dir/');
$this->assertEqual(3,count($rootContent));
foreach($expected as $file) {
$this->assertNotIdentical(false,array_search($file,$rootContent),'cant find '.$file.' in archive');
$this->assertContains($file, $rootContent, 'cant find '. $file . ' in archive');
}
$dirContent=$this->instance->getFolder('dir/');
$expected=array('lorem.txt');
$this->assertEqual(1,count($dirContent));
foreach($expected as $file) {
$this->assertNotIdentical(false,array_search($file,$dirContent),'cant find '.$file.' in archive');
$this->assertContains($file, $dirContent, 'cant find '. $file . ' in archive');
}
}
public function testContent() {
$this->instance=$this->getExisting();
$dir=OC::$SERVERROOT.'/apps/files_archive/tests/data';
$dir=OC::$SERVERROOT.'/tests/data';
$textFile=$dir.'/lorem.txt';
$this->assertEqual(file_get_contents($textFile),$this->instance->getFile('lorem.txt'));
$tmpFile=OCP\Files::tmpFile('.txt');
$this->instance->extractFile('lorem.txt',$tmpFile);
$this->assertEqual(file_get_contents($textFile),file_get_contents($tmpFile));
}
public function testWrite() {
$dir=OC::$SERVERROOT.'/apps/files_archive/tests/data';
$dir=OC::$SERVERROOT.'/tests/data';
$textFile=$dir.'/lorem.txt';
$this->instance=$this->getNew();
$this->assertEqual(0,count($this->instance->getFiles()));
@ -69,14 +69,14 @@ abstract class Test_Archive extends UnitTestCase {
$this->assertEqual(1,count($this->instance->getFiles()));
$this->assertTrue($this->instance->fileExists('lorem.txt'));
$this->assertFalse($this->instance->fileExists('lorem.txt/'));
$this->assertEqual(file_get_contents($textFile),$this->instance->getFile('lorem.txt'));
$this->instance->addFile('lorem.txt','foobar');
$this->assertEqual('foobar',$this->instance->getFile('lorem.txt'));
}
public function testReadStream() {
$dir=OC::$SERVERROOT.'/apps/files_archive/tests/data';
$dir=OC::$SERVERROOT.'/tests/data';
$this->instance=$this->getExisting();
$fh=$this->instance->getStream('lorem.txt','r');
$this->assertTrue($fh);
@ -85,7 +85,7 @@ abstract class Test_Archive extends UnitTestCase {
$this->assertEqual(file_get_contents($dir.'/lorem.txt'),$content);
}
public function testWriteStream() {
$dir=OC::$SERVERROOT.'/apps/files_archive/tests/data';
$dir=OC::$SERVERROOT.'/tests/data';
$this->instance=$this->getNew();
$fh=$this->instance->getStream('lorem.txt','w');
$source=fopen($dir.'/lorem.txt','r');
@ -107,7 +107,7 @@ abstract class Test_Archive extends UnitTestCase {
$this->assertFalse($this->instance->fileExists('/test/'));
}
public function testExtract() {
$dir=OC::$SERVERROOT.'/apps/files_archive/tests/data';
$dir=OC::$SERVERROOT.'/tests/data';
$this->instance=$this->getExisting();
$tmpDir=OCP\Files::tmpFolder();
$this->instance->extract($tmpDir);
@ -118,7 +118,7 @@ abstract class Test_Archive extends UnitTestCase {
OCP\Files::rmdirr($tmpDir);
}
public function testMoveRemove() {
$dir=OC::$SERVERROOT.'/apps/files_archive/tests/data';
$dir=OC::$SERVERROOT.'/tests/data';
$textFile=$dir.'/lorem.txt';
$this->instance=$this->getNew();
$this->instance->addFile('lorem.txt',$textFile);
@ -131,7 +131,7 @@ abstract class Test_Archive extends UnitTestCase {
$this->assertFalse($this->instance->fileExists('target.txt'));
}
public function testRecursive() {
$dir=OC::$SERVERROOT.'/apps/files_archive/tests/data';
$dir=OC::$SERVERROOT.'/tests/data';
$this->instance=$this->getNew();
$this->instance->addRecursive('/dir',$dir);
$this->assertTrue($this->instance->fileExists('/dir/lorem.txt'));

View File

@ -8,17 +8,13 @@
require_once 'archive.php';
if(is_dir(OC::$SERVERROOT.'/apps/files_archive/tests/data')) {
class Test_Archive_TAR extends Test_Archive{
protected function getExisting() {
$dir=OC::$SERVERROOT.'/apps/files_archive/tests/data';
return new OC_Archive_TAR($dir.'/data.tar.gz');
}
protected function getNew() {
return new OC_Archive_TAR(OCP\Files::tmpFile('.tar.gz'));
}
class Test_Archive_TAR extends Test_Archive {
protected function getExisting() {
$dir = OC::$SERVERROOT . '/tests/data';
return new OC_Archive_TAR($dir . '/data.tar.gz');
}
protected function getNew() {
return new OC_Archive_TAR(OCP\Files::tmpFile('.tar.gz'));
}
}else{
abstract class Test_Archive_TAR extends Test_Archive{}
}

View File

@ -8,17 +8,13 @@
require_once 'archive.php';
if(is_dir(OC::$SERVERROOT.'/apps/files_archive/tests/data')) {
class Test_Archive_ZIP extends Test_Archive{
protected function getExisting() {
$dir=OC::$SERVERROOT.'/apps/files_archive/tests/data';
return new OC_Archive_ZIP($dir.'/data.zip');
}
protected function getNew() {
return new OC_Archive_ZIP(OCP\Files::tmpFile('.zip'));
}
class Test_Archive_ZIP extends Test_Archive {
protected function getExisting() {
$dir = OC::$SERVERROOT . '/tests/data';
return new OC_Archive_ZIP($dir . '/data.zip');
}
protected function getNew() {
return new OC_Archive_ZIP(OCP\Files::tmpFile('.zip'));
}
}else{
abstract class Test_Archive_ZIP extends Test_Archive{}
}