Fix namespace for archive tests
This commit is contained in:
parent
9eade36ae5
commit
5ce5eb195a
|
@ -6,23 +6,26 @@
|
||||||
* See the COPYING-README file.
|
* See the COPYING-README file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Test\Archive;
|
||||||
|
|
||||||
|
|
||||||
use OC\Archive\TAR;
|
use OC\Archive\TAR;
|
||||||
|
|
||||||
class Test_Archive_TAR extends Test_Archive {
|
class TARTest extends TestBase {
|
||||||
protected function setUp() {
|
protected function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
if (OC_Util::runningOnWindows()) {
|
if (\OC_Util::runningOnWindows()) {
|
||||||
$this->markTestSkipped('[Windows] tar archives are not supported on Windows');
|
$this->markTestSkipped('[Windows] tar archives are not supported on Windows');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getExisting() {
|
protected function getExisting() {
|
||||||
$dir = OC::$SERVERROOT . '/tests/data';
|
$dir = \OC::$SERVERROOT . '/tests/data';
|
||||||
return new TAR($dir . '/data.tar.gz');
|
return new TAR($dir . '/data.tar.gz');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getNew() {
|
protected function getNew() {
|
||||||
return new TAR(OCP\Files::tmpFile('.tar.gz'));
|
return new TAR(\OCP\Files::tmpFile('.tar.gz'));
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -6,20 +6,23 @@
|
||||||
* See the COPYING-README file.
|
* 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;
|
protected $instance;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the existing test archive
|
* get the existing test archive
|
||||||
* @return OC_Archive
|
* @return \OC\Archive\Archive
|
||||||
*/
|
*/
|
||||||
abstract protected function getExisting();
|
abstract protected function getExisting();
|
||||||
/**
|
/**
|
||||||
* get a new archive for write testing
|
* get a new archive for write testing
|
||||||
* @return OC_Archive
|
* @return \OC\Archive\Archive
|
||||||
*/
|
*/
|
||||||
abstract protected function getNew();
|
abstract protected function getNew();
|
||||||
|
|
||||||
|
@ -51,17 +54,17 @@ abstract class Test_Archive extends \Test\TestCase {
|
||||||
|
|
||||||
public function testContent() {
|
public function testContent() {
|
||||||
$this->instance=$this->getExisting();
|
$this->instance=$this->getExisting();
|
||||||
$dir=OC::$SERVERROOT.'/tests/data';
|
$dir=\OC::$SERVERROOT.'/tests/data';
|
||||||
$textFile=$dir.'/lorem.txt';
|
$textFile=$dir.'/lorem.txt';
|
||||||
$this->assertEquals(file_get_contents($textFile), $this->instance->getFile('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->instance->extractFile('lorem.txt', $tmpFile);
|
||||||
$this->assertEquals(file_get_contents($textFile), file_get_contents($tmpFile));
|
$this->assertEquals(file_get_contents($textFile), file_get_contents($tmpFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWrite() {
|
public function testWrite() {
|
||||||
$dir=OC::$SERVERROOT.'/tests/data';
|
$dir=\OC::$SERVERROOT.'/tests/data';
|
||||||
$textFile=$dir.'/lorem.txt';
|
$textFile=$dir.'/lorem.txt';
|
||||||
$this->instance=$this->getNew();
|
$this->instance=$this->getNew();
|
||||||
$this->assertEquals(0, count($this->instance->getFiles()));
|
$this->assertEquals(0, count($this->instance->getFiles()));
|
||||||
|
@ -76,7 +79,7 @@ abstract class Test_Archive extends \Test\TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReadStream() {
|
public function testReadStream() {
|
||||||
$dir=OC::$SERVERROOT.'/tests/data';
|
$dir=\OC::$SERVERROOT.'/tests/data';
|
||||||
$this->instance=$this->getExisting();
|
$this->instance=$this->getExisting();
|
||||||
$fh=$this->instance->getStream('lorem.txt', 'r');
|
$fh=$this->instance->getStream('lorem.txt', 'r');
|
||||||
$this->assertTrue((bool)$fh);
|
$this->assertTrue((bool)$fh);
|
||||||
|
@ -85,11 +88,11 @@ abstract class Test_Archive extends \Test\TestCase {
|
||||||
$this->assertEquals(file_get_contents($dir.'/lorem.txt'), $content);
|
$this->assertEquals(file_get_contents($dir.'/lorem.txt'), $content);
|
||||||
}
|
}
|
||||||
public function testWriteStream() {
|
public function testWriteStream() {
|
||||||
$dir=OC::$SERVERROOT.'/tests/data';
|
$dir=\OC::$SERVERROOT.'/tests/data';
|
||||||
$this->instance=$this->getNew();
|
$this->instance=$this->getNew();
|
||||||
$fh=$this->instance->getStream('lorem.txt', 'w');
|
$fh=$this->instance->getStream('lorem.txt', 'w');
|
||||||
$source=fopen($dir.'/lorem.txt', 'r');
|
$source=fopen($dir.'/lorem.txt', 'r');
|
||||||
OCP\Files::streamCopy($source, $fh);
|
\OCP\Files::streamCopy($source, $fh);
|
||||||
fclose($source);
|
fclose($source);
|
||||||
fclose($fh);
|
fclose($fh);
|
||||||
$this->assertTrue($this->instance->fileExists('lorem.txt'));
|
$this->assertTrue($this->instance->fileExists('lorem.txt'));
|
||||||
|
@ -107,18 +110,18 @@ abstract class Test_Archive extends \Test\TestCase {
|
||||||
$this->assertFalse($this->instance->fileExists('/test/'));
|
$this->assertFalse($this->instance->fileExists('/test/'));
|
||||||
}
|
}
|
||||||
public function testExtract() {
|
public function testExtract() {
|
||||||
$dir=OC::$SERVERROOT.'/tests/data';
|
$dir=\OC::$SERVERROOT.'/tests/data';
|
||||||
$this->instance=$this->getExisting();
|
$this->instance=$this->getExisting();
|
||||||
$tmpDir=OCP\Files::tmpFolder();
|
$tmpDir=\OCP\Files::tmpFolder();
|
||||||
$this->instance->extract($tmpDir);
|
$this->instance->extract($tmpDir);
|
||||||
$this->assertEquals(true, file_exists($tmpDir.'lorem.txt'));
|
$this->assertEquals(true, file_exists($tmpDir.'lorem.txt'));
|
||||||
$this->assertEquals(true, file_exists($tmpDir.'dir/lorem.txt'));
|
$this->assertEquals(true, file_exists($tmpDir.'dir/lorem.txt'));
|
||||||
$this->assertEquals(true, file_exists($tmpDir.'logo-wide.png'));
|
$this->assertEquals(true, file_exists($tmpDir.'logo-wide.png'));
|
||||||
$this->assertEquals(file_get_contents($dir.'/lorem.txt'), file_get_contents($tmpDir.'lorem.txt'));
|
$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() {
|
public function testMoveRemove() {
|
||||||
$dir=OC::$SERVERROOT.'/tests/data';
|
$dir=\OC::$SERVERROOT.'/tests/data';
|
||||||
$textFile=$dir.'/lorem.txt';
|
$textFile=$dir.'/lorem.txt';
|
||||||
$this->instance=$this->getNew();
|
$this->instance=$this->getNew();
|
||||||
$this->instance->addFile('lorem.txt', $textFile);
|
$this->instance->addFile('lorem.txt', $textFile);
|
||||||
|
@ -131,7 +134,7 @@ abstract class Test_Archive extends \Test\TestCase {
|
||||||
$this->assertFalse($this->instance->fileExists('target.txt'));
|
$this->assertFalse($this->instance->fileExists('target.txt'));
|
||||||
}
|
}
|
||||||
public function testRecursive() {
|
public function testRecursive() {
|
||||||
$dir=OC::$SERVERROOT.'/tests/data';
|
$dir=\OC::$SERVERROOT.'/tests/data';
|
||||||
$this->instance=$this->getNew();
|
$this->instance=$this->getNew();
|
||||||
$this->instance->addRecursive('/dir', $dir);
|
$this->instance->addRecursive('/dir', $dir);
|
||||||
$this->assertTrue($this->instance->fileExists('/dir/lorem.txt'));
|
$this->assertTrue($this->instance->fileExists('/dir/lorem.txt'));
|
|
@ -6,23 +6,26 @@
|
||||||
* See the COPYING-README file.
|
* See the COPYING-README file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Test\Archive;
|
||||||
|
|
||||||
|
|
||||||
use OC\Archive\ZIP;
|
use OC\Archive\ZIP;
|
||||||
|
|
||||||
class Test_Archive_ZIP extends Test_Archive {
|
class ZIPTest extends TestBase {
|
||||||
protected function setUp() {
|
protected function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
if (OC_Util::runningOnWindows()) {
|
if (\OC_Util::runningOnWindows()) {
|
||||||
$this->markTestSkipped('[Windows] ');
|
$this->markTestSkipped('[Windows] ');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getExisting() {
|
protected function getExisting() {
|
||||||
$dir = OC::$SERVERROOT . '/tests/data';
|
$dir = \OC::$SERVERROOT . '/tests/data';
|
||||||
return new ZIP($dir . '/data.zip');
|
return new ZIP($dir . '/data.zip');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getNew() {
|
protected function getNew() {
|
||||||
return new ZIP(OCP\Files::tmpFile('.zip'));
|
return new ZIP(\OCP\Files::tmpFile('.zip'));
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue