2012-10-13 13:51:37 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2012 Lukas Reschke <lukas@statuscode.ch>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
2014-11-10 21:59:50 +00:00
|
|
|
class Test_Helper extends \Test\TestCase {
|
2012-10-13 13:51:37 +00:00
|
|
|
|
2013-09-13 15:22:45 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider humanFileSizeProvider
|
|
|
|
*/
|
|
|
|
public function testHumanFileSize($expected, $input)
|
|
|
|
{
|
|
|
|
$result = OC_Helper::humanFileSize($input);
|
|
|
|
$this->assertEquals($expected, $result);
|
2012-10-13 13:51:37 +00:00
|
|
|
}
|
|
|
|
|
2013-09-13 15:22:45 +00:00
|
|
|
public function humanFileSizeProvider()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
array('0 B', 0),
|
|
|
|
array('1 kB', 1024),
|
|
|
|
array('9.5 MB', 10000000),
|
2014-03-17 11:15:12 +00:00
|
|
|
array('1.3 GB', 1395864371),
|
2013-09-13 15:22:45 +00:00
|
|
|
array('465.7 GB', 500000000000),
|
|
|
|
array('454.7 TB', 500000000000000),
|
|
|
|
array('444.1 PB', 500000000000000000),
|
|
|
|
);
|
|
|
|
}
|
2012-10-13 13:51:37 +00:00
|
|
|
|
2014-04-07 13:31:34 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider phpFileSizeProvider
|
|
|
|
*/
|
|
|
|
public function testPhpFileSize($expected, $input)
|
|
|
|
{
|
|
|
|
$result = OC_Helper::phpFileSize($input);
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function phpFileSizeProvider()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
array('0B', 0),
|
|
|
|
array('1K', 1024),
|
|
|
|
array('9.5M', 10000000),
|
|
|
|
array('1.3G', 1395864371),
|
|
|
|
array('465.7G', 500000000000),
|
|
|
|
array('465661.3G', 500000000000000),
|
|
|
|
array('465661287.3G', 500000000000000000),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-09-13 15:22:45 +00:00
|
|
|
/**
|
2015-05-07 15:56:13 +00:00
|
|
|
* @dataProvider providesComputerFileSize
|
2013-09-13 15:22:45 +00:00
|
|
|
*/
|
|
|
|
function testComputerFileSize($expected, $input) {
|
|
|
|
$result = OC_Helper::computerFileSize($input);
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
2012-10-13 13:51:37 +00:00
|
|
|
|
2015-05-07 15:56:13 +00:00
|
|
|
function providesComputerFileSize(){
|
|
|
|
return [
|
|
|
|
[0.0, "0 B"],
|
|
|
|
[1024.0, "1 kB"],
|
|
|
|
[1395864371.0, '1.3 GB'],
|
|
|
|
[9961472.0, "9.5 MB"],
|
|
|
|
[500041567437.0, "465.7 GB"],
|
|
|
|
[false, "12 GB etfrhzui"]
|
|
|
|
];
|
2012-10-13 13:51:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testGetMimeType() {
|
2012-10-13 19:02:12 +00:00
|
|
|
$dir=OC::$SERVERROOT.'/tests/data';
|
|
|
|
$result = OC_Helper::getMimeType($dir."/");
|
2012-10-13 13:51:37 +00:00
|
|
|
$expected = 'httpd/unix-directory';
|
|
|
|
$this->assertEquals($result, $expected);
|
|
|
|
|
2012-10-13 19:02:12 +00:00
|
|
|
$result = OC_Helper::getMimeType($dir."/data.tar.gz");
|
2012-10-13 13:51:37 +00:00
|
|
|
$expected = 'application/x-gzip';
|
|
|
|
$this->assertEquals($result, $expected);
|
|
|
|
|
2012-10-13 19:02:12 +00:00
|
|
|
$result = OC_Helper::getMimeType($dir."/data.zip");
|
2012-10-13 13:51:37 +00:00
|
|
|
$expected = 'application/zip';
|
|
|
|
$this->assertEquals($result, $expected);
|
|
|
|
|
2015-05-21 20:40:26 +00:00
|
|
|
$result = OC_Helper::getMimeType($dir."/desktopapp.svg");
|
2012-10-13 13:51:37 +00:00
|
|
|
$expected = 'image/svg+xml';
|
|
|
|
$this->assertEquals($result, $expected);
|
|
|
|
|
2015-05-21 20:40:26 +00:00
|
|
|
$result = OC_Helper::getMimeType($dir."/desktopapp.png");
|
2012-10-13 13:51:37 +00:00
|
|
|
$expected = 'image/png';
|
|
|
|
$this->assertEquals($result, $expected);
|
|
|
|
}
|
|
|
|
|
2014-04-14 15:17:50 +00:00
|
|
|
function testGetSecureMimeType() {
|
|
|
|
$dir=OC::$SERVERROOT.'/tests/data';
|
|
|
|
|
|
|
|
$result = OC_Helper::getSecureMimeType('image/svg+xml');
|
|
|
|
$expected = 'text/plain';
|
|
|
|
$this->assertEquals($result, $expected);
|
|
|
|
|
|
|
|
$result = OC_Helper::getSecureMimeType('image/png');
|
|
|
|
$expected = 'image/png';
|
|
|
|
$this->assertEquals($result, $expected);
|
|
|
|
}
|
|
|
|
|
2013-06-16 18:19:37 +00:00
|
|
|
function testGetFileNameMimeType() {
|
|
|
|
$this->assertEquals('text/plain', OC_Helper::getFileNameMimeType('foo.txt'));
|
|
|
|
$this->assertEquals('image/png', OC_Helper::getFileNameMimeType('foo.png'));
|
|
|
|
$this->assertEquals('image/png', OC_Helper::getFileNameMimeType('foo.bar.png'));
|
|
|
|
$this->assertEquals('application/octet-stream', OC_Helper::getFileNameMimeType('.png'));
|
|
|
|
$this->assertEquals('application/octet-stream', OC_Helper::getFileNameMimeType('foo'));
|
|
|
|
$this->assertEquals('application/octet-stream', OC_Helper::getFileNameMimeType(''));
|
|
|
|
}
|
|
|
|
|
2012-10-13 13:51:37 +00:00
|
|
|
function testGetStringMimeType() {
|
2014-11-10 10:01:43 +00:00
|
|
|
if (\OC_Util::runningOnWindows()) {
|
|
|
|
$this->markTestSkipped('[Windows] Strings have mimetype application/octet-stream on Windows');
|
|
|
|
}
|
|
|
|
|
2012-10-13 13:51:37 +00:00
|
|
|
$result = OC_Helper::getStringMimeType("/data/data.tar.gz");
|
|
|
|
$expected = 'text/plain; charset=us-ascii';
|
|
|
|
$this->assertEquals($result, $expected);
|
|
|
|
}
|
|
|
|
|
2014-05-11 13:50:59 +00:00
|
|
|
function testIsSubDirectory() {
|
|
|
|
$result = OC_Helper::isSubDirectory("./data/", "/anotherDirectory/");
|
2012-10-13 13:51:37 +00:00
|
|
|
$this->assertFalse($result);
|
|
|
|
|
2014-05-11 13:50:59 +00:00
|
|
|
$result = OC_Helper::isSubDirectory("./data/", "./data/");
|
2012-10-13 13:51:37 +00:00
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
mkdir("data/TestSubdirectory", 0777);
|
2014-05-11 13:50:59 +00:00
|
|
|
$result = OC_Helper::isSubDirectory("data/TestSubdirectory/", "data");
|
2012-10-13 13:51:37 +00:00
|
|
|
rmdir("data/TestSubdirectory");
|
|
|
|
$this->assertTrue($result);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testMb_array_change_key_case() {
|
|
|
|
$arrayStart = array(
|
|
|
|
"Foo" => "bar",
|
|
|
|
"Bar" => "foo",
|
|
|
|
);
|
|
|
|
$arrayResult = array(
|
|
|
|
"foo" => "bar",
|
|
|
|
"bar" => "foo",
|
|
|
|
);
|
|
|
|
$result = OC_Helper::mb_array_change_key_case($arrayStart);
|
|
|
|
$expected = $arrayResult;
|
|
|
|
$this->assertEquals($result, $expected);
|
|
|
|
|
|
|
|
$arrayStart = array(
|
|
|
|
"foo" => "bar",
|
|
|
|
"bar" => "foo",
|
|
|
|
);
|
|
|
|
$arrayResult = array(
|
|
|
|
"FOO" => "bar",
|
|
|
|
"BAR" => "foo",
|
|
|
|
);
|
|
|
|
$result = OC_Helper::mb_array_change_key_case($arrayStart, MB_CASE_UPPER);
|
|
|
|
$expected = $arrayResult;
|
2014-05-19 15:50:53 +00:00
|
|
|
$this->assertEquals($result, $expected);
|
2012-10-13 13:51:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testMb_substr_replace() {
|
|
|
|
$result = OC_Helper::mb_substr_replace("This is a teststring", "string", 5);
|
|
|
|
$expected = "This string is a teststring";
|
|
|
|
$this->assertEquals($result, $expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testMb_str_replace() {
|
|
|
|
$result = OC_Helper::mb_str_replace("teststring", "string", "This is a teststring");
|
|
|
|
$expected = "This is a string";
|
|
|
|
$this->assertEquals($result, $expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testRecursiveArraySearch() {
|
|
|
|
$haystack = array(
|
|
|
|
"Foo" => "own",
|
|
|
|
"Bar" => "Cloud",
|
|
|
|
);
|
|
|
|
|
|
|
|
$result = OC_Helper::recursiveArraySearch($haystack, "own");
|
|
|
|
$expected = "Foo";
|
|
|
|
$this->assertEquals($result, $expected);
|
|
|
|
|
|
|
|
$result = OC_Helper::recursiveArraySearch($haystack, "NotFound");
|
|
|
|
$this->assertFalse($result);
|
|
|
|
}
|
2013-03-08 13:22:04 +00:00
|
|
|
|
|
|
|
function testBuildNotExistingFileNameForView() {
|
|
|
|
$viewMock = $this->getMock('\OC\Files\View', array(), array(), '', false);
|
|
|
|
$this->assertEquals('/filename', OC_Helper::buildNotExistingFileNameForView('/', 'filename', $viewMock));
|
|
|
|
$this->assertEquals('dir/filename.ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename.ext', $viewMock));
|
|
|
|
|
|
|
|
$viewMock->expects($this->at(0))
|
|
|
|
->method('file_exists')
|
2013-07-05 13:38:09 +00:00
|
|
|
->will($this->returnValue(true)); // filename.ext exists
|
2013-03-08 13:22:04 +00:00
|
|
|
$this->assertEquals('dir/filename (2).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename.ext', $viewMock));
|
|
|
|
|
|
|
|
$viewMock->expects($this->at(0))
|
|
|
|
->method('file_exists')
|
2013-07-05 13:38:09 +00:00
|
|
|
->will($this->returnValue(true)); // filename.ext exists
|
2013-03-08 13:22:04 +00:00
|
|
|
$viewMock->expects($this->at(1))
|
|
|
|
->method('file_exists')
|
2013-07-05 13:38:09 +00:00
|
|
|
->will($this->returnValue(true)); // filename (2).ext exists
|
2013-03-08 13:22:04 +00:00
|
|
|
$this->assertEquals('dir/filename (3).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename.ext', $viewMock));
|
|
|
|
|
|
|
|
$viewMock->expects($this->at(0))
|
|
|
|
->method('file_exists')
|
2013-07-05 13:38:09 +00:00
|
|
|
->will($this->returnValue(true)); // filename (1).ext exists
|
2013-03-08 13:22:04 +00:00
|
|
|
$this->assertEquals('dir/filename (2).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename (1).ext', $viewMock));
|
|
|
|
|
|
|
|
$viewMock->expects($this->at(0))
|
|
|
|
->method('file_exists')
|
2013-07-05 13:38:09 +00:00
|
|
|
->will($this->returnValue(true)); // filename (2).ext exists
|
|
|
|
$this->assertEquals('dir/filename (3).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename (2).ext', $viewMock));
|
|
|
|
|
|
|
|
$viewMock->expects($this->at(0))
|
|
|
|
->method('file_exists')
|
|
|
|
->will($this->returnValue(true)); // filename (2).ext exists
|
2013-03-08 13:22:04 +00:00
|
|
|
$viewMock->expects($this->at(1))
|
|
|
|
->method('file_exists')
|
2013-07-05 13:38:09 +00:00
|
|
|
->will($this->returnValue(true)); // filename (3).ext exists
|
|
|
|
$this->assertEquals('dir/filename (4).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename (2).ext', $viewMock));
|
2013-03-08 13:22:04 +00:00
|
|
|
|
|
|
|
$viewMock->expects($this->at(0))
|
|
|
|
->method('file_exists')
|
2013-07-05 13:38:09 +00:00
|
|
|
->will($this->returnValue(true)); // filename(1).ext exists
|
2013-03-08 13:22:04 +00:00
|
|
|
$this->assertEquals('dir/filename(2).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename(1).ext', $viewMock));
|
|
|
|
|
|
|
|
$viewMock->expects($this->at(0))
|
|
|
|
->method('file_exists')
|
2013-07-05 13:38:09 +00:00
|
|
|
->will($this->returnValue(true)); // filename(1) (1).ext exists
|
2013-03-08 13:22:04 +00:00
|
|
|
$this->assertEquals('dir/filename(1) (2).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename(1) (1).ext', $viewMock));
|
2013-07-05 13:38:09 +00:00
|
|
|
|
|
|
|
$viewMock->expects($this->at(0))
|
|
|
|
->method('file_exists')
|
|
|
|
->will($this->returnValue(true)); // filename(1) (1).ext exists
|
|
|
|
$viewMock->expects($this->at(1))
|
|
|
|
->method('file_exists')
|
|
|
|
->will($this->returnValue(true)); // filename(1) (2).ext exists
|
|
|
|
$this->assertEquals('dir/filename(1) (3).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename(1) (1).ext', $viewMock));
|
|
|
|
|
|
|
|
$viewMock->expects($this->at(0))
|
|
|
|
->method('file_exists')
|
|
|
|
->will($this->returnValue(true)); // filename(1) (2) (3).ext exists
|
|
|
|
$this->assertEquals('dir/filename(1) (2) (4).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename(1) (2) (3).ext', $viewMock));
|
2013-03-08 13:22:04 +00:00
|
|
|
}
|
2013-10-14 19:33:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider streamCopyDataProvider
|
|
|
|
*/
|
|
|
|
public function testStreamCopy($expectedCount, $expectedResult, $source, $target) {
|
|
|
|
|
|
|
|
if (is_string($source)) {
|
|
|
|
$source = fopen($source, 'r');
|
|
|
|
}
|
|
|
|
if (is_string($target)) {
|
|
|
|
$target = fopen($target, 'w');
|
|
|
|
}
|
|
|
|
|
|
|
|
list($count, $result) = \OC_Helper::streamCopy($source, $target);
|
|
|
|
|
|
|
|
if (is_resource($source)) {
|
|
|
|
fclose($source);
|
|
|
|
}
|
|
|
|
if (is_resource($target)) {
|
|
|
|
fclose($target);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertSame($expectedCount, $count);
|
|
|
|
$this->assertSame($expectedResult, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function streamCopyDataProvider() {
|
|
|
|
return array(
|
|
|
|
array(0, false, false, false),
|
|
|
|
array(0, false, \OC::$SERVERROOT . '/tests/data/lorem.txt', false),
|
2013-11-02 19:31:29 +00:00
|
|
|
array(filesize(\OC::$SERVERROOT . '/tests/data/lorem.txt'), true, \OC::$SERVERROOT . '/tests/data/lorem.txt', \OC::$SERVERROOT . '/tests/data/lorem-copy.txt'),
|
2013-11-04 16:19:04 +00:00
|
|
|
array(3670, true, \OC::$SERVERROOT . '/tests/data/testimage.png', \OC::$SERVERROOT . '/tests/data/testimage-copy.png'),
|
2013-10-14 19:33:23 +00:00
|
|
|
);
|
|
|
|
}
|
2014-04-16 12:32:08 +00:00
|
|
|
|
|
|
|
// Url generator methods
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @small
|
2014-05-19 15:50:53 +00:00
|
|
|
* test absolute URL construction
|
2014-04-16 12:32:08 +00:00
|
|
|
* @dataProvider provideDocRootURLs
|
|
|
|
*/
|
|
|
|
function testMakeAbsoluteURLDocRoot($url, $expectedResult) {
|
|
|
|
\OC::$WEBROOT = '';
|
|
|
|
$result = \OC_Helper::makeURLAbsolute($url);
|
|
|
|
|
|
|
|
$this->assertEquals($expectedResult, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @small
|
2014-05-19 15:50:53 +00:00
|
|
|
* test absolute URL construction
|
2014-04-16 12:32:08 +00:00
|
|
|
* @dataProvider provideSubDirURLs
|
|
|
|
*/
|
|
|
|
function testMakeAbsoluteURLSubDir($url, $expectedResult) {
|
|
|
|
\OC::$WEBROOT = '/owncloud';
|
|
|
|
$result = \OC_Helper::makeURLAbsolute($url);
|
|
|
|
|
|
|
|
$this->assertEquals($expectedResult, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideDocRootURLs() {
|
|
|
|
return array(
|
|
|
|
array('index.php', 'http://localhost/index.php'),
|
|
|
|
array('/index.php', 'http://localhost/index.php'),
|
|
|
|
array('/apps/index.php', 'http://localhost/apps/index.php'),
|
|
|
|
array('apps/index.php', 'http://localhost/apps/index.php'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideSubDirURLs() {
|
|
|
|
return array(
|
|
|
|
array('index.php', 'http://localhost/owncloud/index.php'),
|
|
|
|
array('/index.php', 'http://localhost/owncloud/index.php'),
|
|
|
|
array('/apps/index.php', 'http://localhost/owncloud/apps/index.php'),
|
|
|
|
array('apps/index.php', 'http://localhost/owncloud/apps/index.php'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @small
|
2014-05-19 15:50:53 +00:00
|
|
|
* test linkTo URL construction
|
2014-04-16 12:32:08 +00:00
|
|
|
* @dataProvider provideDocRootAppUrlParts
|
|
|
|
*/
|
|
|
|
public function testLinkToDocRoot($app, $file, $args, $expectedResult) {
|
|
|
|
\OC::$WEBROOT = '';
|
|
|
|
$result = \OC_Helper::linkTo($app, $file, $args);
|
|
|
|
|
|
|
|
$this->assertEquals($expectedResult, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @small
|
2014-05-19 15:50:53 +00:00
|
|
|
* test linkTo URL construction in sub directory
|
2014-04-16 12:32:08 +00:00
|
|
|
* @dataProvider provideSubDirAppUrlParts
|
|
|
|
*/
|
|
|
|
public function testLinkToSubDir($app, $file, $args, $expectedResult) {
|
|
|
|
\OC::$WEBROOT = '/owncloud';
|
|
|
|
$result = \OC_Helper::linkTo($app, $file, $args);
|
|
|
|
|
|
|
|
$this->assertEquals($expectedResult, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideDocRootAppUrlParts() {
|
|
|
|
return array(
|
|
|
|
array('files', 'index.php', array(), '/index.php/apps/files'),
|
|
|
|
array('files', 'index.php', array('trut' => 'trat', 'dut' => 'dat'), '/index.php/apps/files?trut=trat&dut=dat'),
|
|
|
|
array('', 'index.php', array('trut' => 'trat', 'dut' => 'dat'), '/index.php?trut=trat&dut=dat'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideSubDirAppUrlParts() {
|
|
|
|
return array(
|
|
|
|
array('files', 'index.php', array(), '/owncloud/index.php/apps/files'),
|
|
|
|
array('files', 'index.php', array('trut' => 'trat', 'dut' => 'dat'), '/owncloud/index.php/apps/files?trut=trat&dut=dat'),
|
|
|
|
array('', 'index.php', array('trut' => 'trat', 'dut' => 'dat'), '/owncloud/index.php?trut=trat&dut=dat'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @small
|
2014-05-19 15:50:53 +00:00
|
|
|
* test linkToAbsolute URL construction
|
2014-04-16 12:32:08 +00:00
|
|
|
* @dataProvider provideDocRootAppAbsoluteUrlParts
|
|
|
|
*/
|
|
|
|
public function testLinkToAbsoluteDocRoot($app, $file, $args, $expectedResult) {
|
|
|
|
\OC::$WEBROOT = '';
|
|
|
|
$result = \OC_Helper::linkToAbsolute($app, $file, $args);
|
|
|
|
|
|
|
|
$this->assertEquals($expectedResult, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @small
|
2014-05-19 15:50:53 +00:00
|
|
|
* test linkToAbsolute URL construction in sub directory
|
2014-04-16 12:32:08 +00:00
|
|
|
* @dataProvider provideSubDirAppAbsoluteUrlParts
|
|
|
|
*/
|
|
|
|
public function testLinkToAbsoluteSubDir($app, $file, $args, $expectedResult) {
|
|
|
|
\OC::$WEBROOT = '/owncloud';
|
|
|
|
$result = \OC_Helper::linkToAbsolute($app, $file, $args);
|
|
|
|
|
|
|
|
$this->assertEquals($expectedResult, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideDocRootAppAbsoluteUrlParts() {
|
|
|
|
return array(
|
|
|
|
array('files', 'index.php', array(), 'http://localhost/index.php/apps/files'),
|
|
|
|
array('files', 'index.php', array('trut' => 'trat', 'dut' => 'dat'), 'http://localhost/index.php/apps/files?trut=trat&dut=dat'),
|
|
|
|
array('', 'index.php', array('trut' => 'trat', 'dut' => 'dat'), 'http://localhost/index.php?trut=trat&dut=dat'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideSubDirAppAbsoluteUrlParts() {
|
|
|
|
return array(
|
|
|
|
array('files', 'index.php', array(), 'http://localhost/owncloud/index.php/apps/files'),
|
|
|
|
array('files', 'index.php', array('trut' => 'trat', 'dut' => 'dat'), 'http://localhost/owncloud/index.php/apps/files?trut=trat&dut=dat'),
|
|
|
|
array('', 'index.php', array('trut' => 'trat', 'dut' => 'dat'), 'http://localhost/owncloud/index.php?trut=trat&dut=dat'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @small
|
2014-05-19 15:50:53 +00:00
|
|
|
* test linkToRemoteBase URL construction
|
2014-04-16 12:32:08 +00:00
|
|
|
*/
|
|
|
|
public function testLinkToRemoteBase() {
|
|
|
|
\OC::$WEBROOT = '';
|
|
|
|
$result = \OC_Helper::linkToRemoteBase('webdav');
|
|
|
|
$this->assertEquals('/remote.php/webdav', $result);
|
|
|
|
|
|
|
|
\OC::$WEBROOT = '/owncloud';
|
|
|
|
$result = \OC_Helper::linkToRemoteBase('webdav');
|
|
|
|
$this->assertEquals('/owncloud/remote.php/webdav', $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @small
|
2014-05-19 15:50:53 +00:00
|
|
|
* test linkToRemote URL construction
|
2014-04-16 12:32:08 +00:00
|
|
|
*/
|
|
|
|
public function testLinkToRemote() {
|
|
|
|
\OC::$WEBROOT = '';
|
|
|
|
$result = \OC_Helper::linkToRemote('webdav');
|
|
|
|
$this->assertEquals('http://localhost/remote.php/webdav/', $result);
|
|
|
|
$result = \OC_Helper::linkToRemote('webdav', false);
|
|
|
|
$this->assertEquals('http://localhost/remote.php/webdav', $result);
|
|
|
|
|
|
|
|
\OC::$WEBROOT = '/owncloud';
|
|
|
|
$result = \OC_Helper::linkToRemote('webdav');
|
|
|
|
$this->assertEquals('http://localhost/owncloud/remote.php/webdav/', $result);
|
|
|
|
$result = \OC_Helper::linkToRemote('webdav', false);
|
|
|
|
$this->assertEquals('http://localhost/owncloud/remote.php/webdav', $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @small
|
2014-05-19 15:50:53 +00:00
|
|
|
* test linkToPublic URL construction
|
2014-04-16 12:32:08 +00:00
|
|
|
*/
|
|
|
|
public function testLinkToPublic() {
|
|
|
|
\OC::$WEBROOT = '';
|
|
|
|
$result = \OC_Helper::linkToPublic('files');
|
2014-09-04 17:51:38 +00:00
|
|
|
$this->assertEquals('http://localhost/s', $result);
|
2014-04-16 12:32:08 +00:00
|
|
|
$result = \OC_Helper::linkToPublic('files', false);
|
2014-09-04 17:51:38 +00:00
|
|
|
$this->assertEquals('http://localhost/s', $result);
|
|
|
|
$result = \OC_Helper::linkToPublic('files', true);
|
|
|
|
$this->assertEquals('http://localhost/s/', $result);
|
|
|
|
|
|
|
|
$result = \OC_Helper::linkToPublic('other');
|
|
|
|
$this->assertEquals('http://localhost/public.php?service=other', $result);
|
|
|
|
$result = \OC_Helper::linkToPublic('other', false);
|
|
|
|
$this->assertEquals('http://localhost/public.php?service=other', $result);
|
|
|
|
$result = \OC_Helper::linkToPublic('other', true);
|
|
|
|
$this->assertEquals('http://localhost/public.php?service=other/', $result);
|
2014-04-16 12:32:08 +00:00
|
|
|
|
|
|
|
\OC::$WEBROOT = '/owncloud';
|
|
|
|
$result = \OC_Helper::linkToPublic('files');
|
2014-09-04 17:51:38 +00:00
|
|
|
$this->assertEquals('http://localhost/owncloud/s', $result);
|
2014-04-16 12:32:08 +00:00
|
|
|
$result = \OC_Helper::linkToPublic('files', false);
|
2014-09-04 17:51:38 +00:00
|
|
|
$this->assertEquals('http://localhost/owncloud/s', $result);
|
|
|
|
$result = \OC_Helper::linkToPublic('files', true);
|
|
|
|
$this->assertEquals('http://localhost/owncloud/s/', $result);
|
|
|
|
|
|
|
|
$result = \OC_Helper::linkToPublic('other');
|
|
|
|
$this->assertEquals('http://localhost/owncloud/public.php?service=other', $result);
|
|
|
|
$result = \OC_Helper::linkToPublic('other', false);
|
|
|
|
$this->assertEquals('http://localhost/owncloud/public.php?service=other', $result);
|
|
|
|
$result = \OC_Helper::linkToPublic('other', true);
|
|
|
|
$this->assertEquals('http://localhost/owncloud/public.php?service=other/', $result);
|
2014-04-16 12:32:08 +00:00
|
|
|
}
|
|
|
|
|
2014-06-23 14:48:25 +00:00
|
|
|
/**
|
|
|
|
* Tests recursive folder deletion with rmdirr()
|
|
|
|
*/
|
|
|
|
public function testRecursiveFolderDeletion() {
|
|
|
|
$baseDir = \OC_Helper::tmpFolder() . '/';
|
|
|
|
mkdir($baseDir . 'a/b/c/d/e', 0777, true);
|
|
|
|
mkdir($baseDir . 'a/b/c1/d/e', 0777, true);
|
|
|
|
mkdir($baseDir . 'a/b/c2/d/e', 0777, true);
|
|
|
|
mkdir($baseDir . 'a/b1/c1/d/e', 0777, true);
|
|
|
|
mkdir($baseDir . 'a/b2/c1/d/e', 0777, true);
|
|
|
|
mkdir($baseDir . 'a/b3/c1/d/e', 0777, true);
|
|
|
|
mkdir($baseDir . 'a1/b', 0777, true);
|
|
|
|
mkdir($baseDir . 'a1/c', 0777, true);
|
|
|
|
file_put_contents($baseDir . 'a/test.txt', 'Hello file!');
|
|
|
|
file_put_contents($baseDir . 'a/b1/c1/test one.txt', 'Hello file one!');
|
|
|
|
file_put_contents($baseDir . 'a1/b/test two.txt', 'Hello file two!');
|
|
|
|
\OC_Helper::rmdirr($baseDir . 'a');
|
|
|
|
|
|
|
|
$this->assertFalse(file_exists($baseDir . 'a'));
|
|
|
|
$this->assertTrue(file_exists($baseDir . 'a1'));
|
|
|
|
|
|
|
|
\OC_Helper::rmdirr($baseDir);
|
|
|
|
$this->assertFalse(file_exists($baseDir));
|
|
|
|
}
|
2014-09-26 14:14:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Allows us to test private methods/properties
|
|
|
|
*
|
|
|
|
* @param $object
|
|
|
|
* @param $methodName
|
|
|
|
* @param array $parameters
|
|
|
|
* @return mixed
|
2015-06-03 10:03:02 +00:00
|
|
|
* @deprecated Please extend \Test\TestCase and use self::invokePrivate() then
|
2014-09-26 14:14:59 +00:00
|
|
|
*/
|
|
|
|
public static function invokePrivate($object, $methodName, array $parameters = array()) {
|
2015-06-03 10:03:02 +00:00
|
|
|
return parent::invokePrivate($object, $methodName, $parameters);
|
2014-09-26 14:14:59 +00:00
|
|
|
}
|
2012-10-13 19:02:12 +00:00
|
|
|
}
|