From 5ce5eb195ac6b464455b1e55ed37af3f555dfb21 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 18 May 2016 18:46:03 +0200 Subject: Fix namespace for archive tests --- tests/lib/archive.php | 141 ---------------------------------------- tests/lib/archive/tar.php | 28 -------- tests/lib/archive/tartest.php | 31 +++++++++ tests/lib/archive/testbase.php | 144 +++++++++++++++++++++++++++++++++++++++++ tests/lib/archive/zip.php | 28 -------- tests/lib/archive/ziptest.php | 31 +++++++++ 6 files changed, 206 insertions(+), 197 deletions(-) delete mode 100644 tests/lib/archive.php delete mode 100644 tests/lib/archive/tar.php create mode 100644 tests/lib/archive/tartest.php create mode 100644 tests/lib/archive/testbase.php delete mode 100644 tests/lib/archive/zip.php create mode 100644 tests/lib/archive/ziptest.php diff --git a/tests/lib/archive.php b/tests/lib/archive.php deleted file mode 100644 index 690b4378b88..00000000000 --- a/tests/lib/archive.php +++ /dev/null @@ -1,141 +0,0 @@ - - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ - -abstract class Test_Archive extends \Test\TestCase { - /** - * @var OC_Archive - */ - protected $instance; - - /** - * get the existing test archive - * @return OC_Archive - */ - abstract protected function getExisting(); - /** - * get a new archive for write testing - * @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->assertEquals(4, count($allFiles), 'only found '.count($allFiles).' out of 4 expected files'); - foreach($expected as $file) { - $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->assertEquals(3, count($rootContent)); - foreach($expected as $file) { - $this->assertContains($file, $rootContent, 'cant find '. $file . ' in archive'); - } - - $dirContent=$this->instance->getFolder('dir/'); - $expected=array('lorem.txt'); - $this->assertEquals(1, count($dirContent)); - foreach($expected as $file) { - $this->assertContains($file, $dirContent, 'cant find '. $file . ' in archive'); - } - } - - public function testContent() { - $this->instance=$this->getExisting(); - $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'); - $this->instance->extractFile('lorem.txt', $tmpFile); - $this->assertEquals(file_get_contents($textFile), file_get_contents($tmpFile)); - } - - public function testWrite() { - $dir=OC::$SERVERROOT.'/tests/data'; - $textFile=$dir.'/lorem.txt'; - $this->instance=$this->getNew(); - $this->assertEquals(0, count($this->instance->getFiles())); - $this->instance->addFile('lorem.txt', $textFile); - $this->assertEquals(1, count($this->instance->getFiles())); - $this->assertTrue($this->instance->fileExists('lorem.txt')); - $this->assertFalse($this->instance->fileExists('lorem.txt/')); - - $this->assertEquals(file_get_contents($textFile), $this->instance->getFile('lorem.txt')); - $this->instance->addFile('lorem.txt', 'foobar'); - $this->assertEquals('foobar', $this->instance->getFile('lorem.txt')); - } - - public function testReadStream() { - $dir=OC::$SERVERROOT.'/tests/data'; - $this->instance=$this->getExisting(); - $fh=$this->instance->getStream('lorem.txt', 'r'); - $this->assertTrue((bool)$fh); - $content=fread($fh, $this->instance->filesize('lorem.txt')); - fclose($fh); - $this->assertEquals(file_get_contents($dir.'/lorem.txt'), $content); - } - public function testWriteStream() { - $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); - fclose($source); - fclose($fh); - $this->assertTrue($this->instance->fileExists('lorem.txt')); - $this->assertEquals(file_get_contents($dir.'/lorem.txt'), $this->instance->getFile('lorem.txt')); - } - public function testFolder() { - $this->instance=$this->getNew(); - $this->assertFalse($this->instance->fileExists('/test')); - $this->assertFalse($this->instance->fileExists('/test/')); - $this->instance->addFolder('/test'); - $this->assertTrue($this->instance->fileExists('/test')); - $this->assertTrue($this->instance->fileExists('/test/')); - $this->instance->remove('/test'); - $this->assertFalse($this->instance->fileExists('/test')); - $this->assertFalse($this->instance->fileExists('/test/')); - } - public function testExtract() { - $dir=OC::$SERVERROOT.'/tests/data'; - $this->instance=$this->getExisting(); - $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); - } - public function testMoveRemove() { - $dir=OC::$SERVERROOT.'/tests/data'; - $textFile=$dir.'/lorem.txt'; - $this->instance=$this->getNew(); - $this->instance->addFile('lorem.txt', $textFile); - $this->assertFalse($this->instance->fileExists('target.txt')); - $this->instance->rename('lorem.txt', 'target.txt'); - $this->assertTrue($this->instance->fileExists('target.txt')); - $this->assertFalse($this->instance->fileExists('lorem.txt')); - $this->assertEquals(file_get_contents($textFile), $this->instance->getFile('target.txt')); - $this->instance->remove('target.txt'); - $this->assertFalse($this->instance->fileExists('target.txt')); - } - public function testRecursive() { - $dir=OC::$SERVERROOT.'/tests/data'; - $this->instance=$this->getNew(); - $this->instance->addRecursive('/dir', $dir); - $this->assertTrue($this->instance->fileExists('/dir/lorem.txt')); - $this->assertTrue($this->instance->fileExists('/dir/data.zip')); - $this->assertTrue($this->instance->fileExists('/dir/data.tar.gz')); - } -} diff --git a/tests/lib/archive/tar.php b/tests/lib/archive/tar.php deleted file mode 100644 index 2d20bb4c3b1..00000000000 --- a/tests/lib/archive/tar.php +++ /dev/null @@ -1,28 +0,0 @@ - - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ - -use OC\Archive\TAR; - -class Test_Archive_TAR extends Test_Archive { - protected function setUp() { - parent::setUp(); - - if (OC_Util::runningOnWindows()) { - $this->markTestSkipped('[Windows] tar archives are not supported on Windows'); - } - } - - protected function getExisting() { - $dir = OC::$SERVERROOT . '/tests/data'; - return new TAR($dir . '/data.tar.gz'); - } - - protected function getNew() { - return new TAR(OCP\Files::tmpFile('.tar.gz')); - } -} diff --git a/tests/lib/archive/tartest.php b/tests/lib/archive/tartest.php new file mode 100644 index 00000000000..998ce201e72 --- /dev/null +++ b/tests/lib/archive/tartest.php @@ -0,0 +1,31 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Test\Archive; + + +use OC\Archive\TAR; + +class TARTest extends TestBase { + protected function setUp() { + parent::setUp(); + + if (\OC_Util::runningOnWindows()) { + $this->markTestSkipped('[Windows] tar archives are not supported on Windows'); + } + } + + protected function getExisting() { + $dir = \OC::$SERVERROOT . '/tests/data'; + return new TAR($dir . '/data.tar.gz'); + } + + protected function getNew() { + return new TAR(\OCP\Files::tmpFile('.tar.gz')); + } +} diff --git a/tests/lib/archive/testbase.php b/tests/lib/archive/testbase.php new file mode 100644 index 00000000000..5bf4d9d43ea --- /dev/null +++ b/tests/lib/archive/testbase.php @@ -0,0 +1,144 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Test\Archive; + + +abstract class TestBase extends \Test\TestCase { + /** + * @var \OC\Archive\Archive + */ + protected $instance; + + /** + * get the existing test archive + * @return \OC\Archive\Archive + */ + abstract protected function getExisting(); + /** + * get a new archive for write testing + * @return \OC\Archive\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->assertEquals(4, count($allFiles), 'only found '.count($allFiles).' out of 4 expected files'); + foreach($expected as $file) { + $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->assertEquals(3, count($rootContent)); + foreach($expected as $file) { + $this->assertContains($file, $rootContent, 'cant find '. $file . ' in archive'); + } + + $dirContent=$this->instance->getFolder('dir/'); + $expected=array('lorem.txt'); + $this->assertEquals(1, count($dirContent)); + foreach($expected as $file) { + $this->assertContains($file, $dirContent, 'cant find '. $file . ' in archive'); + } + } + + public function testContent() { + $this->instance=$this->getExisting(); + $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'); + $this->instance->extractFile('lorem.txt', $tmpFile); + $this->assertEquals(file_get_contents($textFile), file_get_contents($tmpFile)); + } + + public function testWrite() { + $dir=\OC::$SERVERROOT.'/tests/data'; + $textFile=$dir.'/lorem.txt'; + $this->instance=$this->getNew(); + $this->assertEquals(0, count($this->instance->getFiles())); + $this->instance->addFile('lorem.txt', $textFile); + $this->assertEquals(1, count($this->instance->getFiles())); + $this->assertTrue($this->instance->fileExists('lorem.txt')); + $this->assertFalse($this->instance->fileExists('lorem.txt/')); + + $this->assertEquals(file_get_contents($textFile), $this->instance->getFile('lorem.txt')); + $this->instance->addFile('lorem.txt', 'foobar'); + $this->assertEquals('foobar', $this->instance->getFile('lorem.txt')); + } + + public function testReadStream() { + $dir=\OC::$SERVERROOT.'/tests/data'; + $this->instance=$this->getExisting(); + $fh=$this->instance->getStream('lorem.txt', 'r'); + $this->assertTrue((bool)$fh); + $content=fread($fh, $this->instance->filesize('lorem.txt')); + fclose($fh); + $this->assertEquals(file_get_contents($dir.'/lorem.txt'), $content); + } + public function testWriteStream() { + $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); + fclose($source); + fclose($fh); + $this->assertTrue($this->instance->fileExists('lorem.txt')); + $this->assertEquals(file_get_contents($dir.'/lorem.txt'), $this->instance->getFile('lorem.txt')); + } + public function testFolder() { + $this->instance=$this->getNew(); + $this->assertFalse($this->instance->fileExists('/test')); + $this->assertFalse($this->instance->fileExists('/test/')); + $this->instance->addFolder('/test'); + $this->assertTrue($this->instance->fileExists('/test')); + $this->assertTrue($this->instance->fileExists('/test/')); + $this->instance->remove('/test'); + $this->assertFalse($this->instance->fileExists('/test')); + $this->assertFalse($this->instance->fileExists('/test/')); + } + public function testExtract() { + $dir=\OC::$SERVERROOT.'/tests/data'; + $this->instance=$this->getExisting(); + $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); + } + public function testMoveRemove() { + $dir=\OC::$SERVERROOT.'/tests/data'; + $textFile=$dir.'/lorem.txt'; + $this->instance=$this->getNew(); + $this->instance->addFile('lorem.txt', $textFile); + $this->assertFalse($this->instance->fileExists('target.txt')); + $this->instance->rename('lorem.txt', 'target.txt'); + $this->assertTrue($this->instance->fileExists('target.txt')); + $this->assertFalse($this->instance->fileExists('lorem.txt')); + $this->assertEquals(file_get_contents($textFile), $this->instance->getFile('target.txt')); + $this->instance->remove('target.txt'); + $this->assertFalse($this->instance->fileExists('target.txt')); + } + public function testRecursive() { + $dir=\OC::$SERVERROOT.'/tests/data'; + $this->instance=$this->getNew(); + $this->instance->addRecursive('/dir', $dir); + $this->assertTrue($this->instance->fileExists('/dir/lorem.txt')); + $this->assertTrue($this->instance->fileExists('/dir/data.zip')); + $this->assertTrue($this->instance->fileExists('/dir/data.tar.gz')); + } +} diff --git a/tests/lib/archive/zip.php b/tests/lib/archive/zip.php deleted file mode 100644 index 2f4c9cace1d..00000000000 --- a/tests/lib/archive/zip.php +++ /dev/null @@ -1,28 +0,0 @@ - - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ - -use OC\Archive\ZIP; - -class Test_Archive_ZIP extends Test_Archive { - protected function setUp() { - parent::setUp(); - - if (OC_Util::runningOnWindows()) { - $this->markTestSkipped('[Windows] '); - } - } - - protected function getExisting() { - $dir = OC::$SERVERROOT . '/tests/data'; - return new ZIP($dir . '/data.zip'); - } - - protected function getNew() { - return new ZIP(OCP\Files::tmpFile('.zip')); - } -} diff --git a/tests/lib/archive/ziptest.php b/tests/lib/archive/ziptest.php new file mode 100644 index 00000000000..8d639e0d686 --- /dev/null +++ b/tests/lib/archive/ziptest.php @@ -0,0 +1,31 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Test\Archive; + + +use OC\Archive\ZIP; + +class ZIPTest extends TestBase { + protected function setUp() { + parent::setUp(); + + if (\OC_Util::runningOnWindows()) { + $this->markTestSkipped('[Windows] '); + } + } + + protected function getExisting() { + $dir = \OC::$SERVERROOT . '/tests/data'; + return new ZIP($dir . '/data.zip'); + } + + protected function getNew() { + return new ZIP(\OCP\Files::tmpFile('.zip')); + } +} -- cgit v1.2.3