Fix namespace for archive tests

This commit is contained in:
Joas Schilling 2016-05-18 18:46:03 +02:00
parent 9eade36ae5
commit 5ce5eb195a
No known key found for this signature in database
GPG Key ID: 70A0B324C41C0946
3 changed files with 32 additions and 23 deletions

View File

@ -6,23 +6,26 @@
* See the COPYING-README file.
*/
namespace Test\Archive;
use OC\Archive\TAR;
class Test_Archive_TAR extends Test_Archive {
class TARTest extends TestBase {
protected function setUp() {
parent::setUp();
if (OC_Util::runningOnWindows()) {
if (\OC_Util::runningOnWindows()) {
$this->markTestSkipped('[Windows] tar archives are not supported on Windows');
}
}
protected function getExisting() {
$dir = OC::$SERVERROOT . '/tests/data';
$dir = \OC::$SERVERROOT . '/tests/data';
return new TAR($dir . '/data.tar.gz');
}
protected function getNew() {
return new TAR(OCP\Files::tmpFile('.tar.gz'));
return new TAR(\OCP\Files::tmpFile('.tar.gz'));
}
}

View File

@ -6,20 +6,23 @@
* See the COPYING-README file.
*/
abstract class Test_Archive extends \Test\TestCase {
namespace Test\Archive;
abstract class TestBase extends \Test\TestCase {
/**
* @var OC_Archive
* @var \OC\Archive\Archive
*/
protected $instance;
/**
* get the existing test archive
* @return OC_Archive
* @return \OC\Archive\Archive
*/
abstract protected function getExisting();
/**
* get a new archive for write testing
* @return OC_Archive
* @return \OC\Archive\Archive
*/
abstract protected function getNew();
@ -51,17 +54,17 @@ abstract class Test_Archive extends \Test\TestCase {
public function testContent() {
$this->instance=$this->getExisting();
$dir=OC::$SERVERROOT.'/tests/data';
$dir=\OC::$SERVERROOT.'/tests/data';
$textFile=$dir.'/lorem.txt';
$this->assertEquals(file_get_contents($textFile), $this->instance->getFile('lorem.txt'));
$tmpFile=OCP\Files::tmpFile('.txt');
$tmpFile=\OCP\Files::tmpFile('.txt');
$this->instance->extractFile('lorem.txt', $tmpFile);
$this->assertEquals(file_get_contents($textFile), file_get_contents($tmpFile));
}
public function testWrite() {
$dir=OC::$SERVERROOT.'/tests/data';
$dir=\OC::$SERVERROOT.'/tests/data';
$textFile=$dir.'/lorem.txt';
$this->instance=$this->getNew();
$this->assertEquals(0, count($this->instance->getFiles()));
@ -76,7 +79,7 @@ abstract class Test_Archive extends \Test\TestCase {
}
public function testReadStream() {
$dir=OC::$SERVERROOT.'/tests/data';
$dir=\OC::$SERVERROOT.'/tests/data';
$this->instance=$this->getExisting();
$fh=$this->instance->getStream('lorem.txt', 'r');
$this->assertTrue((bool)$fh);
@ -85,11 +88,11 @@ abstract class Test_Archive extends \Test\TestCase {
$this->assertEquals(file_get_contents($dir.'/lorem.txt'), $content);
}
public function testWriteStream() {
$dir=OC::$SERVERROOT.'/tests/data';
$dir=\OC::$SERVERROOT.'/tests/data';
$this->instance=$this->getNew();
$fh=$this->instance->getStream('lorem.txt', 'w');
$source=fopen($dir.'/lorem.txt', 'r');
OCP\Files::streamCopy($source, $fh);
\OCP\Files::streamCopy($source, $fh);
fclose($source);
fclose($fh);
$this->assertTrue($this->instance->fileExists('lorem.txt'));
@ -107,18 +110,18 @@ abstract class Test_Archive extends \Test\TestCase {
$this->assertFalse($this->instance->fileExists('/test/'));
}
public function testExtract() {
$dir=OC::$SERVERROOT.'/tests/data';
$dir=\OC::$SERVERROOT.'/tests/data';
$this->instance=$this->getExisting();
$tmpDir=OCP\Files::tmpFolder();
$tmpDir=\OCP\Files::tmpFolder();
$this->instance->extract($tmpDir);
$this->assertEquals(true, file_exists($tmpDir.'lorem.txt'));
$this->assertEquals(true, file_exists($tmpDir.'dir/lorem.txt'));
$this->assertEquals(true, file_exists($tmpDir.'logo-wide.png'));
$this->assertEquals(file_get_contents($dir.'/lorem.txt'), file_get_contents($tmpDir.'lorem.txt'));
OCP\Files::rmdirr($tmpDir);
\OCP\Files::rmdirr($tmpDir);
}
public function testMoveRemove() {
$dir=OC::$SERVERROOT.'/tests/data';
$dir=\OC::$SERVERROOT.'/tests/data';
$textFile=$dir.'/lorem.txt';
$this->instance=$this->getNew();
$this->instance->addFile('lorem.txt', $textFile);
@ -131,7 +134,7 @@ abstract class Test_Archive extends \Test\TestCase {
$this->assertFalse($this->instance->fileExists('target.txt'));
}
public function testRecursive() {
$dir=OC::$SERVERROOT.'/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

@ -6,23 +6,26 @@
* See the COPYING-README file.
*/
namespace Test\Archive;
use OC\Archive\ZIP;
class Test_Archive_ZIP extends Test_Archive {
class ZIPTest extends TestBase {
protected function setUp() {
parent::setUp();
if (OC_Util::runningOnWindows()) {
if (\OC_Util::runningOnWindows()) {
$this->markTestSkipped('[Windows] ');
}
}
protected function getExisting() {
$dir = OC::$SERVERROOT . '/tests/data';
$dir = \OC::$SERVERROOT . '/tests/data';
return new ZIP($dir . '/data.zip');
}
protected function getNew() {
return new ZIP(OCP\Files::tmpFile('.zip'));
return new ZIP(\OCP\Files::tmpFile('.zip'));
}
}